Skip to content
Open
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: 2 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ xattr = { workspace = true }
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dev-dependencies]
rlimit = "0.11.0"

[target.'cfg(target_os = "linux")'.dependencies]
rustix = { workspace = true }

[build-dependencies]
phf_codegen = { workspace = true }

Expand Down
22 changes: 14 additions & 8 deletions src/uu/pgrep/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ impl ProcessInformation {

pub fn current_process_info() -> Result<ProcessInformation, io::Error> {
#[cfg(target_os = "linux")]
let pid = uucore::process::getpid();
let pid = rustix::process::getpid().as_raw_pid();
#[cfg(not(target_os = "linux"))]
let pid = 0; // dummy

Expand Down Expand Up @@ -798,9 +798,9 @@ pub fn walk_threads() -> impl Iterator<Item = ProcessInformation> {
mod tests {
use super::*;
#[cfg(target_os = "linux")]
use std::collections::HashSet;
use rustix::process::getpid;
#[cfg(target_os = "linux")]
use uucore::process::getpid;
use std::collections::HashSet;

#[test]
#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -870,7 +870,7 @@ unknown /dev/tty 4 1-63 console"#;
#[test]
#[cfg(target_os = "linux")]
fn test_walk_pid() {
let find = walk_process().find(|it| it.pid == getpid() as usize);
let find = walk_process().find(|it| it.pid == getpid().as_raw_pid() as usize);

assert!(find.is_some());
}
Expand Down Expand Up @@ -963,10 +963,16 @@ unknown /dev/tty 4 1-63 console"#;
#[cfg(target_os = "linux")]
fn test_uid_gid() {
let mut pid_entry = ProcessInformation::current_process_info().unwrap();
assert_eq!(pid_entry.uid().unwrap(), uucore::process::getuid());
assert_eq!(pid_entry.euid().unwrap(), uucore::process::geteuid());
assert_eq!(pid_entry.gid().unwrap(), uucore::process::getgid());
assert_eq!(pid_entry.egid().unwrap(), uucore::process::getegid());
assert_eq!(pid_entry.uid().unwrap(), rustix::process::getuid().as_raw());
assert_eq!(
pid_entry.euid().unwrap(),
rustix::process::geteuid().as_raw()
);
assert_eq!(pid_entry.gid().unwrap(), rustix::process::getgid().as_raw());
assert_eq!(
pid_entry.egid().unwrap(),
rustix::process::getegid().as_raw()
);
}

#[test]
Expand Down
3 changes: 3 additions & 0 deletions src/uu/pidof/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ uucore = { workspace = true, features = ["process"] }
clap = { workspace = true }
uu_pgrep = { path = "../pgrep" }

[target.'cfg(unix)'.dependencies]
rustix = { workspace = true }

[lib]
path = "src/pidof.rs"

Expand Down
6 changes: 3 additions & 3 deletions src/uu/pidof/src/pidof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
use std::path::PathBuf;

use clap::{crate_version, Arg, ArgAction, ArgMatches, Command};
#[cfg(unix)]
use rustix::process::geteuid;
use uu_pgrep::process::{walk_process, ProcessInformation};
use uucore::error::UResult;
#[cfg(unix)]
use uucore::process::geteuid;

#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Expand Down Expand Up @@ -95,7 +95,7 @@ fn collect_matched_pids(matches: &ArgMatches) -> Vec<usize> {

// Original pidof silently ignores the check-root option if the user is not root.
#[cfg(unix)]
let check_root = matches.get_flag("check-root") && geteuid() == 0;
let check_root = matches.get_flag("check-root") && geteuid().as_raw() == 0;
#[cfg(not(unix))]
let check_root = false;
let our_root = ProcessInformation::current_process_info()
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_pgrep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ fn test_invalid_group_name() {
fn test_current_user() {
new_ucmd!()
.arg("-U")
.arg(uucore::process::getuid().to_string())
.arg(rustix::process::getuid().as_raw().to_string())
.succeeds();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/by-util/test_ps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use regex::Regex;
use uutests::new_ucmd;

#[cfg(target_os = "linux")]
use uucore::process::geteuid;
use rustix::process::geteuid;

#[test]
#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -402,7 +402,7 @@ fn test_combined_selection_criteria() {
"--pid",
"1",
"--user",
&geteuid().to_string(),
&geteuid().as_raw().to_string(),
"--no-headers",
"-o",
"pid",
Expand Down