Verified Commit 1ee9229c authored by jD91mZM2's avatar jD91mZM2

fixup! Fix sigaction Undefind Behavior

parent 35b30e6f
......@@ -417,15 +417,16 @@ fn sigaction() {
sync::atomic::{AtomicBool, Ordering}
};
let child = unsafe { dbg!(crate::clone(0)).unwrap() };
static SA_HANDLER_WAS_RAN: AtomicBool = AtomicBool::new(false);
static SA_HANDLER_2_WAS_IGNORED: AtomicBool = AtomicBool::new(false);
if child == 0 {
static SA_HANDLER_WAS_RAN: AtomicBool = AtomicBool::new(false);
let child = unsafe { crate::clone(crate::CLONE_VM).unwrap() };
let pid = dbg!(crate::getpid()).unwrap();
if child == 0 {
let pid = crate::getpid().unwrap();
extern "C" fn hello_im_a_signal_handler(signal: usize) {
assert_eq!(dbg!(signal), crate::SIGUSR1);
assert_eq!(signal, crate::SIGUSR1);
SA_HANDLER_WAS_RAN.store(true, Ordering::SeqCst);
}
......@@ -433,38 +434,43 @@ fn sigaction() {
sa_handler: Some(hello_im_a_signal_handler),
..Default::default()
};
dbg!(crate::sigaction(crate::SIGUSR1, Some(&my_signal_handler), None)).unwrap();
crate::sigaction(crate::SIGUSR1, Some(&my_signal_handler), None).unwrap();
dbg!(crate::kill(pid, crate::SIGUSR1)).unwrap(); // calls handler
crate::kill(pid, crate::SIGUSR1).unwrap(); // calls handler
let mut old_signal_handler = crate::SigAction::default();
dbg!(crate::sigaction(
crate::sigaction(
crate::SIGUSR1,
Some(&crate::SigAction {
sa_handler: unsafe { mem::transmute::<usize, Option<extern "C" fn(usize)>>(crate::SIG_IGN) },
..Default::default()
}),
Some(&mut old_signal_handler)
)).unwrap();
).unwrap();
assert_eq!(my_signal_handler, old_signal_handler);
dbg!(crate::kill(pid, crate::SIGUSR1)).unwrap(); // does nothing
crate::kill(pid, crate::SIGUSR1).unwrap(); // does nothing
dbg!(crate::sigaction(
SA_HANDLER_2_WAS_IGNORED.store(true, Ordering::SeqCst);
crate::sigaction(
crate::SIGUSR1,
Some(&crate::SigAction {
sa_handler: unsafe { mem::transmute::<usize, Option<extern "C" fn(usize)>>(crate::SIG_DFL) },
..Default::default()
}),
Some(&mut old_signal_handler)
)).unwrap();
).unwrap();
dbg!(crate::kill(pid, crate::SIGUSR1)).unwrap(); // actually exits
crate::kill(pid, crate::SIGUSR1).unwrap(); // actually exits
} else {
let mut status = 0;
dbg!(crate::waitpid(child, &mut status, 0)).unwrap();
assert!(crate::wifsignaled(status));
assert_eq!(crate::wtermsig(status), crate::SIGUSR1);
assert!(SA_HANDLER_WAS_RAN.load(Ordering::SeqCst));
assert!(SA_HANDLER_2_WAS_IGNORED.load(Ordering::SeqCst));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment