Expand description
Exit codes, signals and job control.
§The SIGPIPE regression
The Rust runtime sets SIGPIPE to SIG_IGN before main runs, because a
Rust program would rather see EPIPE from a write than die. That setting is
inherited across exec, so a child launched by prk run starts with
SIGPIPE ignored – which is not what it was written to expect.
Concretely, prk run -- yes | head -1 hangs forever: head exits, the
pipe closes, and yes never receives the signal that would stop it. Every
program in a pipeline that relies on SIGPIPE to know when to stop is
affected, which is most of them.
The fix is restore_default_dispositions, called from pre_exec
immediately before the image is replaced. Its regression test is
tests/unix_exec.rs::yes_piped_into_head_terminates_rather_than_hanging.
§The signal mask
Blocked signals are also inherited across exec, and a blocked signal is
not something the child can discover or undo before it matters. prk does
not block anything itself, but it may have been started by something that
did, so the mask is cleared rather than assumed empty.
Constants§
- SIGINT
SIGINT, the signal Ctrl-C sends.- SIGNAL_
EXIT_ BASE - The offset a shell adds to a signal number to form an exit status.
- SIGPIPE
SIGPIPE, which the Rust runtime ignores and which must be restored.- SIGTERM
SIGTERM, the defaultkillsignal.
Functions§
- child_
exit_ status - Maps a child’s outcome to the status
prkshould exit with. - exit_
status_ for_ signal - The exit status a shell reports for a process killed by a signal.
- restore_
default_ dispositions - Restores the signal state a freshly-started program expects.