Files
topgrade/src/ctrlc/unix.rs

18 lines
563 B
Rust
Raw Normal View History

2018-12-31 14:07:55 +02:00
//! SIGINT handling in Unix systems.
use crate::ctrlc::interrupted::set_interrupted;
2023-11-24 07:50:41 +08:00
use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal};
2018-12-31 14:07:55 +02:00
/// Handle SIGINT. Set the interruption flag.
extern "C" fn handle_sigint(_: i32) {
set_interrupted();
}
2018-12-31 14:07:55 +02:00
/// Set the necessary signal handlers.
/// The function panics on failure.
pub fn set_handler() {
2023-11-24 07:50:41 +08:00
let sig_action = SigAction::new(SigHandler::Handler(handle_sigint), SaFlags::empty(), SigSet::empty());
unsafe {
2023-11-24 07:50:41 +08:00
sigaction(Signal::SIGINT, &sig_action).unwrap();
}
}