From 18e8d4817120446370389796ca896481401ac0b0 Mon Sep 17 00:00:00 2001 From: Benoit de Chezelles Date: Wed, 17 Feb 2021 13:56:59 +0100 Subject: [PATCH] unix: Correctly signal child process on exit --- pty/src/lib.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pty/src/lib.rs b/pty/src/lib.rs index cf33835b1..079d83c85 100644 --- a/pty/src/lib.rs +++ b/pty/src/lib.rs @@ -47,6 +47,7 @@ use anyhow::Error; #[cfg(feature = "serde_support")] use serde_derive::*; use std::io::Result as IoResult; +use libc; pub mod cmdbuilder; pub use cmdbuilder::CommandBuilder; @@ -115,7 +116,7 @@ pub trait MasterPty: std::io::Write { pub trait Child: std::fmt::Debug { /// Poll the child to see if it has completed. /// Does not block. - /// Returns None if the has not yet terminated, + /// Returns None if the child has not yet terminated, /// else returns its exit status. fn try_wait(&mut self) -> IoResult>; /// Terminate the child process @@ -187,6 +188,12 @@ impl Child for std::process::Child { } fn kill(&mut self) -> IoResult<()> { + #[cfg(unix)] + { + unsafe { libc::kill(self.id() as i32, libc::SIGHUP) }; + Ok(()) + } + #[cfg(windows)] std::process::Child::kill(self) }