From 4299ea0f4486e3d0c318609a75ca3124bf42b314 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Fri, 9 Aug 2024 14:43:36 +0200 Subject: [PATCH] Remove usage of command-group on unix --- Cargo.toml | 2 +- lib/system/runner.rs | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b199c50..53bba7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,6 @@ zip = "2.1" async-once-cell = "0.5" async-signal = "0.2" -command-group = { version = "5.0", features = ["with-tokio"] } futures = "0.3" reqwest = { version = "0.12", default-features = false, features = [ "rustls-tls", @@ -91,6 +90,7 @@ tracing-subscriber = { optional = true, version = "0.3", features = [ ] } [target.'cfg(windows)'.dependencies] +command-group = { version = "5.0", features = ["with-tokio"] } winapi = { version = "0.3", features = ["processthreadsapi", "wincon"] } winreg = "0.52" diff --git a/lib/system/runner.rs b/lib/system/runner.rs index 2540df6..b80f129 100644 --- a/lib/system/runner.rs +++ b/lib/system/runner.rs @@ -1,8 +1,10 @@ use std::ffi::OsStr; use std::io::Result as IoResult; -use async_signal::{Signal, Signals}; +#[cfg(windows)] use command_group::AsyncCommandGroup; + +use async_signal::{Signal, Signals}; use futures::StreamExt; use tokio::{ process::Command, @@ -80,16 +82,22 @@ where The newer `process-wrap` crate claims to also support this behavior for inheriting process group but it doesn't seem to work as expected. */ - let mut child_handle = Command::new(command) - .args(args) - .group() - .kill_on_drop(true) - .spawn()?; + let mut command = Command::new(command); + let mut child = { + #[cfg(unix)] + { + command.args(args).kill_on_drop(true).spawn()? + } + #[cfg(windows)] + { + command.args(args).group().kill_on_drop(true).spawn()? + } + }; let code = tokio::select! { // If the spawned process exits cleanly, we'll return its exit code, // which may or may not exist. Interpret a non-existent code as 1. - command_result = child_handle.wait() => { + command_result = child.wait() => { let code = command_result.ok().and_then(|s| s.code()).unwrap_or(1); signal_aborter.abort(); code @@ -97,7 +105,7 @@ where // If the command was manually interrupted by a signal, we will // return a special exit code for the signal. More details above. task_result = signal_handle => { - child_handle.kill().await.ok(); + child.kill().await.ok(); task_result.unwrap_or(EXIT_CODE_GOT_SIGNAL) } };