diff --git a/lib/src/process.rs b/lib/src/process.rs index ddb7f4a..18ac55f 100644 --- a/lib/src/process.rs +++ b/lib/src/process.rs @@ -2,12 +2,12 @@ use crate::error::Result; use crate::pathop::PathOp; +use command_group::{CommandGroup, GroupChild}; use std::{ collections::{HashMap, HashSet}, path::PathBuf, process::Command, }; -use command_group::{CommandGroup, GroupChild}; /// Shell to use to run commands. /// @@ -134,7 +134,7 @@ pub fn spawn( collect_path_env_vars(updated_paths) }; - for &(ref name, ref val) in &command_envs { + for (name, val) in &command_envs { command.env(name, val); } diff --git a/lib/src/run.rs b/lib/src/run.rs index 70251a6..b0da994 100644 --- a/lib/src/run.rs +++ b/lib/src/run.rs @@ -164,14 +164,18 @@ impl ExecHandler { Signal::SIGCHLD => { debug!("Try-waiting on command"); child.try_wait().ok(); - }, + } _ => { #[cfg(unix)] - child.signal(sig).unwrap_or_else(|err| warn!("Could not pass on signal to command: {}", err)); + child.signal(sig).unwrap_or_else(|err| { + warn!("Could not pass on signal to command: {}", err) + }); #[cfg(not(unix))] - child.kill().unwrap_or_else(|err| warn!("Could not pass on termination to command: {}", err)); - }, + child.kill().unwrap_or_else(|err| { + warn!("Could not pass on termination to command: {}", err) + }); + } } } } @@ -189,8 +193,13 @@ impl ExecHandler { clearscreen::clear()?; } - debug!("Launching command"); let mut guard = self.child_process.lock()?; + if let Some(child) = guard.as_mut() { + debug!("Killing process group id={}", child.id()); + child.kill()?; + } + + debug!("Launching command"); *guard = Some(process::spawn( &self.args.cmd, ops, @@ -346,12 +355,14 @@ fn signal_process(process: &Mutex>, signal: Signal) -> Result let mut guard = process.lock().expect("poisoned lock in signal_process"); if let Some(child) = guard.as_mut() { - #[cfg(unix)] { + #[cfg(unix)] + { debug!("Signaling process with {}", signal); child.signal(signal)?; } - #[cfg(not(unix))] { + #[cfg(not(unix))] + { if matches!(signal, Signal::SIGTERM | Signal::SIGKILL) { debug!("Killing process"); child.kill()?;