Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ include = ["src/*.rs", "Cargo.toml", "README.md", "LICENSE-MIT"]
default = []

[dependencies]
libc = "0.2"
log = { version = "0.4", optional = true }
thiserror = "1.0"

[target.'cfg(not(windows))'.dependencies]
nix = { version = "0.30.1", features = ["signal"] }

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.45.0", features = [
"Win32_System_Threading",
Expand Down
12 changes: 3 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,9 @@ fn process_exists(pid: i32) -> bool {

#[cfg(not(target_os = "windows"))]
{
// SAFETY: libc::kill with signal 0 is safe when called with a valid PID because:
// - Signal 0 (null signal) performs no actual signal delivery
// - It only checks if the process exists and we have permission to signal it
// - POSIX guarantees this is a safe operation that won't affect the target process
// - We've already validated the PID is within reasonable bounds
unsafe {
let result = libc::kill(pid, 0);
result == 0
}
// We specify None as the signal, which equates to using 0 in `kill(2)`. This
// means no signal is sent, but error checking is still performed.
nix::sys::signal::kill(nix::unistd::Pid::from_raw(pid), None).is_ok()
}
}

Expand Down