Skip to main content

register_shutdown_handler

Function register_shutdown_handler 

Source
pub fn register_shutdown_handler()
Expand description

Registers the global shutdown handler for Ctrl+C / SIGTERM / SIGHUP.

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 (clean exit 141, Unix convention).