signal-mod 1.0.0

Cross-platform OS signal handling and graceful-shutdown orchestration for Rust. One API for SIGTERM, SIGINT, SIGHUP, SIGQUIT, SIGPIPE, SIGUSR1, SIGUSR2 and the Windows console control events, with cloneable observer and initiator handles, priority-ordered shutdown hooks, and optional adapters for the Tokio and async-std runtimes.
Documentation
//! Synchronous `ctrlc` back-end for
//! [`Coordinator::install`](crate::Coordinator::install).
//!
//! Selected when neither `tokio` nor `async-std` is enabled but
//! `ctrlc-fallback` is. The `ctrlc` crate registers a single
//! process-global handler for `SIGINT` / Ctrl+C; coverage is therefore
//! limited to [`Signal::Interrupt`]. Other variants in the configured
//! set are silently skipped.

use crate::coord::Coordinator;
use crate::error::{Error, Result};
use crate::reason::ShutdownReason;
use crate::signal::Signal;

/// Install a `ctrlc` handler for [`Signal::Interrupt`] if present in
/// the configured set.
pub(crate) fn install(coord: &Coordinator) -> Result<()> {
    let trigger = coord.trigger();
    if coord.signals().contains(Signal::Interrupt) {
        ctrlc::try_set_handler(move || {
            let _ = trigger.trigger(ShutdownReason::Signal(Signal::Interrupt));
        })
        .map_err(|e| Error::SignalRegistration {
            signal: Signal::Interrupt,
            source: std::io::Error::other(e),
        })?;
    }
    Ok(())
}