Skip to content

Commit 645e37d

Browse files
committed
Handle SA_SIGINFO flag in the constructor.
If someone creates so many SigAction structs, that a few extra instructions per object creation create a performance problem, we could still provide an unsafe variant, that let's the user take care of the flag.
1 parent 9938df6 commit 645e37d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/sys/signal.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ pub struct SigAction {
394394
}
395395

396396
impl SigAction {
397+
/// This function will set or unset the flag `SA_SIGINFO` depending on the
398+
/// type of the `handler` argument.
397399
pub fn new(handler: SigHandler, flags: SockFlag, mask: SigSet) -> SigAction {
398400
let mut s = unsafe { mem::uninitialized::<sigaction_t>() };
399401
s.sa_handler = match handler {
@@ -402,7 +404,10 @@ impl SigAction {
402404
SigHandler::Handler(f) => f,
403405
SigHandler::SigAction(f) => unsafe { mem::transmute(f) },
404406
};
405-
s.sa_flags = flags;
407+
s.sa_flags = match handler {
408+
SigHandler::SigAction(_) => flags | SA_SIGINFO,
409+
_ => flags - SA_SIGINFO,
410+
};
406411
s.sa_mask = mask.sigset;
407412

408413
SigAction { sigaction: s }

0 commit comments

Comments
 (0)