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

Remove usage of command-group on unix #64

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
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
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