Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

79.13. turnstile-0.1.11

Per-user service manager launcher: login tracking, the runtime directory and a backend per user

Version 0.1.11, release 1
Shelf auth — Authentication, authorisation, accounts and directory services
Phase 41_system (System), 187 of 1047 in build order
Licence BSD-2-Clause
Homepage https://github.com/chimera-linux/turnstile
Build time 0.1 SBU
Installed size 143.6 KiB in 7 files
Recipe ports/core/auth/turnstile/kpkgbuild

About

turnstile is the part of systemd --user that Plasma needs, and nothing else. Its daemon, turnstiled, counts each user’s logins across SDDM, the text consoles and anything else that runs the PAM module pam_turnstile: at the first login it creates /run/user/<uid> and starts that user’s service manager through a backend, and at the last logout it stops the services and removes the directory, unless the user lingers. The PAM module holds the login until the backend reports its services ready, then exports XDG_RUNTIME_DIR and DBUS_SESSION_BUS_ADDRESS into the session.

On KDOS the backend is ksvc, the script /usr/lib/turnstile/ksvc, which runs the scripts in /etc/kdos/user-services/ under ksvc: the session bus at $XDG_RUNTIME_DIR/bus, the account’s ssh-agent, PipeWire, WirePlumber, pipewire-pulse, mpd once it is configured, the user’s timers, and the stop of the user’s boxes at the last logout. Every account from uid 1000 gets them, and so does plasma-setup, the system account the first-boot wizard runs in; the greeter’s sddm account gets the session bus alone, and other system accounts nothing. Both it and /etc/turnstile/turnstiled.conf come from the tree’s fs/ overlay, not from this port. turnstiled itself runs as root under ksvc from an init script. See No systemd init, units or service manager.

Sources

Dependencies

Depends on: meson, ninja, pkgconf, pam, scdoc.

Required by (1): sddm.

Patches

build.sh applies these; kpkg applies nothing by itself.

The last logout’s clear of the runtime directory leaves every mount point in it alone (rundir-mounts.patch). KDOS’s pack daemon composes each box’s root as an overlay under /run/user/<uid>/kdos/boxes/<box>/root, whose upper directory is the box’s persistent state in the user’s home, so a clear that descended into it would write a whiteout for every file of the box.

A login that arrives while the previous manager is stopping waits for that manager to exit and for the next one to report ready (stopping-manager-readiness.patch). Upstream releases it on the stopping manager’s readiness when that manager was still coming up as the last session closed, and SDDM’s automatic login after loginctl terminate-user lands there: Plasma starts on the session bus that is being stopped, kded6 and plasmashell lose it, and the screen stays black. The same patch closes a stopped manager’s unreported readiness pipe when the next one starts, since an event on it would otherwise make turnstiled exit. The patch is to be offered upstream.

session-socket-cloexec.patch opens the connection pam_turnstile makes to turnstiled, which is the login, close-on-exec. turnstiled counts a login as ended only when the last copy of that connection closes, and without the flag every program the PAM caller executes inherits one: SDDM’s session, Plasma and every process started from it, a box’s kdos-appbox keeper, conmon and podman exec included. A box or any other process from the session still running at Log Out then holds the login open, and the last logout never stops the user services or clears /run/user/<uid>. With the flag only the PAM caller holds the login: sddm-helper opens the PAM session and then forks and executes the session, and closes the PAM session when the session process exits; util-linux login opens it, forks the shell and closes it when the shell exits. A PAM caller that executes the session in its own process, with no parent left to call pam_close_session, would end the login at once; no PAM stack on KDOS that loads pam_turnstile belongs to one. The X server probe socket the module opens is made close-on-exec as well. The patch is to be offered upstream.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install turnstile'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/auth/turnstile.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/auth/turnstile
echo '04904eff68a726bed281820b3497e018ede55a5d745f31ceb9a502f905d0ed56  turnstile-0.1.11.tar.gz' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/turnstile
SRC=$SRC_ROOT/turnstile-0.1.11
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf turnstile-0.1.11.tar.gz -C "$SRC" --strip-components=1

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

patch -p1 -i "$PORT_SRC/rundir-mounts.patch"
patch -p1 -i "$PORT_SRC/stopping-manager-readiness.patch"
patch -p1 -i "$PORT_SRC/session-socket-cloexec.patch"

meson setup build \
	--prefix=/usr --sysconfdir=/etc --libdir=lib \
	--libexecdir=/usr/lib \
	--buildtype=release \
	-Ddinit=disabled \
	-Drunit=disabled \
	-Dmanage_rundir=true \
	-Dstatedir=lib/elogind \
	-Dlibrary=disabled \
	-Dman=true
meson compile -C build
DESTDIR=$PKG meson install --no-rebuild -C build

rm "$PKG/etc/turnstile/turnstiled.conf"
rmdir "$PKG/etc/turnstile"

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/turnstile, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf turnstile-0.1.11-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/turnstile, and runs the triggers its paths call for.

Contents

Installed programs: turnstiled.

Installed directories: /usr/share/licenses/turnstile.

Short descriptions

turnstiled the main session management daemon

Notes

The recipe deletes /etc/turnstile/turnstiled.conf, which the build generates from its options. KDOS’s own copy is in fs/ and sets backend = ksvc, manage_rundir = yes, export_dbus_address = yes and linger = maybe; a copy in the package would be installed over it, because packages are installed after fs/ is synced. default_backend is not passed: it changes only the generated file, and turnstiled’s own built-in backend is dinit whatever the build says, so without KDOS’s file every login would try to run a dinit backend that does not exist. The runtime-directory default does reach the daemon, through -Dmanage_rundir=true.

/etc/pam.d/turnstiled is upstream’s: the PAM stack of the session turnstiled opens for the user’s service manager. It includes pam_elogind, so elogind sees that session, and pam_limits, so the realtime and memory-lock limits in /etc/security/limits.d reach PipeWire, which the backend starts inside it, and not only the login shell.

turnstiled waits for the backend’s readiness report for at most login_timeout seconds and then ends the user’s service manager and closes the user’s session connections, so a backend that never reports ready shows up as a login that hangs for that long and then has no user services.