From 7e50127db8e6866ff925be1395631953ce3230de Mon Sep 17 00:00:00 2001 From: "Scott C. Livingston" Date: Thu, 2 Jan 2025 16:49:22 -0800 Subject: [PATCH] rework camera process kill code --- src/api.rs | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/api.rs b/src/api.rs index 7632d64..15277c6 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1209,18 +1209,39 @@ impl HSAPIClient { if entry.extension().unwrap() == "pid" { let file_stem = entry.file_stem().unwrap(); stopped_via_pids.push(file_stem.to_string_lossy().to_string()); - let pid: i32 = String::from_utf8(std::fs::read(&entry).unwrap()) + let pid = String::from_utf8(std::fs::read(&entry).unwrap()) .unwrap() .trim() - .parse()?; - if let Err(err) = signal::kill(unistd::Pid::from_raw(pid), signal::SIGTERM) { - warn!( - "failed to terminate local process {} for camera {}: {}", - pid, - stopped_via_pids.last().unwrap(), - err - ); + .to_string(); + + #[cfg(target_os = "windows")] + let kresult = process::Command::new("taskkill") + .args(["/pid", &pid]) + .status(); + #[cfg(any(target_os = "linux", target_os = "macos"))] + let kresult = process::Command::new("kill").arg(&pid).status(); + + match kresult { + Ok(r) => { + if !r.success() { + return error(format!( + "failed to terminate local process {} for camera {}: {}", + pid, + stopped_via_pids.last().unwrap(), + r + )); + } + } + Err(err) => { + return error(format!( + "failed to terminate local process {} for camera {}: {}", + pid, + stopped_via_pids.last().unwrap(), + err + )); + } } + std::fs::remove_file(entry)?; } }