Skip to main content

Module signal

Module signal 

Source
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::Child that 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§

GracefulModeGuard
RAII guard that calls set_graceful_mode on construction and clear_graceful_mode on drop. Used by run_watch so 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 SHUTDOWN without killing children or calling exit(). The caller is responsible for polling is_shutting_down() and exiting cleanly.