Expand description
Process-wide signal handling and scoped child-process registry.
See signal/mod.rs for the design rationale.
Process-wide signal handling and scoped child-process registry.
On SIGINT or SIGTERM (Unix) and the equivalent console-control events on
Windows, fallow’s default unwind drops std::process::Child handles
without killing the underlying children. The fallow-cov sidecar,
npm install -g, and self-invoked fallow health can run for minutes
and accumulate as orphan processes when the user hits Ctrl+C.
This module installs a single handler (see install_handlers) that on
signal delivery: kills every ScopedChild currently registered, drains
them with a bounded budget (500ms Unix, 1500ms Windows), and exits with
the conventional 128+signum exit code (130 for SIGINT, 143 for SIGTERM).
Watch mode opts into cooperative shutdown via set_graceful_mode: the
handler then only flips the shutdown flag and returns, letting the watch
loop exit cleanly with code 0 because Ctrl+C is its documented
termination path. Other commands keep the forceful 128+signum behavior.
See .plans/issue-477-signal-handlers.md for the design rationale and
crates/lsp/src/main.rs for the LSP-side cooperative cancellation.
Re-exports§
pub use scoped_child::ScopedChild;
Modules§
- registry
- Process-wide registry of live spawned-child PIDs.
- scoped_
child - RAII wrapper around
std::process::Childthat registers the child’s PID with the process-wide signal registry on spawn and deregisters on drop or explicit consume (wait_with_output,wait).
Structs§
- Graceful
Mode Guard - RAII guard that calls
set_graceful_modeon construction andclear_graceful_modeon drop. Used byrun_watchso any return path (success, panic-with-unwind in debug, early return on config error) restores forceful-exit behavior for the next command.
Functions§
- clear_
graceful_ mode - Leave cooperative shutdown mode. Subsequent signals revert to the
forceful behavior (kill registered children,
exit(128 + signum)). - install_
handlers - Install the signal handler. Idempotent; safe to call multiple times. Returns the original error from the underlying primitive on first call failure.
- is_
shutting_ down - True after a signal has been observed. Read by long-running loops
(currently
fallow watch) to break out cooperatively. - set_
graceful_ mode - Enter cooperative shutdown mode. Subsequent signals set
SHUTDOWNwithout killing children or callingexit(). The caller is responsible for pollingis_shutting_down()and exiting cleanly.