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
8 changes: 8 additions & 0 deletions src/uu/pgrep/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@ impl ProcessInformation {
self.get_uid_or_gid_field("Gid", 1)
}

pub fn suid(&mut self) -> Result<u32, io::Error> {
self.get_uid_or_gid_field("Uid", 2)
}

pub fn sgid(&mut self) -> Result<u32, io::Error> {
self.get_uid_or_gid_field("Gid", 2)
}

// Root directory of the process (which can be changed by chroot)
pub fn root(&mut self) -> Result<PathBuf, io::Error> {
read_link(format!("/proc/{}/root", self.pid))
Expand Down
62 changes: 45 additions & 17 deletions src/uu/ps/src/picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,24 @@ pub(crate) fn collect_pickers(
match code.as_str() {
"pid" | "tgid" => pickers.push(helper(pid)),
"ppid" => pickers.push(helper(ppid)),
"uid" => pickers.push(helper(uid)),
"euid" => pickers.push(helper(euid)),
"user" => pickers.push(helper(user)),
"euser" => pickers.push(helper(euser)),
"uid" | "euid" => pickers.push(helper(euid)),
"ruid" => pickers.push(helper(ruid)),
"suid" => pickers.push(helper(suid)),
"user" | "euser" => pickers.push(helper(euser)),
"ruser" => pickers.push(helper(ruser)),
"suser" => pickers.push(helper(suser)),
"pgid" => pickers.push(helper(pgid)),
"sid" => pickers.push(helper(sid)),
"gid" => pickers.push(helper(gid)),
"egid" => pickers.push(helper(egid)),
"group" => pickers.push(helper(group)),
"egroup" => pickers.push(helper(egroup)),
"sid" | "sess" => pickers.push(helper(sid)),
"gid" | "egid" => pickers.push(helper(egid)),
"rgid" => pickers.push(helper(rgid)),
"sgid" => pickers.push(helper(sgid)),
"group" | "egroup" => pickers.push(helper(egroup)),
"rgroup" => pickers.push(helper(rgroup)),
"sgroup" => pickers.push(helper(sgroup)),
"tname" | "tt" | "tty" => pickers.push(helper(tty)),
"time" | "cputime" => pickers.push(helper(time)),
"ucmd" => pickers.push(helper(ucmd)),
"cmd" => pickers.push(helper(cmd)),
"ucmd" | "comm" => pickers.push(helper(ucmd)),
"cmd" | "command" | "args" => pickers.push(helper(cmd)),
_ => {}
}
}
Expand All @@ -64,15 +68,19 @@ fn ppid(proc_info: RefCell<ProcessInformation>) -> String {
proc_info.borrow_mut().ppid().unwrap().to_string()
}

fn uid(proc_info: RefCell<ProcessInformation>) -> String {
fn ruid(proc_info: RefCell<ProcessInformation>) -> String {
proc_info.borrow_mut().uid().unwrap().to_string()
}

fn euid(proc_info: RefCell<ProcessInformation>) -> String {
proc_info.borrow_mut().euid().unwrap().to_string()
}

fn user(proc_info: RefCell<ProcessInformation>) -> String {
fn suid(proc_info: RefCell<ProcessInformation>) -> String {
proc_info.borrow_mut().suid().unwrap_or(0).to_string()
}

fn ruser(proc_info: RefCell<ProcessInformation>) -> String {
let uid = proc_info.borrow_mut().uid().unwrap();
uid2usr(uid).ok().unwrap_or_else(|| uid.to_string())
}
Expand All @@ -82,15 +90,24 @@ fn euser(proc_info: RefCell<ProcessInformation>) -> String {
uid2usr(euid).ok().unwrap_or_else(|| euid.to_string())
}

fn gid(proc_info: RefCell<ProcessInformation>) -> String {
fn suser(proc_info: RefCell<ProcessInformation>) -> String {
let suid = proc_info.borrow_mut().suid().unwrap_or(0);
uid2usr(suid).unwrap_or_else(|_| suid.to_string())
}

fn rgid(proc_info: RefCell<ProcessInformation>) -> String {
proc_info.borrow_mut().gid().unwrap().to_string()
}

fn egid(proc_info: RefCell<ProcessInformation>) -> String {
proc_info.borrow_mut().egid().unwrap().to_string()
}

fn group(proc_info: RefCell<ProcessInformation>) -> String {
fn sgid(proc_info: RefCell<ProcessInformation>) -> String {
proc_info.borrow_mut().sgid().unwrap_or(0).to_string()
}

fn rgroup(proc_info: RefCell<ProcessInformation>) -> String {
let gid = proc_info.borrow_mut().gid().unwrap();
gid2grp(gid).ok().unwrap_or_else(|| gid.to_string())
}
Expand All @@ -100,6 +117,11 @@ fn egroup(proc_info: RefCell<ProcessInformation>) -> String {
gid2grp(egid).ok().unwrap_or_else(|| egid.to_string())
}

fn sgroup(proc_info: RefCell<ProcessInformation>) -> String {
let sgid = proc_info.borrow_mut().sgid().unwrap_or(0);
gid2grp(sgid).unwrap_or_else(|_| sgid.to_string())
}

fn pgid(proc_info: RefCell<ProcessInformation>) -> String {
proc_info.borrow_mut().pgid().unwrap().to_string()
}
Expand Down Expand Up @@ -144,11 +166,17 @@ fn format_time(seconds: i64) -> String {
}

fn cmd(proc_info: RefCell<ProcessInformation>) -> String {
proc_info.borrow().cmdline.clone()
// Use command line if available, otherwise show process name in brackets (for kernel threads)
let cmdline = proc_info.borrow().cmdline.clone();
if !cmdline.is_empty() {
cmdline
} else {
format!("[{}]", proc_info.borrow_mut().name().unwrap())
}
}

fn ucmd(proc_info: RefCell<ProcessInformation>) -> String {
proc_info.borrow_mut().status().get("Name").unwrap().into()
proc_info.borrow_mut().name().unwrap()
}

#[test]
Expand Down
Loading