Skip to content

Commit

Permalink
Fix sysinfo windows issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thorio committed Jan 5, 2025
1 parent 88057a7 commit bbb3439
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 7 deletions.
69 changes: 67 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ shellexpand = "3.1.0"
single-instance = "0.3.3"
stderrlog = { version = "0.6.0", default-features = false }
syn = "2.0.68"
sysinfo = { version = "0.33.1", default-features = false }
sysinfo = { version = "0.33.1", default-features = false, features = ["system"] }
system_shutdown = "4.0.1"
thiserror = "2.0.9"
urlencoding = "2.1.3"
Expand Down
10 changes: 6 additions & 4 deletions gravel-provider-kill/src/windows.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use anyhow::Result;
use gravel_ffi::SimpleHit;
use std::ffi::OsStr;
use std::thread::sleep;
use std::time::Duration;
use sysinfo::{Process, System};
use sysinfo::{Process, ProcessesToUpdate, System};
use thiserror::Error;
use winapi::shared::minwindef::DWORD;
use winapi::um::errhandlingapi;
Expand Down Expand Up @@ -38,7 +39,7 @@ pub fn query() -> Result<impl Iterator<Item = SimpleHit>> {
// TODO: sysinfo crate loads a lot of unnecessary data into memory,
// replace with native calls (or a crate that does streaming)
let mut sys = System::new();
sys.refresh_processes();
sys.refresh_processes(ProcessesToUpdate::All, true);

let hits = sys
.processes()
Expand All @@ -51,9 +52,10 @@ pub fn query() -> Result<impl Iterator<Item = SimpleHit>> {
}

fn get_hit(pid: sysinfo::Pid, process: &Process) -> SimpleHit {
let cmdline = process.cmd().join(" ");
let cmdline = process.cmd().join(OsStr::new(" "));
let cmdline = cmdline.to_string_lossy();

super::get_hit(process.name(), pid.as_u32(), &cmdline)
super::get_hit(&process.name().to_string_lossy(), pid.as_u32(), &cmdline)
}

fn open_process(desired_access: DWORD, pid: Pid) -> Result<Handle, KillError> {
Expand Down

0 comments on commit bbb3439

Please sign in to comment.