pub fn register_shutdown_handler()Expand description
Registers the global shutdown handler for every event the platform offers.
See the module docs for the exact per-platform event set; on Unix that is Ctrl+C / SIGTERM / SIGHUP, on Windows the five console control events.
First signal: sets SHUTDOWN flag, cancels the global
cancellation token and emits a best-effort notice on stderr.
Second signal: calls [std::process::exit(130)] for immediate termination
following Unix convention (128 + SIGINT=2) — with ZERO I/O on that path.
§G42/S8 — panic-free by contract
The pre-v1.0.79 handler used eprintln! (second signal) and
tracing::warn! (first signal). When the parent shell dies the CLI is
reparented to PID 1 and stderr becomes a CLOSED pipe; eprintln! then
panics with BrokenPipe, which under panic = "abort" becomes the
SIGABRT observed on the “ctrl-c” thread (G42/C2 crash report). This
handler therefore:
- writes the first-signal notice with
writeln!and IGNORES any I/O error (let _ =), never panicking; - performs NO I/O at all on the forced-exit path.
BrokenPipe on stdout/stderr elsewhere is handled by resetting SIGPIPE
to its default disposition in main on Unix, and by classifying the stdout
write error in main on Windows — both reach the same clean exit 141.