Skip to content

Commit

Permalink
Remove usage of command-group on unix
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptibell committed Aug 9, 2024
1 parent 4bd5aa6 commit 4299ea0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"

Expand Down
24 changes: 16 additions & 8 deletions lib/system/runner.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -80,24 +82,30 @@ 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
}
// 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)
}
};
Expand Down

0 comments on commit 4299ea0

Please sign in to comment.