Skip to content

Commit

Permalink
imp: Narrow refresh kind (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
oissevalt authored Oct 21, 2024
1 parent cb46289 commit 26ab639
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 39 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
text=auto

text eol=lf
58 changes: 50 additions & 8 deletions Cargo.lock

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

49 changes: 24 additions & 25 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
[package]
name = "sealupd"
version = "0.1.0"
edition = "2021"
name = "sealupd"
version = "0.1.0"
edition = "2021"

[profile.release]
strip = true
opt-level = 'z'
lto = true
codegen-units = 1
panic = "abort"
strip = true
opt-level = 'z'
lto = true
codegen-units = 1
panic = "abort"

[dependencies]
# Command-line parser
clap = { version = "4.5.11", features = ["derive"] }
# Command-line parser
clap = { version = "4.5.11", features = ["derive"] }

# System info
sysinfo = "0.30.13"
# System info
sysinfo = "0.31.2"

# Logging
log = "0.4.22"
fern = "0.6.2"
chrono = "0.4.38"

# File archives
zip = "2.1.5"
tar = "0.4.41"
flate2 = "1.0.30"
# Logging
log = "0.4.22"
fern = "0.6.2"
chrono = "0.4.38"

# File archives
zip = "2.1.5"
tar = "0.4.41"
flate2 = "1.0.30"

[build-dependencies]
# Static links on Windows
static_vcruntime = "2.0.0"
# Static links on Windows
static_vcruntime = "2.0.0"

# Manifest files for 32-bit Windows
embed-manifest = "1.4.0"
# Manifest files for 32-bit Windows
embed-manifest = "1.4.0"
30 changes: 24 additions & 6 deletions src/proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
use std::{process, thread, time::Duration};

use log::debug;
use sysinfo::{Pid, ProcessRefreshKind, RefreshKind, System};
use sysinfo::{Pid, ProcessRefreshKind, ProcessesToUpdate, RefreshKind, System};

struct RefreshSpecs {
refresh_kind: RefreshKind,
proc_refresh_kind: ProcessRefreshKind,
}

impl RefreshSpecs {
pub fn new() -> Self {
let proc_refresh_kind = ProcessRefreshKind::new();
RefreshSpecs {
refresh_kind: RefreshKind::new().with_processes(proc_refresh_kind),
proc_refresh_kind,
}
}
}

/// Waits for the process with specified PID to finish. If the program is spawned
/// by that process, finishes waiting if the program has inherited the PID.
Expand All @@ -14,21 +29,24 @@ pub fn wait(pid: u32) {
return;
}

let mut sys = System::new_with_specifics(
RefreshKind::new().with_processes(ProcessRefreshKind::everything()),
);
let specs = RefreshSpecs::new();
let mut sys = System::new_with_specifics(specs.refresh_kind);

loop {
match sys.process(pid) {
None => break,
Some(proc) => {
let pname = proc.name();
debug!("Found process {} \"{}\"", pid, pname.escape_debug());
debug!(
"Found process {} \"{}\"",
pid,
pname.to_string_lossy().escape_debug()
);
if pname == env!("CARGO_PKG_NAME") || prog_pid == pid {
break;
}

sys.refresh_processes();
sys.refresh_processes_specifics(ProcessesToUpdate::All, specs.proc_refresh_kind);
prog_pid = Pid::from_u32(process::id());
thread::sleep(Duration::from_secs(1));
}
Expand Down

0 comments on commit 26ab639

Please sign in to comment.