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