use core::mem::MaybeUninit;
use core::ptr::null;
use rustix::io;
pub type Sigaction = libc::sigaction;
pub use rustix::runtime::Signal;
pub use libc::sighandler_t as Sighandler;
pub use libc::siginfo_t as Siginfo;
bitflags::bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Default)]
pub struct SigactionFlags: libc::c_int {
const NOCLDSTOP = libc::SA_NOCLDSTOP as _;
const NOCLDWAIT = libc::SA_NOCLDWAIT as _;
const NODEFER = libc::SA_NODEFER as _;
const ONSTACK = libc::SA_ONSTACK as _;
const RESETHAND = libc::SA_RESETHAND as _;
const RESTART = libc::SA_RESTART as _;
const SIGINFO = libc::SA_SIGINFO as _;
const _ = !0;
}
}
pub unsafe fn sigaction(sig: Signal, action: Option<Sigaction>) -> io::Result<Sigaction> {
unsafe {
let action: *const Sigaction = match action {
Some(action) => &action,
None => null(),
};
let mut old = MaybeUninit::<Sigaction>::uninit();
if libc::sigaction(sig.as_raw(), action, old.as_mut_ptr()) == 0 {
Ok(old.assume_init())
} else {
Err(rustix::io::Errno::from_raw_os_error(errno::errno().0))
}
}
}
#[doc(alias = "SIG_IGN")]
#[must_use]
pub const fn sig_ign() -> Sighandler {
libc::SIG_IGN
}
pub use libc::SIG_DFL;
pub const SIGSTKSZ: usize = libc::SIGSTKSZ;
pub const SS_DISABLE: i32 = libc::SS_DISABLE;