diff --git a/Cargo.lock b/Cargo.lock index ef56dbce..79c6ed4e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3506,17 +3506,16 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.30.13" +version = "0.31.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a5b4ddaee55fb2bea2bf0e5000747e5f5c0de765e5a5ff87f4cd106439f4bb3" +checksum = "355dbe4f8799b304b05e1b0f05fc59b2a18d36645cf169607da45bde2f69a1be" dependencies = [ - "cfg-if", "core-foundation-sys", "libc", + "memchr", "ntapi", - "once_cell", "rayon", - "windows 0.52.0", + "windows 0.57.0", ] [[package]] @@ -4224,11 +4223,11 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.52.0" +version = "0.57.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" dependencies = [ - "windows-core 0.52.0", + "windows-core 0.57.0", "windows-targets 0.52.6", ] @@ -4251,19 +4250,42 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement 0.57.0", + "windows-interface 0.57.0", + "windows-result 0.1.2", + "windows-targets 0.52.6", +] + [[package]] name = "windows-core" version = "0.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" dependencies = [ - "windows-implement", - "windows-interface", - "windows-result", + "windows-implement 0.58.0", + "windows-interface 0.58.0", + "windows-result 0.2.0", "windows-strings", "windows-targets 0.52.6", ] +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.74", +] + [[package]] name = "windows-implement" version = "0.58.0" @@ -4275,6 +4297,17 @@ dependencies = [ "syn 2.0.74", ] +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.74", +] + [[package]] name = "windows-interface" version = "0.58.0" @@ -4292,11 +4325,20 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" dependencies = [ - "windows-result", + "windows-result 0.2.0", "windows-strings", "windows-targets 0.52.6", ] +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-result" version = "0.2.0" @@ -4312,7 +4354,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" dependencies = [ - "windows-result", + "windows-result 0.2.0", "windows-targets 0.52.6", ] diff --git a/service/Cargo.toml b/service/Cargo.toml index a18352fb..5d2a2119 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -28,7 +28,7 @@ env_logger = "0.11.5" clap = { version = "4.5.16", features = ["derive"] } hex = "0.4.3" mockall = "0.13.0" -sysinfo = "0.30.13" +sysinfo = "0.31.4" axum = "0.7.5" serde = { version = "1.0.209", features = ["derive"] } range-set = "0.0.11" diff --git a/service/src/main.rs b/service/src/main.rs index a74f48ba..937eab2b 100644 --- a/service/src/main.rs +++ b/service/src/main.rs @@ -3,7 +3,7 @@ use std::{fs::read_to_string, net::SocketAddr, path::PathBuf, sync::Arc, time::D use clap::{Args, Parser, ValueEnum}; use eyre::Context; use serde_with::{formats, hex::Hex, serde_as}; -use sysinfo::{Pid, ProcessStatus, System}; +use sysinfo::{Pid, ProcessRefreshKind, ProcessStatus, ProcessesToUpdate, System}; use tokio::net::TcpListener; use tokio::sync::oneshot::{self, error::TryRecvError, Receiver}; use tonic::transport::{Certificate, Identity}; @@ -312,14 +312,20 @@ fn watch_pid(pid: Pid, interval: Duration, mut term: Receiver<()>) { log::info!("watching PID {pid}"); let mut sys = System::new(); - while sys.refresh_process(pid) { - if let Some(p) = sys.process(pid) { - match p.status() { - ProcessStatus::Zombie | ProcessStatus::Dead => { - log::info!("PID {pid} died"); + loop { + sys.refresh_processes_specifics(ProcessesToUpdate::All, ProcessRefreshKind::new()); + match sys.process(pid) { + None => { + log::info!("PID {pid} not found"); + return; + } + Some(p) => { + let status = p.status(); + log::debug!("PID {pid} status: {status}"); + if matches!(p.status(), ProcessStatus::Zombie | ProcessStatus::Dead) { + log::info!("PID {pid} died (status: {status})"); return; } - _ => {} } } match term.try_recv() { @@ -355,8 +361,13 @@ mod tests { // Don't watch assert!(super::watch_pid_if_needed(None).await.is_none()); // Watch - let (_term_tx, term_rx) = oneshot::channel(); - super::watch_pid_if_needed(Some((Pid::from(0), term_rx))) + let mut proc = Command::new("sleep").arg("99999").spawn().unwrap(); + let (_, term_rx) = oneshot::channel(); + + // kill and wait + proc.kill().unwrap(); + proc.wait().unwrap(); + super::watch_pid_if_needed(Some((Pid::from_u32(proc.id()), term_rx))) .await .expect("should be some") .expect("should be OK");