Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
97: Prevent file descriptor leak in the spawned child. r=matthiasbeyer a=kosayoda ## Problem After [forking the child process](https://github.com/rust-cli/rexpect/blob/cee87fc7a2ef743f09e1e880c8cf7b268a59b351/src/process.rs#L98), the file descriptors for the master and slave aren't closed since we created these descriptors ourselves (Rust sets CLOEXEC on any fds created in the stdlib). I stumbled upon the problem when my child became a orphan after sending SIGINT to its parent. Since the drop handlers weren't run, the child isn't terminated/waited on. The expected scenario (what pexpect does) is that the master side of the pty is closed by the kernel on process exit, and SIGHUP is sent to the child process (which kills the child by default). However, since the controlling terminal is left open by the child, SIGHUP is not sent. ## Reproduction and Fix ```rust use rexpect::spawn; fn main() { let mut p = spawn("sleep 100", Some(30_000)).unwrap(); // Hang parent let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); } ``` On the current master: <img width="375" alt="image" src="https://user-images.githubusercontent.com/41782385/229242068-01c6b68e-30b4-4c3b-a99d-62ed513fd9e9.png"> On the PR branch: <img width="372" alt="image" src="https://user-images.githubusercontent.com/41782385/229242179-98e6085e-a671-42d2-93fc-9075a2ba72b4.png"> Co-authored-by: kosayoda <[email protected]>
- Loading branch information