blob: c11f0781083204648e4c9839047352e82a1afc91 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
use std::sync::atomic::{AtomicBool, Ordering};
/// Set by the first Ctrl-C. Cleared between turns.
pub static CANCEL: AtomicBool = AtomicBool::new(false);
extern "C" fn handler(_: libc::c_int) {
// First Ctrl-C aborts the turn. A second one is taken to mean "I really mean
// it" and leaves immediately; `_exit` is async-signal-safe, `exit` is not.
if CANCEL.swap(true, Ordering::SeqCst) {
unsafe { libc::_exit(130) }
}
}
pub fn install() {
let handler: extern "C" fn(libc::c_int) = handler;
unsafe {
libc::signal(libc::SIGINT, handler as libc::sighandler_t);
}
}
|