Expand description
Child reaping + orphan discipline.
Two responsibilities:
- Subreaper / PID-1 discipline.
PR_SET_CHILD_SUBREAPERmakes grandchildren orphaned by a dying subagent reparent to us, not host init — so the whole tree stays in agentd’s reaping domain. When agentd is PID 1 (a bare container), the same applies natively. - Reaping. Each active
Supervisortick drains the process-global reaper (reaper::reap_and_dispatch), whosereap_pendinghere is the singlewaitpid(-1, WNOHANG)loop — looped because SIGCHLD does not queue, so one signal may cover several exits. The SIGCHLD self-pipe (signals.rs) is only a promptness hint; correctness does not depend on it.
The exit-status decode (classify_status) is pure and unit-tested; the
waitpid loop itself is a thin libc wrapper exercised by the reactor.
Structs§
- Reaped
- A reaped child: its pid and how it ended.
Enums§
- Wait
Outcome - How a child process ended.
Constants§
- INSTANCE_
CHILD_ ENV - Set in an instance-tier child’s environment by the spawning parent.
The child daemon sees it at startup and installs
install_instance_pdeathsigso a parent crash retires the child gracefully (SIGTERM → its own drain) instead of orphaning a daemon.
Functions§
- classify_
status - Decode a raw
waitpidstatus into aWaitOutcome. Pure — uses the libcWIF*macros so the encoding stays correct per platform. - install_
instance_ pdeathsig - PDEATHSIG(SIGTERM) for an instance-tier child — set post-exec by the child
itself (the pre-exec value would not survive the execve), mirroring the
subagent’s SIGKILL install in
subagent::control. SIGTERM, not SIGKILL: a daemon child has durable state worth a graceful drain. - is_init
- Are we PID 1 (running as a bare container’s init)? Then we must reap all orphans, and our own death takes the tree with us.
- set_
child_ subreaper - Become a subreaper so orphaned grandchildren reparent to us. Returns
true on success (Linux ≥ 3.4). Best-effort: a failure just means
orphans go to init, which
PDEATHSIGalready guards against.