use std::sync::atomic::{AtomicI32, Ordering};
static ARRIVED: AtomicI32 = AtomicI32::new(0);
#[cfg(unix)]
extern "C" fn record(signal: libc::c_int) {
ARRIVED.store(signal, Ordering::Relaxed);
}
#[cfg(unix)]
pub fn defer() {
let handler = record as *const () as libc::sighandler_t;
for signal in [libc::SIGINT, libc::SIGTERM, libc::SIGHUP] {
unsafe {
if libc::signal(signal, handler) == libc::SIG_IGN {
libc::signal(signal, libc::SIG_IGN);
}
}
}
}
#[cfg(not(unix))]
pub fn defer() {}
pub fn requested() -> bool {
ARRIVED.load(Ordering::Relaxed) != 0
}
#[cfg(unix)]
pub fn honour() {
let signal = ARRIVED.load(Ordering::Relaxed);
if signal == 0 {
return;
}
unsafe {
libc::signal(signal, libc::SIG_DFL);
libc::raise(signal);
}
}
#[cfg(not(unix))]
pub fn honour() {}