Skip to content

Commit ad624c8

Browse files
committed
Merge #869
869: Change SigAction::flags to use from_bits_truncated r=asomers a=Detegr 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.
2 parents 2b9c67c + 4419205 commit ad624c8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/sys/signal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl SigAction {
389389
}
390390

391391
pub fn flags(&self) -> SaFlags {
392-
SaFlags::from_bits(self.sigaction.sa_flags).unwrap()
392+
SaFlags::from_bits_truncate(self.sigaction.sa_flags)
393393
}
394394

395395
pub fn mask(&self) -> SigSet {

test/sys/test_signal.rs

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ fn test_kill_none() {
66
kill(getpid(), None).expect("Should be able to send signal to myself.");
77
}
88

9+
#[test]
10+
fn test_old_sigaction_flags() {
11+
extern "C" fn handler(_: ::libc::c_int) {}
12+
let act = SigAction::new(
13+
SigHandler::Handler(handler),
14+
SaFlags::empty(),
15+
SigSet::empty(),
16+
);
17+
let oact = unsafe { sigaction(SIGINT, &act) }.unwrap();
18+
let _flags = oact.flags();
19+
let oact = unsafe { sigaction(SIGINT, &act) }.unwrap();
20+
let _flags = oact.flags();
21+
}
22+
923
#[test]
1024
fn test_sigprocmask_noop() {
1125
sigprocmask(SigmaskHow::SIG_BLOCK, None, None)

0 commit comments

Comments
 (0)