Skip to content

Commit

Permalink
Change SigAction::flags to use from_bits_truncated
Browse files Browse the repository at this point in the history
On Linux, if the signal trampoline code is in the C library, sigaction
sets the SA_RESTORER flag (0x04000000) in the sa_flags field of old
sigaction (see sigreturn(2)).

This is not intended for application use and is missing from SaFlags,
therefore from_bits fails and unwrapping panics the user program.

This fix just drops the bits that are not defined in SaFlags.
  • Loading branch information
Detegr committed Mar 2, 2018
1 parent 2b9c67c commit 4419205
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl SigAction {
}

pub fn flags(&self) -> SaFlags {
SaFlags::from_bits(self.sigaction.sa_flags).unwrap()
SaFlags::from_bits_truncate(self.sigaction.sa_flags)
}

pub fn mask(&self) -> SigSet {
Expand Down
14 changes: 14 additions & 0 deletions test/sys/test_signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ fn test_kill_none() {
kill(getpid(), None).expect("Should be able to send signal to myself.");
}

#[test]
fn test_old_sigaction_flags() {
extern "C" fn handler(_: ::libc::c_int) {}
let act = SigAction::new(
SigHandler::Handler(handler),
SaFlags::empty(),
SigSet::empty(),
);
let oact = unsafe { sigaction(SIGINT, &act) }.unwrap();
let _flags = oact.flags();
let oact = unsafe { sigaction(SIGINT, &act) }.unwrap();
let _flags = oact.flags();
}

#[test]
fn test_sigprocmask_noop() {
sigprocmask(SigmaskHow::SIG_BLOCK, None, None)
Expand Down

0 comments on commit 4419205

Please sign in to comment.