Skip to main content

Module reap

Module reap 

Source
Expand description

Child reaping + orphan discipline.

Two responsibilities:

  1. Subreaper / PID-1 discipline. PR_SET_CHILD_SUBREAPER makes 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.
  2. Reaping. Each active Supervisor tick drains the process-global reaper (reaper::reap_and_dispatch), whose reap_pending here is the single waitpid(-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§

WaitOutcome
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_pdeathsig so a parent crash retires the child gracefully (SIGTERM → its own drain) instead of orphaning a daemon.

Functions§

classify_status
Decode a raw waitpid status into a WaitOutcome. Pure — uses the libc WIF* 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 PDEATHSIG already guards against.