Expand description
Child reaping + orphan discipline. RFC 0003 §pid1-orphan.
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.
Functions§
- classify_
status - Decode a raw
waitpidstatus into aWaitOutcome. Pure — uses the libcWIF*macros so the encoding stays correct per platform. - 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.