Skip to the text
KDOS
Menu

The daemons

KDOS keeps six root daemons of its own. Each answers a few fixed questions, on a Unix socket in /run, on the system bus, or both: open a named service in the firewall, say which application is spending the battery, kill a runaway program before the desktop freezes, mount application packs, set the machine’s name, clock and keyboard, and install a system update into the other root slot. Everything else a desktop asks of root, such as suspending, logging in or mounting a USB stick, belongs to programs KDOS ports from upstream: elogind, polkit, udisks2 and the rest. This chapter describes KDOS’s six; kdos-mdnsd, which answers .local names and binds its socket as root but then runs as nobody; the per-box Wayland socket kdos-boxsock, which sits close to privilege without being a root daemon; the other services ksvc runs beside them, and the two login-record services, utmpd and wtmpd.

It is written for two readers:

Why the authorisation is shaped this way, and what it defends against, is argued in The security model. How init starts services is in Boot and init. Every socket path, bus name and verb on the system is listed in Filesystem and IPC.

At a glance

Each root daemon is one binary in /usr/sbin, started at boot by a script in /etc/init.d and kept running by ksvc, the service supervisor in kdos-tools. None of them ships a D-Bus activation file: a bus name is taken by the supervised daemon or by nobody.

Daemon Socket System bus Command-line client Other clients Init script Skipped at boot when
kdos-settingsd — org.freedesktop.hostname1, org.freedesktop.timedate1, org.freedesktop.locale1 kdos timezone, kdos hostname, kdos locale, kdos keymap System Settings’ Date & Time page, plasma-setup, the login screen’s KWin (kwin_wayland --locale1), startplasma, System Monitor’s OS sensors 43_settingsd.sh The binary is missing
kdos-sysupdated — org.freedesktop.sysupdate1, io.kdos.Slots1 kdos update, kdos-bootctl (which it runs) Discover, the System Versions page, kdos-notice 46_sysupdated.sh The binary is missing
kdos-powerd /run/kdos-powerd.sock io.kdos.Power1 kdos-power The Firewall settings page, kdos-fwask and kded-kdos (over the bus), kdos theme, kdos phosphor, kdos doctor 55_powerd.sh The binary is missing
kdos-energyd /run/kdos-energyd.sock — kdos-energy System Monitor’s KDOS sensors (ksystemstats-kdos), kdos doctor 56_energyd.sh The binary is missing, or no /sys/class/powercap/*/energy_uj is readable
kdos-oomd /run/kdos-oomd.sock — — kdos doctor, kdos-notice 57_oomd.sh The binary is missing, or /proc/pressure/memory is not writable (the kernel has PSI off)
kdos-packd /run/kdos-packd.sock — — kdos-appbox (and kdos app, which runs it), Discover’s KDOS backend, kdos doctor 59_packd.sh The binary is missing, or erofs is absent from /proc/filesystems even after modprobe erofs
kdos-mdnsd UDP 127.0.0.1:5380, as nobody — — NetworkManager’s dnsmasq, for every .local lookup 45_mdns.sh The binary or avahi-daemon is missing, or avahi is disabled

kdos-powerd and kdos-energyd are each one binary with two names. Run under the daemon’s name it serves the socket; run under the client’s name (kdos-power, kdos-energy) it sends one request and prints the answer.

Starting and stopping one by hand

The service command (a second name for ksvc) takes the verb first and then the service name, which is the init script’s name without its two-digit prefix and .sh suffix:

service status powerd
service restart settingsd
service stop packd
service start energyd
service list                # every service, whether it starts at boot, and its state
service disable oomd        # do not start it at boot

rcS and rcK are the boot and shutdown scripts in /etc/init.d that run every numbered service script in order (see Boot and init). disable creates /etc/service.disabled/<name>, which both skip; enable removes it. A name that matches no script exactly is matched as a substring, so service status pack also reaches 59_packd.sh. The daemon’s full name (kdos-powerd) matches nothing: it contains the service name rather than the other way round.

The substring match finds the script for status, start, stop and restart only. enable and disable check that some script matches, then write or remove the marker under the name exactly as typed, while rcS and rcK look for the marker under the script’s own service name. They therefore need the exact service name: service disable pack reports success, creates /etc/service.disabled/pack, and disables nothing.

Who may ask for what

Two kinds of gate stand in front of these daemons. A socket asks the kernel who the caller is and admits root and the wheel group, the administrators; a bus method asks polkit about the caller and follows the action’s defaults and whatever /etc/polkit-1/rules.d says. The person at the machine is the active local session, as elogind reports it.

Daemon root wheel The active local session Anyone else
kdos-settingsd Every method, without asking polkit polkit’s answer Time zone and network time without a password (the Date & Time page asks for one anyway, see Checking, then asking, then writing); the clock, locale, keyboard and names after an administrator’s password Refused
kdos-sysupdated Every method, without asking polkit polkit’s answer Checking and Bless without a password; installing, trying a slot and changing the channel after an administrator’s password Refused
kdos-powerd, socket Every verb Every verb ping, firewall list, firewall knocks, and accent and splash when polkit grants them without a prompt ping, firewall list and firewall knocks
kdos-powerd, bus Every method polkit’s answer The accent and the splash without a password; the firewall after an administrator’s password The reads only
kdos-energyd Every verb Every verb Refused Refused
kdos-oomd Every verb Every verb Every verb Refused
kdos-packd Every verb Every verb Refused Refused

The non-administrator column of a socket is never a group: kdos-oomd asks elogind whether the caller has the active session on a seat, and kdos-powerd asks polkit. A login elogind does not count as active, such as an ssh session, gets the administrators’ answer or nothing. Each daemon’s --explain <user> says which row a user falls in.

The shape they share

Every root daemon here is built the same way. Knowing the pattern once tells you how to run, diagnose and review all six.

Supervision and logging

A daemon runs in the foreground and never forks into the background. The init script calls supervise <name> <binary> from /etc/init.d/service_helper; the supervisor leads its own process group, writes /run/kdos-svc.<full name>.pid, and restarts the daemon five seconds after it exits. service stop <name> sends SIGTERM to the whole group, waits for it to empty, checking every 50 ms, and sends SIGKILL to whatever is left when the stop grace runs out. The grace is five seconds unless the init script passed supervise --stop-grace <seconds>; none of these six daemons does. supervise on a name whose supervisor is alive starts nothing and says [SKIP], so a second service start cannot leave a daemon nothing stops. A SIGTERM sent to the supervisor alone is passed on to its group, so the daemon goes with it. A daemon whose supervisor was killed outright is still found through the state file: service status reports it as [FAIL] rather than [DOWN], service start refuses to start a second beside it, and service stop ends it.

The daemon’s output goes to syslog and to a small file in /run. The supervisor points the daemon’s standard output and error, and its own Starting and Exited lines, at a forwarder process. Each line becomes a daemon-facility syslog message tagged with the daemon’s full name (supervise --facility <name> picks another facility; none of these six daemons uses it), and is also appended to /run/kdos-svc.<full name>.log: for example /run/kdos-svc.kdos-powerd.log, tagged kdos-powerd. Files and tags use the full name; only the service command takes the short one. The file holds at most 64 KiB; when it would grow past that it is renamed to /run/kdos-svc.<full name>.log.old and a fresh one starts. The file is what you read before syslogd is up or while it restarts.

The daemon never keeps the descriptors it inherited. Under rcS those point at the boot step’s capture file on the /run tmpfs, so a daemon that crash-looped would fill memory until the next reboot, and a daemon that logs only to standard error would never reach /var/log/messages. The forwarder ignores the SIGTERM that service stop sends the group and exits only when the daemon’s end of the pipe closes, so what a daemon prints while shutting down is kept and it never writes into a pipe with no reader.

The init script checks the machine first and skips with a reason. A daemon that cannot do its job on this machine (no energy counter, no PSI, no EROFS) is skipped and prints [SKIP] <name>: <reason> at boot, because a daemon that refuses to start under a respawn loop is restarted every five seconds for as long as the machine is up. A refusal the script cannot see (kdos-energyd finding no usable energy domain after the script’s glob matched) is restarted every five seconds, and service status reports it as [FAIL] with its exit status rather than [ OK ] (see ksvc and service).

The two bus-only daemons use two more supervise options:

An init script whose daemon owns a bus name calls wait_bus_name <name> after supervise, which holds the boot for up to ten seconds until the name has an owner, so the scripts after it find the name taken. kdos-powerd’s script waits for io.kdos.Power1 only when a system bus is running: its socket answers whether or not the bus is up, and it retries the bus itself.

The socket and the identity check

The four daemons with a socket each own one in /run, named after the daemon, and remove a stale one before binding so that a socket file left by a crash cannot hold the name.

The listening socket and every accepted connection are close-on-exec (SOCK_CLOEXEC on the socket() and on accept4()), so no program a daemon runs inherits a client’s connection. A program that kept one open would hold it past the reply: kdos-powerd’s firewall ssh on starts sshd under its supervisor, and a client whose connection a running program still holds never reads the end of its answer.

The socket is mode 0666, and anyone may connect; the real check is the caller’s identity. The daemon asks the kernel for the connecting process’s credentials (SO_PEERCRED, which the caller cannot forge) and answers err not permitted to anyone it does not admit. The file mode is left open on purpose: a mode that looked like the authorisation is a mode somebody eventually loosens.

There is one implementation of the group check, kb_uid_allowed() in libkbase. It admits uid 0 outright; otherwise it looks the uid up in the password database and reads /etc/group, and admits the account when the group’s id is its primary group or its name is in the group’s member list. Membership is therefore read at the moment of the request, not from the caller’s process credentials, and a group change applies to the next request without a new login. No daemon keeps its own copy of the rule: a copy per daemon is a rule that gets tightened on one socket and stays loose on the others. A daemon that admits more than root and wheel states the difference beside its own call, as kdos-oomd and kdos-powerd do.

The client never names a path. Every verb takes an identifier from a list the daemon itself published: a firewall service name, an accent, a pack id.

One request per connection

The client connects, writes one short line, reads the answer and the connection closes. There is no session state.

Each daemon serves one request at a time. kdos-powerd, kdos-energyd and kdos-oomd give a connection two seconds to send its request, because the same loop drives kdos-powerd’s bus face, kdos-energyd’s sampler and kdos-oomd’s pressure trigger, and a client that connected and said nothing would otherwise stop them. kdos-packd sets no such limit, so a connection that never speaks delays every later request until it closes.

The two bus daemons never block on polkit. An interactive check lasts as long as somebody takes to type a password, so the question goes out asynchronously and the method call is answered when polkit is; the bus keeps answering other callers meanwhile.

Fixtures, skips and test sockets

kdos-energyd, kdos-oomd and kdos-packd each have a fixture mode: the daemon can be pointed at a recorded copy of the system state and made to print what it would do without doing it. This is how the selection logic, which decides what gets measured, mounted or killed, is tested without a machine to lose. kdos-powerd has none; its --explain, --firewall, --accent, --splash and --file-sharing flags run the same rules against a scratch /etc instead (see Diagnosis and testing). kdos-settingsd reads a scratch tree from environment variables, and kdos-sysupdated serves a test bus over a fixture root; each is described in its own section.

Each socket daemon reads another socket path from an environment variable (KDOS_POWERD_SOCKET, KDOS_ENERGYD_SOCKET, KDOS_OOMD_SOCKET, KDOS_PACKD_SOCKET) so the test suite can run it unprivileged. Moving the socket grants nothing: the check is the caller’s identity, never the path. kdos-powerd, kdos-oomd and kdos-packd refuse to start on their real socket unless they are root, because an unprivileged daemon would answer ok to work it cannot do. kdos-energyd has no such check; it refuses to start when it cannot read the energy counter, which without root it cannot.

A socket address holds at most 107 bytes of path. kdos-packd refuses to start on a longer path, because truncating would bind a socket at a path nobody asked for, and the next start would fail with “address already in use” for a file that appears not to exist. kdos-powerd, kdos-energyd and kdos-oomd cut an over-long path to fit and bind at the shortened one.

kdos-powerd

The few root-owned settings a desktop that is not root still changes: which named services the firewall lets in, the accent that everything drawn before a login wears (the boot menu, the splash, the text console and the login screen), and the splash’s motion. It offers the same verbs twice: a socket for the kdos command, and io.kdos.Power1 on the system bus for System Settings. The bus face alone also starts Samba once an account can share folders; see Starting Samba for a shared folder.

Suspend, power-off and reboot are not this daemon’s. They belong to elogind, which Plasma’s Leave menu, PowerDevil and the lid switch all reach through org.freedesktop.login1; see What happens around a suspend.

Verb Who, over the socket Does
ping Anyone Answers ok
firewall list Anyone One row per named service: name, on or off, and what the service is for (the For column below, in the daemon’s words), tab-separated, then ok
firewall knocks Anyone One row per named service: name and the number of packets turned away while it was closed, or -1 where nothing was counted, then ok
firewall <service> on\|off root, wheel, or polkit’s io.kdos.firewall.set without a prompt Open or close one named service
accent <scheme> root, wheel, or polkit’s io.kdos.accent.set without a prompt Recolour the boot menu, the splash, the text console and the login screen
splash phosphor\|modern The same as accent Choose the boot splash’s motion

The three reads answer anybody: a liveness check, a file every user can read, and counts of packets that were dropped. Every refusal is written to the daemon’s log with the caller’s uid and the action polkit did not grant, so a setting that did not change can be attributed.

The client

kdos-power suspend|poweroff|reboot
kdos-power ping
kdos-power firewall list|knocks|<service> on|off
kdos-power accent <scheme>
kdos-power splash phosphor|modern

suspend, poweroff and reboot never reach the daemon. The client replaces itself with loginctl suspend, loginctl poweroff or loginctl reboot, run as the caller, so elogind sees the caller, polkit answers about the caller’s session, and the screen locker’s sleep inhibitor gets its lock in before the machine goes down: the same path the Leave menu takes. When loginctl cannot be run the client says that elogind owns these and exits 1.

Every other verb is one request line of at most 63 bytes, newline included; the daemon reads nothing past that.

Exit status Means
0 The daemon answered ok
1 The daemon answered err …, closed without answering, or is not running (kdos-power: no kdos-powerd — `service start powerd`)
2 Bad usage, or an argument too long for the request line

When the daemon is not running, start it with the command the client prints, service start powerd (see Starting and stopping one by hand).

firewall prints the daemon’s whole reply on standard output, the err line included, so a caller capturing the table reads all of it. For accent and splash an error is printed to standard error as kdos-power: <reply>, and a success that left something unchanged prints the daemon’s note the same way, such as kdos-power: (boot menu unchanged).

io.kdos.Power1

The bus face, at /io/kdos/Power1 on interface io.kdos.Power1, is what the Firewall settings page and kdos-fwask call. Root owns the name; anybody may call it, and polkit decides who may change anything.

Member Kind Does
ListFirewallServices() → a(sbs) Method Each named service: name, whether it is open, what it is for
ListFirewallKnocks() → a(st) Method Each closed service and the packets turned away
SetFirewallService(s name, b open) Method polkit io.kdos.firewall.set
SetAccent(s scheme) Method polkit io.kdos.accent.set
SetSplash(s motion) Method polkit io.kdos.accent.set
StartFileSharing() Method polkit io.kdos.filesharing.start; runs /etc/init.d/83_samba.sh start
Accent (s) Property, emits change The scheme /etc/kdos/accent names
Accents (as) Property, constant Every scheme this build knows
FirewallServicesChanged() Signal After any firewall change, from either face
Action Active local session Inactive Any other
io.kdos.firewall.set auth_admin_keep no no
io.kdos.accent.set yes no no
io.kdos.filesharing.start yes no no

The subject polkit is asked about is the caller’s bus name, which polkitd resolves to a process and a session itself, so nothing the caller says about who it is takes part. A caller that did not allow a prompt is not prompted: a challenge it could have answered comes back as the standard InteractiveAuthorizationRequired error rather than AccessDenied. A bad name answers io.kdos.Power1.Error.NoSuchService, NoSuchAccent or NoSuchMotion.

The socket comes up before the bus and does not wait for it. A system bus that cannot be reached is retried every five seconds from the daemon’s loop while the socket answers, so the kdos command reaches the firewall on a machine whose bus is down.

Starting Samba for a shared folder

smbd does not run until some account can share. At boot, Samba’s service script /etc/init.d/83_samba.sh makes /var/lib/samba/usershares (root’s, group sambashare, mode 1770) and starts smbd only when the sambashare group has a member in /etc/group, that directory holds a usershare, or /etc/samba/smb.conf defines a share below [global]; otherwise it prints [SKIP] samba: no account shares folders. smbd has to be running before the first share can be made: a folder shared from Dolphin’s Share tab is a file net usershare add writes into the directory as the user, and net first turns every name in the share’s ACL, Dolphin’s Everyone among them, into a SID by asking the local smbd. With smbd down it fails with “cannot convert name … to a SID” and writes nothing.

The Share tab adds its user to sambashare, which counts from that user’s next login, and that login can come before the next boot. So the session’s kded-kdos module calls StartFileSharing() once when it loads in a session whose credentials can write into the usershare directory, which only a member’s can. The method takes no argument, so a caller names nothing: after polkit’s io.kdos.filesharing.start, which the person at the machine is granted, the daemon runs /etc/init.d/83_samba.sh start as an argument vector, and the script decides again. That is all the next boot would do, which is why the action needs no password. The call is refused with io.kdos.Power1.Error.Failed while /etc/service.disabled/samba exists, the boot’s own marker for a service an administrator turned off, or when Samba is not installed. A service already supervised is not started twice, so the call at every later login costs one script run. Nothing stops smbd again: leaving the group or removing the last share leaves it serving nothing until the next boot, which then does not start it.

Samba’s lock directory is /var/lib/samba/lock, which the package carries, root’s and mode 0755. smbd refuses to start when the msg.lock directory inside it belongs to anybody but root, and any Samba client run first, net usershare among them, makes the lock directory as the user when it can; in a directory only root can write to, a client makes nothing and still works.

What happens around a suspend

elogind runs a suspend; this daemon takes no part in it. What runs, in order:

  1. Whatever asked (kdos-power suspend, the Leave menu, PowerDevil, or the lid, which /etc/elogind/logind.conf.d/50-kdos.conf sets to suspend unless the machine is docked) calls login1’s Suspend, and polkit answers for the caller’s session.
  2. elogind emits PrepareForSleep(true) and waits up to five seconds (InhibitDelayMaxSec=5) for the delay inhibitors to let go. kscreenlocker locks the session there, and NetworkManager, built with -Dsuspend_resume=elogind, takes its devices down.
  3. The hooks in /usr/lib/elogind/system-sleep run, TLP’s 49-tlp-sleep among them, which saves the radio states and applies TLP’s suspend settings.
  4. The kernel suspends to RAM. /etc/elogind/sleep.conf.d/50-kdos.conf turns hibernation and the hybrid modes off, because swap on KDOS is zram, which holds nothing across a power-off.
  5. On waking the hooks run again with post, and PrepareForSleep(false) brings NetworkManager back.

The power key powers off (HandlePowerKey=poweroff), which is init’s ordinary shutdown through rcK (see Boot and init).

accent

accent <scheme> takes one of the eight scheme names compiled into libkcolor: phosphor, amber, ice, bone, norton, borland, perfect or paper. The name is matched by kcol_find(); anything else is refused with err not an accent. There is no path to aim and nothing to traverse, which is why this verb is safe to reach from a session.

It writes only root-owned files and the login screen’s own:

It recolours nothing inside a session. That is kdos theme’s job, which runs as the user and touches only the user’s own files; kdos theme calls this verb for the parts that need root.

A machine with no writable ESP, or no greeter, is not a failure. The live medium is read-only, and a machine may have no /boot/efi at all. When a part cannot be written the verb still succeeds and names what stayed as it was: ok <scheme> (boot menu unchanged), (login screen unchanged) or (boot menu and login screen unchanged). Refusing would make kdos theme look broken on the ISO, where everything else recolours correctly.

splash

splash phosphor|modern sets the boot splash’s motion: a CRT power-on with Phosphor mode, a flat mark without it. The splash runs in the initramfs before any root filesystem is mounted, so the kernel command line is the one thing it can read; the verb runs kdos-bootctl splash <motion>, which writes kdos.splash=<motion> on every KDOS entry in limine.conf. Any other word is refused with err not a splash motion (phosphor or modern). On a machine whose boot menu cannot be written the answer is ok <motion> (boot menu unchanged), for the accent’s reason. kdos phosphor on and off send it.

firewall

firewall names services, never ports, and the table of what each name means belongs to the daemon. A client that could name a port could open any port; a client that can only name ssh opens exactly what the daemon’s table says ssh is. The Firewall settings page asks for the list rather than carrying its own copy.

The For column is the sentence the Firewall page shows under each name and firewall list prints; the Served by column names the service script or program behind it, which the page does not show.

Service Opens For Served by
ssh TCP 22 Logging in to this computer over SSH 70_sshd.sh. Turning it on also removes /etc/service.disabled/sshd and starts sshd; turning it off puts the marker back and stops sshd
http TCP 80 A web server on this computer Any
https TCP 443 A web server on this computer, over HTTPS Any
ipp TCP 631 Sharing a printer with other computers CUPS
smb TCP 445 Sharing files with Windows and other computers (SMB) 83_samba.sh
kiwix TCP 8080 Offline content served by Kiwix kiwix-serve, on its default port
mqtt TCP 1883, 8883 An MQTT broker for devices on the network (Mosquitto) 73_mosquitto.sh
xmpp TCP 5222 A chat server for XMPP clients (Prosody) 74_prosody.sh
nfs TCP 2049 Sharing files with other computers over NFS 72_nfsd.sh (NFSv4)
babel UDP 6696 Mesh routing with Babel 31_babeld.sh
nut TCP 3493 Telling other computers how the UPS is doing (NUT) 56_nut.sh
snmp UDP 161 Answering SNMP queries about this computer 71_snmpd.sh
mumble TCP 64738, UDP 64738 A Mumble voice chat server 75_mumble-server.sh
caldav TCP 5232 Shared calendars and contacts (Radicale) 77_radicale.sh
mail TCP 25, 143, 465, 587, 993 A mail server for the network (Maddy) 78_maddy.sh
irc TCP 6667, 6697 An IRC chat server 79_ngircd.sh
dlna TCP 8200, UDP 1900 Sharing media with TVs and players (DLNA) 84_minidlna.sh
tryton TCP 8000 GNU Health for Tryton clients 85_gnuhealth.sh
caddy TCP 8443 The Caddy web server’s HTTPS site Caddy, the listener of the shipped /etc/caddy/Caddyfile
mosh UDP 60000–61000 Mosh sessions to this computer (needs SSH too) mosh-server, after an SSH login, so ssh must be on as well
syncthing TCP 22000, UDP 22000, UDP 21027 Syncing folders with Syncthing Syncthing: sync, and local discovery
kdeconnect TCP 1714–1764, UDP 1714–1764 KDE Connect with a phone on the network kdeconnectd in a session
vnc TCP 5900 Sharing this desktop over VNC (Krfb) krfb, on its default port, while sharing is on in a session
rdp TCP 3389 Sharing this desktop over RDP (KRdp) krdp, on its default port, while sharing is on in a session
xonotic UDP 26000 Hosting a Xonotic game for the network A Xonotic server

A port moved in krfb’s or krdp’s own settings stays shut until a hand-written rule beside the daemon’s file opens it.

A closed service is counted. In the daemon’s file an open service is its rule; a closed one is the same match, for a packet from another machine (fib saddr type != local), counting into a named counter, kdos_knock_<service>, after which the packets meet the chain’s policy and are dropped. A packet this machine sent itself is not counted: its own broadcasts — KDE Connect’s identity packet, Syncthing’s discovery, SSDP — loop back in on the network interface, and counted they would be a knock with nobody knocking. firewall knocks and ListFirewallKnocks read those counters with nft list counters, which is how the Firewall page and kdos-fwask can say that a phone or an RDP client was turned away and offer to let it in by name. A reload rebuilds the table, so every change starts every counter from zero; a counter the kernel does not hold reads -1, which is not the same as nothing having knocked.

How a change is applied:

  1. The daemon reads which names are on by looking for each rule’s exact text in /etc/nftables.d/50-kdos-services.nft.
  2. It rewrites that file whole from the names that are on, as additions to the input chain of the inet filter table. It never merges, because merging means parsing nftables syntax, and a parser that got it wrong would leave a port open that the settings page showed as closed. Anything you write by hand belongs in another file under /etc/nftables.d, which the daemon never reads or touches. The new file is renamed into place before anything checks it, because the check reads it through /etc/nftables.conf’s include. The daemon reads the current file first so that it can put it back; a file that exists but cannot be read refuses the toggle with err cannot read the current rules.
  3. It runs nft --check -f /etc/nftables.conf. If the ruleset would not load, the previous 50-kdos-services.nft is put back, or removed if there was none, and the answer is err the ruleset would not load; nothing changed. The kernel keeps the previous rules, and firewall list and the next boot see the previous state too.
  4. It runs nft -f /etc/nftables.conf. That file deletes and rebuilds only its own inet filter table, so the NAT that netavark (the container network backend) sets up for rootful containers and NetworkManager’s for a hotspot survive a toggle. If the load itself fails, the previous file is put back the same way and the answer is err the ruleset did not apply.

A successful toggle answers ok <service> on|off and emits FirewallServicesChanged. An unknown name answers err no service called that; a state other than on or off answers err a service is on or off.

Diagnosis and testing

kdos-powerd --explain <user>
kdos-powerd --firewall list|knocks
kdos-powerd --firewall <service> <on|off>
kdos-powerd --accent <scheme>
kdos-powerd --splash phosphor|modern
kdos-powerd --file-sharing

--explain answers “would this user be allowed, and why”. It is the first thing to run when a settings change is refused, because a refusal otherwise shows up only in the daemon’s log. It asks libkbase the same question the socket asks, needs no privilege, and prints one line, for example:

alice: uid 1001, primary gid 1001, not in wheel — permitted ping, the firewall list and its knocks; `firewall` only where polkit grants io.kdos.firewall.set and `accent` and `splash` only where it grants io.kdos.accent.set, each without a prompt (the shipped policy: the accent and the splash from an active session at the machine), otherwise refused

polkit’s half is named and not asked: polkit answers about a process, and there is no process to ask it about. It exits 0 when the group rule admits the three changes and 1 otherwise.

The other flags run a verb’s own rules without the socket, which is the only way to test them: the socket’s check needs two different users to exercise. They grant nothing, because the binary is writing to an /etc the person running it could already write to. KDOS_POWERD_ETC replaces /etc, and a daemon pointed at another /etc leaves the kernel’s ruleset, sshd, Samba, the boot menu and the login screen alone: KDOS_POWERD_NFT, KDOS_POWERD_BOOTCTL and KDOS_POWERD_SAMBA name stand-ins for nft, kdos-bootctl and Samba’s service script (unset, nothing is run), and KDOS_POWERD_GREETER and KDOS_POWERD_SDDM_HOME name the greeter sets and a home to copy them into. KDOS_POWERD_SOCKET moves the socket.

kdos-energyd

Per-application energy attribution: which application is using the processor’s power.

Measuring the processor’s energy is routine: the kernel exposes the counter under /sys/class/powercap. Attribution is the hard part on an ordinary Linux desktop: an application is dozens of processes in scattered groups, and nothing owns enough of the system to name them. On KDOS every boxed application (one running in its own box, a rootless container) runs under a known name, listed in /usr/share/kdos/alien-apps, so the attribution starts from an identity rather than a guess.

Verb Answers
ping ok
report The text report
report-json The same report as one JSON object
kdos-energy [--json|ping]

kdos-energy prints the report (or JSON with --json) and exits 0. It exits 1 when the daemon is not running or answered err, and 2 on bad usage. An err answer goes to standard error. System Monitor’s KDOS sensors (ksystemstats-kdos) read report-json; each row there carries the display name, and beside it app and box (null for a process in no box), so a reader that groups by box never parses the display string. When the daemon is not running the client suggests service start energyd (see Starting and stopping one by hand).

This is the report the test fixture in testing/fixtures/energy produces (thirty seconds of recorded samples) when replayed with the fixture’s own application table, as the test suite runs it:

KDOS_ALIEN_APPS=testing/fixtures/energy/alien-apps \
    kdos-energyd --fixture testing/fixtures/energy

Without that table the host’s /usr/share/kdos/alien-apps names the processes instead, and the rows differ. Its rows, with the 20-cell bar each prints between the share and the gpu column left out here:

KDOS energy  —  30 s of samples, RAPL package-0

  firefox-esr (appbox kdos-apps)          75.5%  gpu 75.0%
  kwin_wayland                            15.4%  gpu 25.0%
  gimp (appbox kdos-apps)                  0.4%  gpu  0.0%
  short-lived and exited processes         8.7%

and the notes it prints under them, one line each:

Answers go to root and wheel only: on a multi-user machine this list is what everyone else is running.

Figures are shares, never watt-hours. The counter (Intel RAPL, read from /sys/class/powercap) measures the processor package. It cannot see the screen, which is the largest single draw on a laptop, nor the radio, the storage or a discrete graphics card. “This application was 41% of attributable CPU energy today” is a measurement; “this application used 12% of your battery” would be a guess presented as a unit.

The daemon samples every ten seconds. The interval is fixed and not configurable, for the reason given below, and it is short enough to stay far inside the counter’s wrap period. Seven rules each change the answer:

A process’s box is found by walking its parents to the container supervisor that started it, not from its cgroup: a box started where rootless podman could write no cgroup of its own sits in its parent’s, and an elogind session’s delegated subtree is named for the session, not the box.

Why a daemon rather than a one-shot command. The counter runs freely, so a one-shot command could only report what happened while it was watching. The counter is also readable only by root since Linux 5.10, because the PLATYPUS side-channel attack showed that fine-grained unprivileged reads can recover cryptographic keys. What leaves this daemon is a per-application percentage over minutes; the raw counter and the sampling interval are never republished, and no client can ask for a shorter interval. There is no write path into the power interface at all.

The init script skips the daemon when no /sys/class/powercap/*/energy_uj is readable, which covers most virtual machines and every non-x86 processor. The daemon itself also refuses to start there, naming the powercap path in its log, because a daemon sampling an unreadable counter would report a machine that uses no energy, which reads as “nothing is draining the battery”. kdos doctor tells the two cases apart: a machine with no energy domain at all, and a daemon that is not running.

kdos-energyd --fixture <dir> [--json] replays recorded snapshots (<dir>/0, <dir>/1, … each holding a proc tree, a powercap tree, an optional dt in seconds and an optional slept, the seconds the machine was suspended inside that step’s window) through the same sampler and report, and prints the result. KDOS_ENERGY_PROC and KDOS_ENERGY_POWERCAP point the reader at other /proc and powercap trees, and KDOS_ALIEN_APPS at another application-name table.

kdos-oomd

Kills the process that is starving the machine of memory, before the desktop freezes.

The kernel has its own out-of-memory killer, but it fires when an allocation fails. On a machine with swap that is often minutes after the desktop stopped responding, the whole session spent thrashing while the kernel still had pages to hand out. The kernel’s pressure interface (PSI, in /proc/pressure/memory) reports instead that the machine is stalling on memory, which is what a frozen desktop feels like. Boxed applications make this likely: a browser and a 3D slicer on one modest machine.

How it decides

The daemon shields itself from the emergency it watches: at start-up it sets its own oom_score_adj to -1000 and locks its memory with mlockall. Each kill is logged with the victim, the ten-second pressure averages and the memory available when it chose, in the form kdos-oomd: killed <name> [(appbox <box>)] (pid <pid>, <size> MB) — memory pressure avg10 full=<f> some=<s>, <avail> of <total> MB available. A trigger that finds memory not short logs nothing.

The socket

Nothing in the protocol names a process, so there is nothing to aim. The socket takes no argument and answers root, wheel and a user with the active session on a seat:

Verb Answers
ping ok
status ok trigger 'full 150000 1000000', kills <n> and, after the first kill, , last: <name> [(appbox <box>)] (pid <pid>, <size> MB)
protected ok and the protected names, space-separated, the prefix rule last as pipewire*

The active-session answer comes from elogind’s sd_uid_get_state(), read through libelogind, which the daemon opens at first use rather than links. The daemon exists for the minute memory runs out, and a session library that is missing or broken must cost the read tier and never the killer. Root and wheel never reach that question.

kdos doctor reports whether the socket is present and lists the protected names that are not running, naming those that run only at certain times. kdos-notice reads status to say how many processes have been killed since boot.

Testing it

kdos-oomd --fixture <dir> reads a recorded /proc tree, prints the process it would kill as would kill <name> … (pid <pid>, <size> kB) with the recorded pressure, and signals nobody. It exits 0 when there is a candidate and 1 (printing no candidate) when there is none. A tree whose meminfo does not show memory short, by the rule in How it decides, prints no kill: <avail> of <total> kB available and exits 1, the answer the daemon gives a trigger there; a tree without a meminfo is judged on the stall alone.

kdos-oomd --protected prints the protected names one a line, the prefix rule last, which is what the check that holds each name to 15 bytes reads. kdos-oomd --explain <user> prints whether that user may read the socket and why, and exits 0 when permitted.

testing/oomd-fire.sh exercises the real path in a booted virtual machine: it allocates and touches memory until the trigger fires, then asks the socket what happened rather than watching the allocating process die (the kernel’s own killer would also have got it, later). A passing run shows status going from kills 0 to kills 1, last: <name> (pid <pid>, <size> MB) while the script that started the allocation keeps running. A second round then holds a process under a cgroup’s memory.high so the trigger fires while MemAvailable is still high, and exhausts memory with another inside the ten-second cool-down: it passes when the daemon still kills and the kernel’s Out of memory count in dmesg does not rise. That run has one large process to choose; which process the daemon picks on a busy desktop is what --fixture tests.

kdos-packd

The only program on the system that mounts an application pack. A pack is a signed, read-only EROFS image holding an application, a runtime it depends on, or data; how packs are built, verified and combined into a box is in Packs and boxes.

Verb Does
list Every pack the machine can see: id, version, kind, state (mounted, installed or available), size in bytes, and origin (store or medium), tab-separated, then ok
info <id> One pack’s metadata, then its state, origin and, when mounted, mountpoint
mount <id>, unmount <id> Mount or release a pack. A pack still used by a box is not unmounted
compose <box> <id>… Build a box’s overlay stack from 1 to 32 packs. Ids past the 32nd are ignored rather than refused
decompose <box> Tear it down
install <file> [<index>] Copy a pack out of the staging directory, verify the copy and move it into the store. <index> is a second staged file name, a signed index with its signature staged as <index>.sig; the daemon reads no index a request does not name
remove <id> Take a pack out of the store
rollback <id> Return to a retained earlier version
graft <id>, ungraft <id> Place a data pack’s contents where its consumer looks for them, or remove them (a graft)
ping ok
status Tab-separated lines: store, medium and staging directories, retain count, mount route (file-backed, loop device, or not yet used), packs (installed, available and mounted counts), boxes (how many are composed), and a box line for each composed box (name, merged root, ephemeral or persistent), then ok

Every verb answers root and wheel only. Launching a boxed application sends info for the pack’s environment and compose for its box; kdos-box start sends compose and kdos-box remove sends decompose. kdos-appbox genlaunchers --packs sends list and then mount for each installed pack. kdos app import, kdos-appbox import and kdos-box import copy a pack into the staging directory and send install, and an import of a data pack sends graft. Discover’s KDOS backend sends list and info to show the packs, and graft, ungraft and remove when a person installs or removes one. kdos-appbox status and kdos doctor ask for status, and kdos doctor reports the mount route. kdos app install and kdos app remove build and delete container images and ask this daemon nothing. No program on the system sends unmount or rollback; those verbs are reached only by a client that speaks the socket directly.

An id is at most 63 characters from [A-Za-z0-9._-] and does not begin with . or -; anything else is refused before it is looked up.

Paths:

Path What
/var/lib/kdos/packs The store; the current version of a pack is <id>.kpack
/var/lib/kdos/packs/staging Where an unprivileged download lands; mode 01777, set when the daemon starts
/var/lib/kdos/packs/mnt Mountpoints
/mnt/iso/packs Packs on the boot medium
/var/lib/kdos/packs/pack-manifest Every graft made, so an ungraft removes exactly what was added; in the shared store, so at start the daemon makes every host graft it names that this root lacks
/var/lib/kdos/packs/pack-manifest.ungrafted The paths an ungraft dropped, so the other slot unlinks its own copy of each at its next start
/etc/kdos/keys/packs The keys packs are verified against, separate from /etc/kdos/keys, which is kpkg’s package-repository ring
/etc/kdos/packd.conf Configuration

The daemon reads these environment variables in normal operation, not only in fixture mode. The init script sets none of them:

Variable Effect
KDOS_PACK_STORE, KDOS_PACK_MEDIUM, KDOS_PACK_MANIFEST Replace the store, the boot-medium pack directory and the graft record
KDOS_PACK_HOME, KDOS_PACK_SHARE Replace the caller’s home directory and /usr/share as graft and box-upper destinations
KDOS_PACK_RETAIN Overrides retain in packd.conf (below); a negative value counts as 0, as it does in the file
KDOS_REQUIRE_SIG Refuse every unsigned pack at install (<id> is unsigned and KDOS_REQUIRE_SIG is set), for a machine that installs only what it can attribute

All of them are also listed in Filesystem and IPC.

Installing and verifying

The client never names a path, with one exception: install takes a file name inside the staging directory. A name containing /, the name .., an empty name, or a name with a character outside [A-Za-z0-9._-] is refused. status publishes the staging directory and the retention count, so a program writing a download into the store does not have to work either out for itself; a second definition of where an unprivileged write is allowed is the kind of thing that drifts.

Verification happens in the daemon, where the mount happens, because a client that verified and then asked a daemon to mount would have verified nothing. The daemon first copies the staged pack, and the staged index the request names and its <index>.sig when there is one, into private root-owned files in the store (.install.part, .install-index.part, mode 0644), and everything after reads the copies. The staged file belongs to whoever put it in a directory every user may write, so a check on it would say nothing about the bytes a later read found. A staged symlink or anything other than a regular file is refused with err cannot read <name> from the staging directory. An install therefore needs free space in the store for a second copy of the pack while it runs.

  1. If the staging directory held a PACKAGES index whose signature is good and which lists this pack, the pack’s SHA-256 must match the index entry; a mismatch is refused (<id> does not match the signed index).
  2. Otherwise the pack’s own signature block is checked against /etc/kdos/keys/packs. A good signature is accepted; a bad one, a hash mismatch, or a signature by a key the ring does not hold is refused.
  3. A pack with no signature at all is accepted and logged as unsigned, unless KDOS_REQUIRE_SIG is set.

A pack that passes has its copy renamed to <id>.kpack, and only then is the staged file deleted; a refused install deletes the copies and leaves the staged file where it was.

A pack in the store was verified when it was written and only root can write the store, so it is not re-hashed at each mount. A pack on the boot medium was never installed, so it is verified at its first mount; there a bad signature, a hash mismatch or a missing key is refused, and an unsigned pack mounts. Every pack is mounted read-only with nosuid and nodev, and a data pack with noexec as well.

The list is rescanned on every request, so a medium pulled out between two requests is not still offered. At start-up the daemon adopts whatever packs and boxes are already mounted, so a restart while boxes are running does not lose track of them, and then makes every host graft the store’s pack-manifest names for a data pack in the store and this root lacks, so a data pack grafted from the other A/B slot is in place in this one; see Grafts and data packs.

An install replaces the old version safely. If the old version is mounted but not in use, it is unmounted before the file is swapped, so the next compose reads the new file. If it is composed into a running box, the install is refused (<id> is composed into <n> box(es) — stop them, then install), the same rule remove and rollback apply. Without this, a box composed after an update would put the new application’s layer over the old runtime’s still-mounted files, and the application would fail on a library only the new runtime carries. The version being replaced is kept as <id>-<version>.kpack beside the new <id>.kpack.

Retention and rollback

/etc/kdos/packd.conf sets how many superseded versions of each pack the store keeps:

retain = 1
Value Effect
1 (shipped) The most recent update can be undone
0 Nothing is kept; rollback answers err no earlier <id> is kept
Up to 8 That many, newest first by version; higher values are treated as 8

The daemon reads retain from the file once, when it first needs it, and keeps that value for the rest of its life; restart it (service restart packd) after changing the file. KDOS_PACK_RETAIN, when set, is read on every use.

The sweep that deletes older versions runs after an install and at no other time, so nothing deletes a rollback while somebody is deciding whether to use it. rollback keeps the current file as <id>-<version>.kpack, renames the newest retained version (by version comparison, as the sweep keeps them, so 1.10 is newer than 1.9) into its place, and answers ok <id> <current> -> <restored>. The version rolled away from stays in the store under its own version. A retained copy of the installed version itself, left by installing the same version again, is never the one restored; with nothing else retained the answer is err no earlier <id> is kept.

The store’s row for an id is <id>.kpack and no other file. A retained <id>-<version>.kpack is material for rollback and is never listed, mounted or composed. The sweep and rollback count a file as a retained version of an id only when its own metadata names that id, because an id may contain -: foo-bar.kpack is the installed pack foo-bar, not a version bar of foo.

Diagnosis and testing

kdos-packd --fixture <store> [medium] lists the packs in a scratch store with their signature state, composes each application pack, grafts each data pack (printing each graft’s destination), and prints the result, mounting nothing. KDOS_PACKD_VERBOSE shows its log lines; KDOS_KEYS points it at another key directory. The daemon reads KDOS_KEYS only in fixture mode; the kdos-pack tool reads it in normal use, to choose the ring its verify and info check against (default /etc/kdos/keys/packs). kdos-packd --fixture-graft <store> <id> is the graft verb and kdos-packd --fixture-start <store> the start-up re-graft over a scratch store, each mounting nothing but writing the links and the record for real, under KDOS_PACK_SHARE (instead of /usr/share) and KDOS_PACK_HOME (instead of the caller’s home); two share directories over one store stand for the two slots of an A/B machine.

The two mount routes, reference counting and adoption of existing mounts at start-up are described in Packs and boxes.

kdos-settingsd

The machine’s name, clock, time zone, locale and keyboards, on the system bus. KDE does not write these settings to files itself. It calls three interfaces that systemd defined, org.freedesktop.hostname1, org.freedesktop.timedate1 and org.freedesktop.locale1. KDOS has no systemd, so this daemon answers for them, with every method and property of the three interfaces except hostname1’s Describe, which nothing on the system calls. It is C on basu and libkbase and links no glib and no Qt.

Its callers are:

The system-wide /etc/xdg/kxkbrc is written by the installer and rewritten by this daemon on every locale1 layout change. A layout changed through locale1, plasma-setup’s on an OEM first boot included, therefore reaches the login screen, the session and the lock screen of every account that has no ~/.config/kxkbrc of its own. An account whose own kxkbrc names a layout keeps it. What a person sees of the daemon, page by page, is in KDOS’s settings pages.

Where each setting is kept

Each setting is kept in the file the rest of the machine already reads, and nothing is cached: every getter reads its file, so a value the installer or a person with an editor wrote is what the next caller sees.

Setting File
Static hostname /etc/hostname, which 05_hostname.sh gives the kernel at boot; the 127.0.1.1 line of /etc/hosts follows the name, because musl resolves the machine’s own name from that file and nothing else before the DNS
Pretty name, icon, chassis, deployment, location /etc/machine-info
Time zone /etc/localtime, a symlink into /usr/share/zoneinfo, and /etc/profile.d/20-timezone.sh, which exports TZ=':/etc/localtime'
Wi-Fi country /etc/modprobe.d/kdos-regdom.conf, from the zone
Network time Whether /etc/service.disabled/chrony exists
Locale /etc/locale.conf, bare NAME=value lines, which SDDM puts into every session; SetLocale refuses with InvalidArgs a value that is not C, C.UTF-8, POSIX or ll[_CC][.UTF-8\|.utf8][@modifier] whose language has a file in /usr/share/i18n/locales/musl or a directory in /usr/share/locale, and a LANGUAGE element of any other shape (no codeset) or language, so a typo never reaches every session. The territory is not checked, because plasma-setup’s language page sends LANG=<ll_CC>.UTF-8 for every language Plasma is translated into and most have no musl-locales file. A value already in the file is read as written
Console keymap /etc/keymap, which kdos-getty loads on every console, and its copy /boot/efi/EFI/kdos/keymap (below)
Graphical keyboard /etc/kdos/xkb.conf (XKBMODEL, XKBLAYOUT, XKBVARIANT, XKBOPTIONS), never under /etc/X11; and the same layout in /etc/xdg/kxkbrc ([Layout] LayoutList, VariantList, Model and Options with ResetOldOptions=true when set, Use=true), written whole on every layout change and removed for an empty layout, because KWin and the lock screen read the kxkbrc cascade before the environment xkb.conf reaches them through

Both halves of a time zone are written or the call fails. musl reads TZ where it is set, and every login sets it once the installer or the daemon has chosen a zone, so writing only the link would leave every new login reporting the old zone. The colon form points musl at the link itself, the one value that cannot drift from it, and it is the form Qt reads as “follow /etc/localtime”. It is also what moves the programs already running: KDOS’s musl re-reads the file a path-form TZ names on the next tzset() once it has been replaced (see musl’s port note), and Qt calls tzset() before every local time, so the panel clock and every Qt or KDE program take the new zone at their next update. The link is replaced by rename(), so a program never finds it missing. A C program that never calls tzset() keeps the zone it started with.

The Wi-Fi country follows the zone. The kernel’s wireless layer starts in the “world” regulatory domain, which keeps every 5 GHz DFS channel (one shared with radar) closed and caps transmit power until something names a country, and some drivers never take one from an access point. The daemon looks the zone up in zone.tab, which maps each zone to exactly one country code, writes options cfg80211 ieee80211_regdom=<CC> to /etc/modprobe.d/kdos-regdom.conf for the next boot, and runs iw reg set <CC> for this one. A zone with no country, such as UTC, removes the file and runs iw reg set 00, so the running radio returns to the world domain at once rather than keeping the previous country’s channels and power until the next boot. Neither step failing fails the zone: a machine with no radio still has a time zone. The installer writes the same file from the zone chosen during installation.

An empty layout follows the console. The installer writes the console keymap alone and the shipped xkb.conf leaves XKBLAYOUT empty, so locale1’s X11Layout is then the layout nearest /etc/keymap, and the login screen has the installed keyboard from the first boot. A derived layout is given only when xkeyboard-config carries it: KWin falls back to US for a layout it cannot compile and says so only in its log.

The console keymap has one copy, on the ESP. The disk passphrase is typed before any root is open, so the initramfs cannot read /etc/keymap; it loads the map named in /boot/efi/EFI/kdos/keymap instead (see Unlocking an encrypted root). SetVConsoleKeyboard, and SetX11Keyboard with convert, write /etc/keymap and then the ESP’s file, and an empty keymap removes both; at start the daemon rewrites the ESP’s file from /etc/keymap wherever the two differ or the file is missing. Only where /boot/efi/EFI/kdos exists, so the live medium is left alone. The ESP file is written as kdos-bootctl writes the boot state, a temporary file, its fsync, the rename, then the file’s fsync and a syncfs; failing to write it leaves the call succeeded, since /etc/keymap is the setting, and is logged. The daemon never reads the copy.

The console map nearest a layout is the 8-bit one. convert and the installer pick the console map for an XKB layout from a table, then <layout>-latin1, and only then a map named <layout>: kbd’s bare de, dk, no, fr, sg and fr_CH are the 7-bit ISO-646 maps, on which the keys for ü ö ä ß type @ [ ] \, and its pt is the OLPC laptop’s. German gives de-latin1, Swiss German sg-latin1, Swiss French fr_CH-latin1.

The hardware clock is UTC. The kernel reads it as UTC at boot and writes it back every eleven minutes while chrony has the clock synchronised, so LocalRTC is false and SetLocalRTC(true) is refused. A clock set by hand is not synchronised, so SetTime writes the hardware clock itself.

Network time is chrony. CanNTP is true when chrony’s init script and chronyd are both installed. SetNTP(true) removes the marker and runs service start chrony; SetNTP(false) puts it back and runs service stop chrony. On a machine without chrony, SetNTP(true) answers NoNTPSupport and SetNTP(false) succeeds, as systemd-timedated’s does: the Date & Time page sends SetNTP(false) on every Apply when CanNTP is false, and refusing it would fail the whole Apply.

Checking, then asking, then writing

A method validates its arguments before polkit is asked, so a bad value is refused without a password prompt, and polkit answers before a single byte is written. Every value is checked against a character set and, where the machine carries the list, against the list: a zone must be a regular file in the zone tree that starts with the TZif magic, a console keymap must be one of kbd’s keymaps and an XKB layout one of xkeyboard-config’s rules/evdev.lst. A name that passes the character rule and names nothing is refused, because a keymap nobody can load and a layout no compositor can compile both fail silently later, at the login screen, where nobody can type the way out.

Root is answered without asking polkit. Everyone else gets polkit’s answer under systemd’s own action ids, because plasma-setup’s rule and the Date & Time page name them:

Action Active local session
org.freedesktop.timedate1.set-time auth_admin_keep
org.freedesktop.timedate1.set-timezone yes
org.freedesktop.timedate1.set-ntp yes
org.freedesktop.timedate1.set-local-rtc auth_admin_keep
org.freedesktop.locale1.set-locale auth_admin_keep
org.freedesktop.locale1.set-keyboard auth_admin_keep
org.freedesktop.hostname1.set-hostname, set-static-hostname, set-machine-info auth_admin_keep
org.freedesktop.hostname1.get-product-uuid, get-hardware-serial auth_admin_keep

set-time implies set-timezone and set-ntp. The Date & Time page authorises set-time before it saves anything, whatever changed, so every Apply there asks for an administrator’s password, which then covers its three calls. The zone and network time pass with no password only from a caller that asks for them alone, such as kdos timezone or plasma-setup. The last two rows guard the values that identify the machine, which the kernel lets only root read.

An interactive question may stay open for five minutes, after which the call is refused; no answer from polkit is a refusal.

The programs it runs, service, loadkeys and iw, are argument vectors found through PATH and skipped when missing, because every argument they are given came over a bus.

Starting and testing it

43_settingsd.sh starts the daemon under ksvc after polkitd and before the display manager, with --restart-with dbus and --final-exit 3, and waits for all three names. It exits 3 when another process owns one of them. A kernel left with no hostname, which is what SetStaticHostname("") and a missing /etc/hostname produce, is given the default name (DEFAULT_HOSTNAME= in os-release, else kdos) when the daemon starts.

KDOS_SETTINGSD_ETC, KDOS_SETTINGSD_SHARE and KDOS_SETTINGSD_SYS replace /etc, /usr/share and /sys, and the first also keeps the daemon off the machine it runs on: with it set the kernel’s hostname, the clock and the hardware clock are left alone, and the ESP’s keymap copy is written only when KDOS_SETTINGSD_ESP names a scratch ESP directory. testing/selftest.sh drives every method that way, over a private bus, against a polkit stand-in in testing/fixtures/settingsd/.

kdos-sysupdated

The bus face of a KDOS system update. Discover’s stock SystemdSysupdate backend is how Plasma shows an operating-system update, and this daemon serves org.freedesktop.sysupdate1 the way Discover 6.8.2 calls it, so Discover drives a KDOS update with no patch. It does no update work itself: every check, download, install and boot decision is a run of kdos update or kdos-bootctl, executed with an argument vector, both found through the daemon’s PATH, and the daemon waits for them without blocking the bus. It also serves io.kdos.Slots1 for the System Versions page and the update notifier, and it is the root half of the boot confirmation that keeps a new slot. What an update is, where it comes from and how the slots are chosen are in Updating a machine and A/B slot selection; how Discover drives it is in Discover.

What Discover calls

Call Answers
Peer.Ping Whether the backend is there at all
Manager.ListTargets One target, host, at /org/freedesktop/sysupdate1/target/host
Manager.ListJobs, ListAppStream The running job; the AppStream URL
Target.GetAppStream file:///run/kdos/sysupdate/io.kdos.system.metainfo.xml
Target.GetVersion The running version
Target.CheckNew The version on offer, or empty for nothing. Discover calls it when it opens and on Refresh; it fetches the signed indexes at most once per --refresh-after and downloads no package
Target.List, Describe The installed and offered versions
Target.Acquire("", 0) All the long work: kdos update apply --acquire --mount --progress 3. Its reply is a job path, whose Progress Discover watches
Target.Install("", 0) The short arm: kdos update apply --arm --mount --progress 3
Target.Vacuum 0: the slots are the history, and nothing is vacuumed
Job.Cancel Stops the running child
Manager.JobRemoved Sent once, when a job this daemon replied with ends

Acquire answers only after kdos update has said verified or refused. Discover shows a failed call’s message in the details of its “Update Issue” sheet, leaving nothing pending (the discover port’s sysupdate-errors.patch offers a restart only after Install succeeds), but shows a failed job as nothing more than “failed”. So everything that can refuse an update is learned before the reply: a release index, binhost index or image manifest that no trusted key signed, a file the release index does not name, a package the binhost does not cover, a slot that cannot be mounted. Only an update that can go ahead becomes a job. JobRemoved is sent only for a job this daemon replied with, because Discover ends whatever transaction it is waiting on at the first one it sees.

Acquire and Install take "", the offered version, which is what Discover sends, or that version by name; any other version answers that it is not available. Only one job runs at a time, and a call during the hourly check is refused until the check finishes, because the fetch holds the update lock the apply would take. Every one of these is checked again once polkit has answered, since an administrator’s prompt can stay open for minutes: a call whose version is not the one offered or acquired at that moment is refused, and nothing other than the version that was authorised is installed.

A trial boot is offered nothing. While this boot is the trial of the other slot, the slot an update would fill is the confirmed way back, so CheckNew answers empty and Acquire is refused until the trial is confirmed or rolled back. A machine with no second root slot is offered no system update. Its CheckNew runs kdos update fetch --binhost-only as root, at most once per --refresh-after, which fetches the signed binhost index of the release the tree in place is into /var/lib/kdos/binhost, and answers empty when that ends, so Discover reports the system up to date and a session with no terminal still gets the prebuilt programs and the group sizes Make It Yours shows. The time of the last such fetch is the binhost line of /var/lib/kdos/update.state; a line whose code is no-network or fetch-failed counts as no fetch, so the next CheckNew after connecting tries again at once. Such a machine never runs kdos update check --fetch. Its Acquire and Install are refused before any busy check, even while that fetch runs, so the reply never says to try again: on a single-root install it names kdos update apply, which updates it in place at a shell, and on the live medium it says that nothing installed there survives a restart and that KDOS is to be installed. The AppStream file names the live medium as the live session.

The update document belongs to the root that wrote it. On a machine with slots, CheckNew reads /var/lib/kdos/update.json. At most once an hour (--refresh-after) it also runs kdos update check --fetch, which fetches the signed tree and release index and, through that index, the binhost index and the slot image manifest, so what it offers is only what the index named. The hour is judged by the fetch line of /var/lib/kdos/update.state. A no-network code there counts as no fetch, so the next CheckNew after connecting tries again at once; a fetch-failed keeps its time.

The document is kept in each slot, so the first boot of a slot, or the boot a rollback returns to, finds one written before that root was what it is now. A document whose installed is not the running version offers nothing, and the daemon rewrites it at start with kdos update check --out, which downloads nothing. The daemon watches /var/lib/kdos and regenerates the AppStream file whenever the document changes, so a check typed at a shell reaches Discover too.

The AppStream file lives on /run. /run/kdos/sysupdate/io.kdos.system.metainfo.xml is what Discover shows for the update. It carries:

The size reads “to copy” when the offered lane’s origin is a directory or a file:// URL, and “to download” otherwise. The origin is the document’s image field for the image lane and its binhost field for the packages, which is where kdos update fetches the bytes from: update.conf’s image = and binhost = lines, $KDOS_UPDATE_IMAGE and $KDOS_UPDATE_BINHOST, else the release’s https defaults. The tree’s channel does not decide it. The copy in /usr/share/kdos/update/ is the fallback that names the system and offers nothing.

io.kdos.Slots1

The System Versions page and kdos-notice read the slots through io.kdos.Slots1. Its contract is the page’s own io.kdos.Slots1.xml:

Kind Members
Properties Configured, Live (the live medium, from kdos-bootctl status --json), RunningSlot, ActiveSlot, TrySlot, TryAttempts, TryBootNext, Channel, InstallRoute, BuildDeps, State
Methods ListSlots, Try, CancelTry, SetChannel, SetInstallRoute, Bless
Signal SlotsChanged

Each ListSlots entry’s state is the first of trial, visiting, incomplete, failed, abandoned, confirmed, installed and empty that holds. visiting and abandoned are kdos-bootctl status --json’s own words for the slot: visiting is one boot of a root picked at the boot menu, and abandoned a trial set aside there, which is not a failure. The entry carries the booleans failed, abandoned and incomplete beside its state.

InstallRoute and BuildDeps are the install = and build-deps = lines of /etc/kdos/update.conf, the route kdos update install takes when no flag names one and the route of what a source install lacks: each prebuilt or source, and prebuilt when the line is absent or holds anything else, which is what kdos update does with it. SetInstallRoute(ss install, deps) writes both lines, every other line of the file kept as it was, and answers InvalidArgs for any word but those two; PropertiesChanged announces both properties.

SetChannel(s) writes the tree = line of update.conf, or removes it for "". It takes an absolute directory, an https:// URL or a file:/// URL. Anything else, http:// among them, is answered with InvalidArgs “not an update channel: ” and nothing is written, because kdos update fetches with curl’s --proto =https,file. The channel names where the tree comes from; the binhost and the image keep their own lines.

Confirming a boot

A slot is confirmed only when two marks exist, tested together, both root’s regular files in /run/kdos/bless/:

Mark Written when
userspace The end of rcS: every service started
graphical A Plasma session answered for a minute (Bless, which kdos-notice --bless calls), or the login greeter stayed up for a minute on a machine SDDM does not log in automatically

Then the daemon runs kdos-bootctl mark-good, once per boot, and writes /run/kdos/bless/confirmed after it succeeds. Either mark alone confirms nothing: a system whose services all start but whose desktop crashes is the failure a trial exists to catch.

The greeter counts only on a machine with no automatic login, and only before any user session has existed this boot, because a greeter that came back after the session crashed must not confirm the slot that crashed it. On such a machine the greeter is the graphical check, so a desktop that fails only after a login is not caught. Waiting for a session instead would roll a good release back whenever its one trial boot is left at the login screen. The way back from such a desktop is Start This Version Next Time on the other slot, in System Versions.

The greeter is recognised as an sddm-greeter and a kwin_wayland both running as SDDM’s account, sddm, by the uid /etc/passwd gives it. The names alone are not enough, since any account can start two processes called that. A machine whose inittab starts no display manager has no graphical half to wait for, and the first mark is enough there.

Who may call it

Root is answered without asking polkit, and the bus policy lets only root own the two names.

Action Methods Active local session Inactive and any other
org.freedesktop.sysupdate1.check CheckNew yes auth_admin
org.freedesktop.sysupdate1.update Acquire, Install, Cancel auth_admin_keep auth_admin
org.freedesktop.sysupdate1.update-to-version Acquire and Install naming a version auth_admin auth_admin
io.kdos.slots.try Try, CancelTry auth_admin_keep auth_admin
io.kdos.slots.channel SetChannel auth_admin_keep auth_admin
io.kdos.slots.install-route SetInstallRoute auth_admin_keep auth_admin
io.kdos.slots.bless Bless, never interactive yes no

A CheckNew polkit does not allow, denied or answered with a challenge nobody takes up, is not an error: it is answered from the update document with no fetch, after any check already running has rewritten it, as an allowed caller is. The offer is the document’s, which every account reads, so the action guards only the network fetch; an error would be an “Update Issue” sheet in Discover for a caller outside the active session, such as a program started from the live medium’s console, that a quiet answer loses nothing by. Every other method’s refusal is the call’s error.

Running and testing it

kdos-sysupdated [--session] [--root DIR] [--proc DIR]
                [--bless-after SECONDS] [--tick SECONDS] [--refresh-after SECONDS]
Option Default Effect
--session off Serve the session bus, which is where Discover looks with DISCOVER_TEST_SYSUPDATE=1
--root DIR / Read and write every file under a fixture root
--proc DIR /proc Read processes from another tree
--bless-after 60 Seconds the greeter must stay up to earn the graphical mark
--tick 5 Seconds between checks of the boot state
--refresh-after 3600 Seconds between fetches by CheckNew (the tree and indexes, or the binhost index alone on a machine with no second slot); 0 never fetches

--session --root together is how the whole flow runs without root. Without --session the daemon refuses to start unless it is root. It exits 1 when its bus goes away, for the supervisor to restart it with the bus, 2 on bad usage, and 3 when another process owns one of its names. SIGHUP rereads every file it serves from. The children’s standard error is the daemon’s, so a failed update is read line by line in syslog under kdos-sysupdated.

46_sysupdated.sh starts it under ksvc with --restart-with dbus and --final-exit 3 and waits for org.freedesktop.sysupdate1. The interface is tested against Discover’s own XML: tests/org.freedesktop.sysupdate1.xml beside the source is discover-6.8.2’s, byte for byte, and testing/selftest.sh diffs the daemon’s introspection against it and against the Slots1 contract.

kdos-mdnsd

kdos-mdnsd answers DNS questions about .local host names from Avahi, so that ping, ssh, a browser, getent hosts and CUPS resolve <host>.local on musl, which has no NSS for an nss-mdns module to hook into getaddrinfo(). Every host lookup goes to /etc/resolv.conf’s 127.0.0.1, NetworkManager’s dnsmasq, and /etc/NetworkManager/dnsmasq.d/kdos-mdns.conf (server=/local/127.0.0.1#5380) forwards the local domain to this daemon on UDP 127.0.0.1:5380. For each question it opens Avahi’s simple-protocol socket, /run/avahi-daemon/socket, and sends RESOLVE-HOSTNAME-IPV4 <name> or RESOLVE-HOSTNAME-IPV6 <name>.

Question Answer
A or AAAA for a name ending in .local, Avahi answers + <if> <proto> <name> <address> One record with that address, TTL 10 seconds
The same, Avahi answers -, says nothing for three seconds, or gives an IPv6 link-local address NOERROR, no answer, and an SOA for local whose minimum is 10 seconds, which dnsmasq caches
Any other type under .local The same empty answer
A name outside .local, the bare local, or a name holding a byte other than a letter, digit, -, _ or UTF-8 REFUSED
A truncated question, a compression pointer that does not point back before the last one followed, more than one question FORMERR
Avahi’s socket cannot be reached, Avahi ends the connection before a reply line, or 48 clients’ questions are already open (under Avahi’s own limit of 50 simple-protocol clients, past which it closes the connection) SERVFAIL, which dnsmasq does not cache
A packet shorter than a header, or a response Nothing

A miss is never NXDOMAIN: musl’s getaddrinfo() asks A and AAAA together and fails the whole lookup on an NXDOMAIN to either, so an IPv4-only host would resolve to nothing. Once one family has answered, the other family’s question for the same name gets half a second more rather than the rest of its three, because Avahi already holds every address record the responder sent. A question for one family also asks Avahi for the other, with no client waiting on it, and the last 48 answers and misses are kept for ten seconds: a later question for a name and family in that table is answered at once, and one whose family is still being asked joins that question. musl’s getent hosts asks AAAA and only after its miss A, so a name nothing answers fails in one three-second wait, not two. The other family’s question takes one of the 48 slots, is not asked when none is free, and is closed to free its slot for a client’s question that finds none, so it never costs a client a SERVFAIL. An IPv6 link-local address is left out because a DNS record cannot carry the interface it belongs to. Each question has its own non-blocking connection to Avahi, and poll() waits on all of them, so a name that never answers delays no other.

It is the one daemon here that does not keep root: 45_mdns.sh starts it, it binds the port and then becomes nobody (no supplementary groups, no_new_privs) before it reads a packet, and it refuses to run if it can still become root. It links libkbase alone and has no socket in /run, no bus name and no client. 45_mdns.sh sorts after 45_avahi.sh, starts it under ksvc with --restart-with avahi-daemon, and skips it when avahi-daemon is not installed or /etc/service.disabled/avahi exists. A machine whose network is run by 30_network’s dhcpcd has no dnsmasq to forward to it; see Known gaps.

kdos-mdnsd [--port N] [--socket PATH] [--user NAME]
kdos-mdnsd --answer QUERY-FILE AVAHI-REPLY

--port 0 takes a port the kernel picks and prints it on the first line; --socket asks another Avahi socket; --user names the account to become, and only root becomes one. --answer runs one DNS packet from a file through the parser and the answer builder against a recorded Avahi reply line (empty for none) and writes the response packet to standard output, exiting 3 for a packet that gets no answer. testing/selftest.sh drives both through testing/fixtures/mdnsd/drive.py: good A and AAAA questions, misses, refusals, truncated packets and compression loops through --answer, and the daemon against a fake Avahi with one name that never answers beside one that does.

kdos-boxsock

kdos-boxsock is not a root daemon and has no socket in /run. It is installed in /usr/bin, runs as the desktop user, one process per box launcher, and gives that launcher a Wayland socket of its own that KWin tags, so the compositor always knows which box a window came from. kdos-appbox runs it on every launch; the box’s side of it is in kdos-appbox.

kdos-boxsock [-s confined|tagged] <box> [<launcher-id>]

What it does:

  1. Checks the box name: 1 to 63 characters from [A-Za-z0-9._-], the first a letter or a digit, so an option is never taken for a name. The launcher id is the box itself, the box plus one more component (one launcher of a box with several, <box>.<stem>), or the box less its last component (a throwaway box, <launcher-id>.tw<n>, whose windows are its application’s); it defaults to the box. -s is confined unless given. -h or --help alone prints the usage and exits 0; bad usage exits 2.
  2. Checks that the box’s private runtime directory, $XDG_RUNTIME_DIR/kdos/box/<box>, exists and is this user’s alone. kdos-appbox makes it; a box sees it as its whole /run/user/<uid>, so a socket bound anywhere else is one the box cannot reach.
  3. Takes a lock on $XDG_RUNTIME_DIR/kdos/box/.<box>.wl[.<stem>]@<display>.lock, beside the private directory and not inside it, so nothing in the box can take it. The holder writes its pid and its engine into the lock. A second run for the same socket prints the holder’s path when the holder serves the same state, or stops the holder and takes over when it serves the other one.
  4. Binds wl[.<stem>]@<display> in the private directory, mode 0700, so only this user can connect.
  5. Hands it to KWin through the Wayland security-context protocol, tagged with the engine io.kdos.appbox+private for a confined box or io.kdos.appbox+tagged for one with a way past the tag, the launcher id as the application id, and the box as the instance id.
  6. Prints ready <path> on standard output, or error <reason> when it cannot tag, closes standard output so its caller reads to end of file, and stays alive holding the descriptor that keeps the tag valid. When the compositor exits, it removes the socket and exits too.

Every client that connects on that socket is tagged by KWin itself; the client never sees the tag, so it cannot forge, choose or drop it. What the tag carries is read in three places:

<display> is taken from $WAYLAND_DISPLAY: its last path component, reduced to [A-Za-z0-9._-] and cut to twelve characters, or session when nothing is left. It is in the path because the listener belongs to the compositor this process connected to; a path keyed on the box alone would send a later launch through a compositor that may already be gone. kdos-appbox derives the same path from the same variables, so the two agree with nothing passed between them.

If the compositor does not offer the security-context protocol, kdos-boxsock answers error the compositor has no security-context-v1 rather than bind an untagged socket, and kdos-appbox refuses to start the box with that line as the reason. An untagged socket would be indistinguishable from the compositor’s own.

It is a separate program for two reasons:

The port is src/system/kdos-boxsock, built in the 42_graphics phase with libwayland-client.

The other services ksvc runs

These root services come from upstream ports, and KDOS starts each from /etc/init.d under supervise like its own daemons. None of them is started by D-Bus activation: each port ships no activation file, so a caller that came before the name was owned is refused rather than handed a second, unsupervised copy that would then hold the name the supervised one needs.

Init script Service What it is for
40_elogind.sh elogind org.freedesktop.login1: every login registers here, KWin takes the seat through it, polkit asks it who is at the machine, and Plasma’s Shut Down, Restart and Suspend are its calls. Configured by /etc/elogind/logind.conf.d/50-kdos.conf and sleep.conf.d/50-kdos.conf. Run with SYSTEMD_REBOOT_TO_BOOT_LOADER_ENTRY=1, so login1’s RebootToBootLoaderEntry is the file kdos-bootctl try writes, /run/systemd/reboot-to-boot-loader-entry, and the logout screen can name the slot a restart boots
41_polkitd.sh polkitd The authorisation every bus daemon here asks. What KDOS adds to the defaults is /etc/polkit-1/rules.d/50-kdos.rules
44_accounts.sh accounts-daemon org.freedesktop.Accounts: the Users page, plasma-setup’s first account, and the avatar the login screen shows
48_iio-sensor-proxy.sh iio-sensor-proxy net.hadess.SensorProxy, for screen rotation and ambient-light brightness. Started only where udev tagged a sensor it can drive
55_tlp.sh tlp Not supervised: it applies TLP’s settings at boot and exits
56_tlppd.sh tlp-pd Power profiles for PowerDevil and the battery applet, as org.freedesktop.UPower.PowerProfiles and net.hadess.PowerProfiles; each switch runs tlp power-saver\|balanced\|performance
65_turnstiled.sh turnstiled Every login’s runtime directory and every user’s services under ksvc; the greeter cannot start without it
85_crond.sh crond Users’ crontabs, from cronie. The system’s own scheduled jobs are snooze’s timers, and cronie reads no /etc/crontab

elogind, accounts-daemon, iio-sensor-proxy and tlp-pd are restarted with the system bus (--restart-with dbus). How each fits into the boot and the session is in Boot and init and The session.

utmpd and wtmpd

Two services that are not KDOS’s own and not root keep the login records musl cannot: utmpd holds who is logged in now and wtmpd appends the history to /var/log/wtmp. Both come from the utmps port, each run as utmps-utmpd or utmps-wtmpd behind s6-ipcserver (from s6) as the utmp account, and 06_utmps.sh starts both under ksvc with the supervised names utmpd and wtmpd. The service name for service and /etc/service.disabled is utmps, and disabling it leaves who, w, users and last with nothing to report. What each socket and file holds, who may write to them and why every reader is built against utmps is in Login records.

Adding a root daemon

A new daemon should meet all of these. Where an existing one does not, the exception is stated in its section. The standing exception is rule 8: kdos-powerd finds kdos-bootctl through PATH, kdos-settingsd finds service, loadkeys and iw, and kdos-sysupdated finds kdos and kdos-bootctl.

  1. It runs in the foreground and is started by an /etc/init.d script through supervise, with no D-Bus activation file.
  2. Its script skips with a printed reason, before supervision, when the machine cannot support it.
  3. It owns exactly one socket in /run, mode 0666, or its names on the system bus with a bus policy that lets only root own them, and refuses to serve its real socket or the system bus unless it is root (or, like kdos-energyd, cannot start at all without root’s access).
  4. A socket authorises on the caller’s credentials, root and wheel, by calling kb_uid_allowed(), never a copy of that test, and answers err not permitted otherwise; what it admits beyond that comes from elogind or polkit, never from a group. A bus method asks polkit about the caller’s bus name, asynchronously, under an action id with its own .policy file.
  5. No verb takes a path. Identifiers come from a list the daemon published.
  6. A connection that never speaks, and a polkit prompt nobody answers, cannot stall anything the daemon does on a timer, a trigger or the bus.
  7. It has a --fixture mode that decides and prints without acting, or, like kdos-powerd, kdos-settingsd and kdos-sysupdated, a way to run its rules against a scratch tree.
  8. Every program it runs is named by absolute path and executed through an argument vector, never a shell.
  9. It links only libraries whose every line you are willing to run as root, and no toolkit. Today that is libkbase, libkcolor, libkproc and basu, and for kdos-packd libksig, libkpkg and libkpack, which verify and read packs.
  10. Its refusals are documented in this chapter, including the ones that look like limitations.

Where the pieces go is fixed as well. The source and its recipe (kpkgbuild and build.sh) are src/daemons/<name>/, the area that holds the six root daemons above and kdos-mdnsd (kdos-boxsock is a session program, under src/system/); the port is named under the src-daemons heading of script/phases/50_desktop/packages.txt, the only phase whose PORT_REPO includes src/daemons; and its init script is fs/etc/init.d/<NN>_<service>.sh, whose number places it after everything it needs, since rcS starts the scripts in numeric order. The six here are 43, 46, 55, 56, 57 and 59: the bus daemons after polkitd (41), the others after the network; kdos-mdnsd is 45, after Avahi.

See also


Part IV — Programs, chapter 26. Previous: 25. kdos-appbox · Contents · Next: 27. kinstall