pub enum SigHandler {
SigDfl,
SigIgn,
Handler(extern "C" fn(c_int)),
SigAction(extern "C" fn(c_int, *mut siginfo_t, *mut c_void)),
}Expand description
A signal handler used with sigaction or signal.
Signal handlers have very limited functionality. A signal handler must only call async-signal-safe functions. A list of async-signal-safe functions can be found in signal-safety(7).
In particular, signal handlers should only set a flag using an atomic type
(such as std::sync::atomic::AtomicBool) and do nothing else. Any more
complex logic should be performed outside the signal handler.
§Examples
Catch SIGINT and record it with an atomic flag:
static SIGNALED: AtomicBool = AtomicBool::new(false);
extern "C" fn handle_sigint(signal: libc::c_int) {
let signal = Signal::try_from(signal).unwrap();
SIGNALED.store(signal == Signal::SIGINT, Ordering::Relaxed);
}
fn main() {
let handler = SigHandler::Handler(handle_sigint);
unsafe { signal::signal(Signal::SIGINT, handler) }.unwrap();
}Variants§
SigDfl
Default signal handling.
SigIgn
Request that the signal be ignored.
Handler(extern "C" fn(c_int))
Use the given signal-catching function, which takes in the signal.
SigAction(extern "C" fn(c_int, *mut siginfo_t, *mut c_void))
Use the given signal-catching function, which takes in the signal, information about how
the signal was generated, and a pointer to the threads ucontext_t.
Trait Implementations§
Source§impl Clone for SigHandler
impl Clone for SigHandler
Source§fn clone(&self) -> SigHandler
fn clone(&self) -> SigHandler
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more