pub fn restore_sigpipe_default()Expand description
Restore SIGPIPE to its default action (terminate the process)
so piping a ktstr binary’s output to a reader that closes
early (e.g. ... | head) does not panic inside print! /
println!. Rust’s startup code sets SIGPIPE to SIG_IGN,
which turns the broken-pipe write into an io::Error that
print! escalates to a panic. Setting SIG_DFL restores the
POSIX “process terminates on SIGPIPE” convention that Unix
CLI tools rely on.
Call this at the TOP of each of the three user-facing CLIs’
main — ktstr, cargo-ktstr, and ktstr-jemalloc-probe —
before the tracing subscriber installs its stderr handler and
before any stdout write. Shared across src/bin/ktstr.rs,
src/bin/cargo-ktstr.rs, and src/bin/jemalloc_probe.rs so
the three CLIs behave identically under | pipelines and a
future reword of the SAFETY rationale lands in one place. The
ktstr-jemalloc-alloc-worker binary does NOT call this — it
is a test-fixture target spawned by the probe’s closed-loop
integration tests, never piped by a human operator, and its
stdout emission path prints a single “ready” breadcrumb that
the test body ignores, so SIGPIPE restoration there would
add noise without benefit.
No return value; the call is effectively infallible (libc’s
signal(2) can’t fail for a standard signal + SIG_DFL
handler on a live process).
§Safety (FFI)
libc::signal is an FFI call with no memory effects (no
pointer dereferences, no mutation of Rust state). SIG_DFL
is a well-known constant handler. Call must run before any
stdout writes so the handler is in place by the time
print! fires.