devela::_dep::nc

Function rt_sigaction

pub unsafe fn rt_sigaction(
    sig: i32,
    act: Option<&sigaction_t>,
    old_act: Option<&mut sigaction_t>,
) -> Result<(), i32> 
Available on crate feature dep_nc only.
Expand description

Examine and change a signal action.

§Examples

fn handle_sigterm(sig: i32) {
    assert_eq!(sig, nc::SIGTERM);
}

#[cfg(nc_has_sa_restorer)]
let sa = nc::sigaction_t {
    sa_handler: handle_sigterm as nc::sighandler_t,
    sa_flags: nc::SA_RESTORER | nc::SA_RESTART,
    sa_restorer: nc::restore::get_sa_restorer(),
    ..nc::sigaction_t::default()
};
#[cfg(not(nc_has_sa_restorer))]
let sa = nc::sigaction_t {
    sa_handler: handle_sigterm as nc::sighandler_t,
    sa_flags: nc::SA_RESTART,
    ..nc::sigaction_t::default()
};
let ret = unsafe { nc::rt_sigaction(nc::SIGTERM, Some(&sa), None) };
let ret = unsafe { nc::kill(nc::getpid(), nc::SIGTERM) };
assert!(ret.is_ok());