diff --git a/apps/desktop/src-tauri/Cargo.lock b/apps/desktop/src-tauri/Cargo.lock index 8475092..4fa47e0 100644 --- a/apps/desktop/src-tauri/Cargo.lock +++ b/apps/desktop/src-tauri/Cargo.lock @@ -4016,6 +4016,7 @@ dependencies = [ "getrandom 0.3.4", "hmac", "keyring", + "libc", "reqwest", "rusqlite", "rustls", diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index 8c2c274..8bbd304 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -57,3 +57,6 @@ lto = true opt-level = "s" panic = "abort" strip = true + +[target.'cfg(unix)'.dependencies] +libc = "0.2" diff --git a/apps/desktop/src-tauri/src/ai_fix.rs b/apps/desktop/src-tauri/src/ai_fix.rs index 72904b7..20ba93a 100644 --- a/apps/desktop/src-tauri/src/ai_fix.rs +++ b/apps/desktop/src-tauri/src/ai_fix.rs @@ -304,9 +304,17 @@ fn running() -> &'static Running { pub fn kill_tree(pid: u32) { #[cfg(unix)] { - let _ = Command::new("kill").args(["-TERM", &format!("-{pid}")]).status(); + // the agent runs in its own process group (pgid = its pid); never signal any other group, least of all ours + // (a CI run once died of SIGTERM in the middle of these tests) + let pgid = pid as libc::pid_t; + // SAFETY: getpgrp has no preconditions; killpg only sends a signal to the group named + let own = unsafe { libc::getpgrp() }; + if pgid <= 1 || pgid == own { + return; + } + unsafe { libc::killpg(pgid, libc::SIGTERM) }; std::thread::sleep(Duration::from_millis(300)); - let _ = Command::new("kill").args(["-KILL", &format!("-{pid}")]).status(); + unsafe { libc::killpg(pgid, libc::SIGKILL) }; } #[cfg(windows)] {