Skip to content

Commit

Permalink
Call waitpid to reap defunct terminal processes (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzhang authored Nov 15, 2023
1 parent 3d0395b commit 0782485
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions crates/sshx/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use nix::errno::Errno;
use nix::libc::{login_tty, TIOCGWINSZ, TIOCSWINSZ};
use nix::pty::{self, Winsize};
use nix::sys::signal::{kill, Signal::SIGKILL};
use nix::sys::wait::waitpid;
use nix::unistd::{execvp, fork, ForkResult, Pid};
use pin_project::{pin_project, pinned_drop};
use tokio::fs::File;
Expand Down Expand Up @@ -146,10 +147,16 @@ impl AsyncWrite for Terminal {
impl PinnedDrop for Terminal {
fn drop(self: Pin<&mut Self>) {
let this = self.project();
trace!(child = %this.child, "dropping terminal");
let child = *this.child;
trace!(%child, "dropping terminal");

// Reap the child process on closure so that it doesn't keep running.
kill(*this.child, SIGKILL).ok();
// Kill the child process on closure so that it doesn't keep running.
kill(child, SIGKILL).ok();

// Reap the zombie process in a background thread.
std::thread::spawn(move || {
waitpid(child, None).ok();
});
}
}

Expand Down

0 comments on commit 0782485

Please sign in to comment.