Skip to content

Commit

Permalink
Reuse existing fork wrapper in fork_for_test
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Oct 15, 2024
1 parent 62bda20 commit 8643990
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,17 @@ pub(crate) unsafe fn fork() -> io::Result<ForkResult> {
/// child process until a call to `execve` or a similar function is done.
#[cfg(test)]
unsafe fn fork_for_test() -> ForkResult {
let pid = cerr(unsafe { libc::fork() }).unwrap();
if pid == 0 {
let result = fork().unwrap();
if let ForkResult::Child = result {
// Make sure that panics in the child always abort the process if it doesn't deadlock.
// FIXME use std::panic::always_abort() once it is stable
std::panic::set_hook(Box::new(|info| {
use std::io::Write;
let _ = writeln!(std::io::stderr(), "{info}");
std::process::exit(101);
}));
ForkResult::Child
} else {
ForkResult::Parent(pid)
}
result
}

pub fn setsid() -> io::Result<ProcessId> {
Expand Down

0 comments on commit 8643990

Please sign in to comment.