-
Notifications
You must be signed in to change notification settings - Fork 674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change SigAction::flags to use from_bits_truncated #869
Conversation
Do you have an example testcase that demonstrates the failure? |
Sure. extern crate nix;
use nix::sys::signal;
extern "C" fn handler(_: nix::libc::c_int) {}
fn main() {
let act = signal::SigAction::new(
signal::SigHandler::Handler(handler),
signal::SaFlags::empty(),
signal::SigSet::empty(),
);
let oact = unsafe { signal::sigaction(signal::SIGINT, &act) }.unwrap();
println!("{:?}", oact.flags()); // Works, the default handler flags do not have SA_RESTORER set
let oact = unsafe { signal::sigaction(signal::SIGINT, &act) }.unwrap();
println!("{:?}", oact.flags()); // Panics, as sa_flags contains SA_RESTORER
} |
Yeah, that fails for me too, on Linux but not FreeBSD. Could you please add it to tests/sys/test_signal.rs? |
Added. |
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.
bors r+ |
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.
This needed a CHANGELOG entry indicating the fix as well. @Detegr Would you be willing to submit one? |
Sure. Is it okay to have the commit in this PR or should I open a new one? |
Since this was merged, you should open a new one. As all you're changing is the CHANGELOG, put "[skip ci]" at the start of the commit message. Thanks! |
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.