Skip to content

Commit

Permalink
stop asserting that child.kill() fails after wait
Browse files Browse the repository at this point in the history
I've confirmed that this test still fails if we reap the child using
waitpid():

    diff --git a/src/lib.rs b/src/lib.rs
    index ca08e94..2b1479d 100644
    --- a/src/lib.rs
    +++ b/src/lib.rs
    @@ -171,7 +171,12 @@ impl SharedChild {
             // and signal the state condvar.
             let mut state = self.state_lock.lock().unwrap();
             // The child has already exited, so this wait should clean up without blocking.
    -        let final_result = noreap_result.and_then(|_| self.child.lock().unwrap().wait());
    +        let final_result = noreap_result.and_then(|_| unsafe {
    +            let mut status = 0;
    +            let pid = self.child.lock().unwrap().id() as libc::pid_t;
    +            libc::waitpid(pid, &mut status, 0);
    +            Ok(std::os::unix::process::ExitStatusExt::from_raw(status))
    +        });
             *state = if let Ok(exit_status) = final_result {
                 Exited(exit_status)
             } else {

Fails with:

    ---- tests::test_into_inner_after_wait stdout ----
    thread 'tests::test_into_inner_after_wait' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 10, kind: Uncategorized, message: "No child processes" }', src/lib.rs:410:22
  • Loading branch information
oconnor663 committed Sep 26, 2023
1 parent ed1c4f6 commit 8001062
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,8 @@ mod tests {
shared_child.kill().unwrap();
shared_child.wait().unwrap();
let mut child = shared_child.into_inner();
// The child has already been waited on, so kill should be an error.
let kill_err = child.kill().unwrap_err();
if cfg!(windows) {
assert_eq!(std::io::ErrorKind::PermissionDenied, kill_err.kind());
} else {
assert_eq!(std::io::ErrorKind::InvalidInput, kill_err.kind());
}
// But wait should succeed.
// Wait should succeed. (Note that we also used to test that
// child.kill() failed here, but its behavior changed in Rust 1.72.)
child.wait().unwrap();
}

Expand Down

0 comments on commit 8001062

Please sign in to comment.