Skip to content

Commit

Permalink
test_fork: fix race condition under Linux (#3283)
Browse files Browse the repository at this point in the history
Fixes #3275
  • Loading branch information
sporksmith committed Jan 17, 2024
1 parent ff71660 commit 8804ed3
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/test/clone/test_fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ fn test_exit_signal_normal_exit(exit_signal: nix::sys::signal::Signal) -> anyhow
.unwrap();
let child_pid = match clone_res {
CloneResult::CallerIsChild => {
// Give parent time to get into its sleep.
match rustix::thread::nanosleep(&rustix::fs::Timespec {
tv_sec: 1,
tv_nsec: 0,
}) {
rustix::thread::NanosleepRelativeResult::Ok => (),
other => panic!("Unexpected nanosleep result: {other:?}"),
}
// Exit, causing the exit signal to be sent.
unsafe { libc::exit(CHILD_EXIT_STATUS) };
}
CloneResult::CallerIsParent(child_pid) => child_pid,
Expand Down Expand Up @@ -371,6 +380,15 @@ fn test_exit_signal_with_fatal_signal(exit_signal: nix::sys::signal::Signal) ->
.unwrap();
let child_pid = match clone_res {
CloneResult::CallerIsChild => {
// Give parent time to get into its sleep.
match rustix::thread::nanosleep(&rustix::fs::Timespec {
tv_sec: 1,
tv_nsec: 0,
}) {
rustix::thread::NanosleepRelativeResult::Ok => (),
other => panic!("Unexpected nanosleep result: {other:?}"),
}
// Exit, causing the exit signal to be sent.
unsafe { libc::kill(libc::getpid(), libc::SIGKILL) };
unreachable!()
}
Expand Down

0 comments on commit 8804ed3

Please sign in to comment.