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
2 changes: 1 addition & 1 deletion src/uu/tail/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ libc = { workspace = true }
notify = { workspace = true }

[target.'cfg(unix)'.dependencies]
rustix = { workspace = true, features = ["fs"] }
rustix = { workspace = true, features = ["fs", "process"] }

[target.'cfg(windows)'.dependencies]
windows-sys = { workspace = true, features = [
Expand Down
29 changes: 19 additions & 10 deletions src/uu/tail/src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
// file that was distributed with this source code.

// spell-checker:ignore (ToDO) stdlib, ISCHR, GETFD
// spell-checker:ignore (options) EPERM, ENOSYS
// spell-checker:ignore (options) EPERM, ENOSYS, NOSYS

use std::io::Error;
use rustix::process::{Pid as RustixPid, test_kill_process};

pub type Pid = libc::pid_t;
pub type Pid = i32;

pub struct ProcessChecker {
pid: Pid,
Expand All @@ -20,7 +20,14 @@ impl ProcessChecker {
}

pub fn is_dead(&self) -> bool {
unsafe { libc::kill(self.pid, 0) != 0 && get_errno() != libc::EPERM }
let Some(pid) = RustixPid::from_raw(self.pid) else {
return true;
};
match test_kill_process(pid) {
Ok(()) => false,
Err(rustix::io::Errno::PERM) => false,
Err(_) => true,
}
}
}

Expand All @@ -29,12 +36,14 @@ impl Drop for ProcessChecker {
}

pub fn supports_pid_checks(pid: Pid) -> bool {
unsafe { !(libc::kill(pid, 0) != 0 && get_errno() == libc::ENOSYS) }
}

#[inline]
fn get_errno() -> i32 {
Error::last_os_error().raw_os_error().unwrap()
let Some(pid) = RustixPid::from_raw(pid) else {
return false;
};
match test_kill_process(pid) {
Ok(()) => true,
Err(rustix::io::Errno::NOSYS) => false,
Err(_) => true,
}
}

//pub fn stdin_is_bad_fd() -> bool {
Expand Down
Loading