Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call waitpid to reap defunct terminal processes #51

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading