How skarnet/s6 works
1. What this repository is
s6 is a C-based Unix process supervision toolkit. The repo builds a set of small command-line programs plus shared libraries that manage supervised services, logging, notification, file descriptors, and IPC. It is not a single daemon application; it is a toolbox whose components are composed by the operator or by higher-level suites such as s6-rc and s6-linux-init.
2. Top-level architectural shape
The code is organized around functional subsystems in src/: supervision, pipe/FIFO signaling, file-descriptor holding, connection and IPC tools, “daemontools extras,” instance management, user-tree management, and alias wrappers. Each subsystem produces one or more executables and usually one supporting library layer in src/libs6 or local headers under src/include/s6.
3. Core supervision subsystem
src/supervision contains the main runtime tools that watch and control services: s6-svscan, s6-supervise, s6-svc, s6-svstat, s6-svwait, s6-svlisten, s6-svlink, and related helpers. This is the central control plane: it tracks service state, sends control commands, and exposes status. The data flow is from service directories and control pipes/FIFOs into supervision state, then out to status/notification consumers.
4. Service directory and status model
The docs and code refer heavily to service directories, scandirs, and supervise directories. src/libs6/s6_servicedir_*, s6_supervise_*, and s6_svstatus_* show that service metadata and runtime state are represented on disk and updated through small primitives. This is a key boundary: the supervision layer uses filesystem state, not an in-memory central registry.
5. Notification and FIFO signaling
src/pipe-tools and parts of src/libs6 implement FIFO-based event delivery and wait/notify semantics: s6-ftrig-*, s6-mkfifodir, s6-cleanfifodir, and s6-ftrigw_*/ftrigr_*. These pieces form the event bus for the suite: a producer writes a trigger to a FIFO directory, and subscribers wait or react. This is how many tools synchronize without polling.
6. File descriptor persistence subsystem
src/fdholder and src/libs6/s6_fdholder_* implement the fdholder service and client utilities. The daemon stores open file descriptors and later returns them to clients. This is a distinct coordination boundary based on Unix domain IPC and descriptor passing, useful for socket activation and service restarts without losing listening sockets.
7. Connection, IPC, and access control tools
src/conn-tools includes s6-ipcserver, s6-ipcserverd, s6-ipcclient, s6-ioconnect, s6-connlimit, and the s6-sudo family. These programs manage stream or IPC socket servers, client connections, connection limits, and privileged handoff. Access policy support is split between filesystem and cdb-based rules via s6-accessrules-* in both the executables and src/libs6, which is an important security boundary around network-facing services.
8. Daemontools-compatible process wrappers
src/daemontools-extras provides compatibility and utility wrappers such as s6-setuidgid, s6-envdir, s6-softlimit, s6-log, s6-socklog, s6-tai64n, and ucspilogd. These are not the supervision core, but they are the standard process-preparation and logging building blocks used in service run scripts. They define the pre-start and logging pipeline around supervised programs.
9. Instance and user-tree management
src/instance and src/usertree handle higher-level organization of service instances and per-user supervision trees. The instance tools create, list, inspect, delete, and control instances, while the user-tree maker bootstraps per-user layouts. These modules sit above the raw supervision primitives and turn them into manageable service sets.
10. Shared library layer
src/libs6 is the reusable implementation layer for the executables. It contains the low-level state packing/unpacking, async fdholder client logic, ftrigr/ftrigw client logic, accessrules backends, and supervision/service-directory helpers. The library layer is where the common Unix protocol logic lives; the command-line tools are mostly thin front ends over these functions.
11. Aliases and compatibility entry points
src/alias contains small alternate-entry executables like s6-alias, s6-alias-chpst, and s6-alias-sv. This suggests the project preserves familiar names from other supervision ecosystems while mapping them to s6 behavior. Architecturally, these are wrappers rather than separate subsystems.
12. Build and packaging structure
The project is a traditional autotools-style C build with configure, Makefile, and package/ configuration snippets. The src/*/deps-exe and deps-lib files encode per-target dependencies, while tools/ contains scripts for generating configure/dependency artifacts and test helpers. This build layout reflects the repo’s many small binaries and shared code fragments.
13. Documentation and examples as architecture guides
doc/ contains one page per executable plus conceptual pages for service directories, notification, socket activation, and supervision. examples/ shows canonical service layouts such as syslogd and klogd. For diagramming, these examples are useful because they reveal the intended composition: run scripts, optional log services, notification files, and supervised daemons connected by FIFOs and sockets.
14. End-to-end data flow
The dominant runtime flow is: a service directory defines a supervised program; s6-svscan discovers it; s6-supervise runs and monitors it; run/log scripts may wrap the process with UID/GID, limits, and logging helpers; notification and trigger FIFOs signal readiness or events; fdholder and IPC tools exchange descriptors or connection streams; status and control commands query or modify the live service state. The filesystem is the coordination plane, and Unix IPC is the runtime transport.
Main entry points: s6-supervise.c supervise · s6-ftrig-notify.c ftrig · s6-fdholderd.c fdholderd · s6-instance-create.c instances
Components 20
Supervision
Service discovery, state tracking, and control plane tools.
- svscan · Discovers service directories and launches supervised services.
src/supervision/s6-svscan.c - supervise · Runs and monitors one service directory.
src/supervision/s6-supervise.c - svc · Sends control commands to a supervised service.
src/supervision/s6-svc.c - svstat · Reads and reports service status.
src/supervision/s6-svstat.c - svwait · Waits for service state transitions.
src/supervision/s6-svwait.c - svlisten · Waits on multiple services and reacts to status changes.
src/supervision/s6-svlisten.c
Events
FIFO and trigger-based notification primitives.
IPC
Descriptor holding, sockets, and access-controlled connection tools.
- fdholderd · Stores and returns open file descriptors over IPC.
src/fdholder/s6-fdholderd.c - fdholder clients · Store, retrieve, list, delete, and dump fdholder state.
src/fdholder/s6-fdholder-store.c - ipcserver · Runs access-controlled IPC servers and connection handlers.
src/conn-tools/s6-ipcserver.c - ipcclient · Connects to IPC services and bridges streams.
src/conn-tools/s6-ipcclient.c - accessrules · Converts and checks filesystem and cdb access rules.
src/libs6/s6_accessrules_backend_cdb.c
Wrappers
Process setup, logging, and compatibility entry points.
- logging wrap · Loggers and process-prep helpers such as envdir, setuidgid, softlimit, and socklog.
src/daemontools-extras/s6-log.c - aliases · Alternate entry points preserving familiar tool names.
src/alias/s6-alias.c
Managers
Higher-level instance and user-tree orchestration.
libs6
Shared implementation layer used by the executables.
- service dir · Reads and writes service-directory and supervise-directory state.
src/libs6/s6_servicedir_file_list.c - ftrig libs · Shared ftrigr/ftrigw client and waiter primitives.
src/libs6/ftrigr_start.c - fdholder libs · Shared async fdholder client logic and state exchange helpers.
src/libs6/s6_fdholder_start.c
Connections 22
- svscan → supervise: launches · Discovers services and starts per-service monitors.
- supervise → svc: accepts control · Control commands target a live supervise process.
- supervise → svstat: publishes state · Service status is exposed for readers.
- svwait → supervise: waits on · Waits for supervision state changes.
- svlisten → supervise: watches · Observes multiple supervised services.
- supervise → ftrig: signals · Uses trigger FIFOs for readiness and event notifications.
- mkfifodir → ftrig: prepares · Creates FIFO directories consumed by trigger tools.
- ftrig → svlisten: notifies · Delivers event notifications to waiters.
- fdholderd → fdholder clients: serves · Descriptor store is managed by client tools.
- fdholderd → ipcserver: uses IPC · Coordinates through Unix IPC and descriptor passing.
- ipcserver → accessrules: checks policy · Applies access rules before accepting connections.
- ipcclient → ipcserver: connects · Client/server path for stream or IPC services.
- logging wrap → supervise: wraps run · Pre-start setup and logging are composed around supervised programs.
- aliases → svc: maps to · Compatibility entry points forward to s6 commands.
- aliases → supervise: maps to · Compatibility entry points forward to supervision commands.
- instances → svscan: organizes · Instances are built on top of supervised service trees.
- instances → supervise: controls · Instance operations act on live supervised services.
- usertree → svscan: bootstraps · Creates per-user supervision layouts.
- service dir → supervise: supports · Shared service-directory and status helpers underpin supervision.
- ftrig libs → ftrig: supports · Shared trigger primitives back the FIFO tools.
- fdholder libs → fdholderd: supports · Shared fdholder protocol and async helpers back the daemon.
- service dir → instances: supports · Instance tools reuse service-directory helpers.