[][src]Function signal_hook::cleanup::cleanup_signal

pub fn cleanup_signal(signal: c_int) -> Result<(), Error>

Resets the signal handler to the default one and removes all its hooks.

This resets the signal to the OS default. It doesn't revert to calling any previous signal handlers (the ones not handled by signal-hook). All the hooks registered for this signal are removed.

The intended use case is making sure further instances of a terminal signal have immediate effect. If eg. a CTRL+C is pressed, the application removes all signal handling and proceeds to its own shutdown phase. If the shutdown phase takes too long or gets stuck, the user may press CTRL+C again which will then kill the application immediately, by a default signal action.

Warning

This action is global (affecting hooks some other library or unrelated part of program registered) and irreversible. Once called, registering new hooks for this signal has no further effect (they'll appear to be registered, but they won't be called by the signal). The latter may change in the future and it won't be considered a breaking change.

In other words, this is expected to be called only once the application enters its terminal state and is not supported otherwise.

The function is not async-signal-safe. See register and cleanup_raw if you intend to reset the signal directly from inside the signal handler itself.

Examples

use signal_hook::{cleanup, flag, SIGTERM};

fn main() -> Result<(), Error> {
    let terminated = Arc::new(AtomicBool::new(false));
    flag::register(SIGTERM, Arc::clone(&terminated))?;

    while !terminated.load(Ordering::Relaxed) {
        keep_processing();
    }

    cleanup::cleanup_signal(SIGTERM)?;
    app_cleanup();
    Ok(())
}