diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 3ea3ce258f..db372f0cc0 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -911,6 +911,22 @@ pub unsafe fn sigaction_current(signal: Signal) -> Result { sigaction_inner(signal, None) } +/// Whether the specified signal currently has its default action. +/// +/// `signal` can be any signal except `SIGKILL` or `SIGSTOP`. +pub fn sigaction_is_default(signal: Signal) -> Result { + // SAFETY: fetching the current action is safe if the handler isn't called + unsafe { sigaction_current(signal) }.map(|sigaction| sigaction.handler() == SigHandler::SigDfl) +} + +/// Whether the specified signal is currently ignored. +/// +/// `signal` can be any signal except `SIGKILL` or `SIGSTOP`. +pub fn sigaction_is_ignore(signal: Signal) -> Result { + // SAFETY: fetching the current action is safe if the handler isn't called + unsafe { sigaction_current(signal) }.map(|sigaction| sigaction.handler() == SigHandler::SigIgn) +} + /// Signal management (see [signal(3p)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/signal.html)) /// /// Installs `handler` for the given `signal`, returning the previous signal diff --git a/test/sys/test_signal.rs b/test/sys/test_signal.rs index 2d72ab6da3..6b5694fc1e 100644 --- a/test/sys/test_signal.rs +++ b/test/sys/test_signal.rs @@ -55,6 +55,8 @@ fn test_current_sigaction() { unsafe { sigaction_current(SIGINT) }.unwrap().handler(), SigHandler::SigDfl ); + assert!(sigaction_is_default(SIGINT).unwrap()); + assert!(!sigaction_is_ignore(SIGINT).unwrap()); unsafe { sigaction( @@ -72,6 +74,8 @@ fn test_current_sigaction() { unsafe { sigaction_current(SIGINT) }.unwrap().handler(), SigHandler::SigIgn ); + assert!(!sigaction_is_default(SIGINT).unwrap()); + assert!(sigaction_is_ignore(SIGINT).unwrap()); // restore original unsafe { sigaction(SIGINT, &oact) }.unwrap();