diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 9cf99ba4c4..f11b663331 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -464,6 +464,15 @@ impl AsRef for SigSet { } } +pub use self::signal::siginfo; + +pub enum SigHandler { + SigDfl, + SigIgn, + Handler(extern fn(SigNum)), + SigAction(extern fn(SigNum, *mut siginfo, *mut libc::c_void)) +} + type sigaction_t = self::signal::sigaction; pub struct SigAction { @@ -471,10 +480,20 @@ pub struct SigAction { } impl SigAction { - pub fn new(handler: extern fn(libc::c_int), flags: SockFlag, mask: SigSet) -> SigAction { + /// This function will set or unset the flag `SA_SIGINFO` depending on the + /// type of the `handler` argument. + pub fn new(handler: SigHandler, flags: SockFlag, mask: SigSet) -> SigAction { let mut s = unsafe { mem::uninitialized::() }; - s.sa_handler = handler; - s.sa_flags = flags; + s.sa_handler = match handler { + SigHandler::SigDfl => unsafe { mem::transmute(libc::SIG_DFL) }, + SigHandler::SigIgn => unsafe { mem::transmute(libc::SIG_IGN) }, + SigHandler::Handler(f) => f, + SigHandler::SigAction(f) => unsafe { mem::transmute(f) }, + }; + s.sa_flags = match handler { + SigHandler::SigAction(_) => flags | SA_SIGINFO, + _ => flags - SA_SIGINFO, + }; s.sa_mask = mask.sigset; SigAction { sigaction: s }