Enum SigHandler
pub enum SigHandler
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:
# use std::convert::TryFrom;
# use std::sync::atomic::{AtomicBool, Ordering};
# use nix::sys::signal::{self, Signal, SigHandler};
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
impl Clone for SigHandler
fn clone(&self) -> Self
impl Copy for SigHandler
impl Debug for SigHandler
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Hash for SigHandler
fn hash<__H: Hasher>(&self, state: &mut __H)