From 301c60c177debab2e7ed8ceadf78cd981861dfac Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Sat, 30 Dec 2023 17:54:34 +0800 Subject: [PATCH] Release `v0.1.3` --- Cargo.lock | 14 +------------- Cargo.toml | 3 +-- src/main.rs | 22 +++++++++++++++------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f623620..6c8bf1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,12 +73,11 @@ checksum = "c9d19de80eff169429ac1e9f48fffb163916b448a44e8e046186232046d9e1f9" [[package]] name = "atomicalsir" -version = "0.1.2" +version = "0.1.3" dependencies = [ "anyhow", "clap", "color-eyre", - "nix", "reqwest", "serde", "serde_json", @@ -597,17 +596,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "nix" -version = "0.27.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" -dependencies = [ - "bitflags 2.4.1", - "cfg-if", - "libc", -] - [[package]] name = "nu-ansi-term" version = "0.46.0" diff --git a/Cargo.toml b/Cargo.toml index f019db8..27f525d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "GPL-3.0" name = "atomicalsir" readme = "README.md" repository = "https://github.com/hack-ink/atomicalsir" -version = "0.1.2" +version = "0.1.3" [profile.ci-dev] incremental = false @@ -27,7 +27,6 @@ vergen = { version = "8.2", features = ["build", "cargo", "git", "gitcl"] } anyhow = { version = "1.0" } clap = { version = "4.4", features = ["color", "derive"] } color-eyre = { version = "0.6" } -nix = { version = "0.27", features = ["signal"] } reqwest = { version = "0.11", features = ["json"] } serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0" } diff --git a/src/main.rs b/src/main.rs index df85eec..48d230f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,10 +20,6 @@ use clap::{ }, Parser, ValueEnum, }; -use nix::{ - sys::signal::{self, Signal}, - unistd::Pid, -}; use serde::Deserialize; #[tokio::main] @@ -284,7 +280,7 @@ fn execute( } let mut child = cmd.spawn()?; - let id = child.id(); + let pid = child.id(); let should_terminate = Arc::new(AtomicBool::new(false)); let stdout_st = should_terminate.clone(); let stdout_r = BufReader::new(child.stdout.take().unwrap()); @@ -312,7 +308,7 @@ fn execute( _ => (), } - signal::kill(Pid::from_raw(id as i32), Signal::SIGKILL)?; + kill(pid)?; break; } @@ -336,7 +332,8 @@ fn execute( if l.contains("worker stopped with exit code 1") { tracing::warn!("worker stopped with exit code 1; killing process"); - signal::kill(Pid::from_raw(id as i32), Signal::SIGKILL)?; + + kill(pid)?; break; } @@ -355,3 +352,14 @@ fn execute( Ok(()) } + +fn kill(pid: u32) -> Result<()> { + let pid = pid.to_string(); + + #[cfg(any(target_os = "linux", target_os = "macos"))] + Command::new("kill").args(["-9", &pid]).output()?; + #[cfg(target_os = "windows")] + Command::new("taskkill").args(["/F", "/PID", &pid]).output()?; + + Ok(()) +}