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)
Auto Trait Implementations
impl Freeze for SigHandler
impl RefUnwindSafe for SigHandler
impl Send for SigHandler
impl Sync for SigHandler
impl Unpin for SigHandler
impl UnsafeUnpin for SigHandler
impl UnwindSafe for SigHandler
Blanket Implementations
impl<T> Any for SigHandler
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for SigHandler
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for SigHandler
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for SigHandler
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for SigHandler
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for SigHandler
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for SigHandler
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for SigHandler
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for SigHandler
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>