Skip to content

Commit 638cc84

Browse files
committed
ps: Implement suid, suser, sgid, sgroup fields
1 parent 8aaaa23 commit 638cc84

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/uu/ps/src/picker.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@ pub(crate) fn collect_pickers(
3030
"ppid" => pickers.push(helper(ppid)),
3131
"uid" | "euid" => pickers.push(helper(euid)),
3232
"ruid" => pickers.push(helper(ruid)),
33+
"suid" => pickers.push(helper(suid)),
3334
"user" | "euser" => pickers.push(helper(euser)),
3435
"ruser" => pickers.push(helper(ruser)),
36+
"suser" => pickers.push(helper(suser)),
3537
"pgid" => pickers.push(helper(pgid)),
3638
"sid" | "sess" => pickers.push(helper(sid)),
3739
"gid" | "egid" => pickers.push(helper(egid)),
3840
"rgid" => pickers.push(helper(rgid)),
41+
"sgid" => pickers.push(helper(sgid)),
3942
"group" | "egroup" => pickers.push(helper(egroup)),
4043
"rgroup" => pickers.push(helper(rgroup)),
44+
"sgroup" => pickers.push(helper(sgroup)),
4145
"tname" | "tt" | "tty" => pickers.push(helper(tty)),
4246
"time" | "cputime" => pickers.push(helper(time)),
4347
"ucmd" | "comm" => pickers.push(helper(ucmd)),
@@ -72,6 +76,10 @@ fn euid(proc_info: RefCell<ProcessInformation>) -> String {
7276
proc_info.borrow_mut().euid().unwrap().to_string()
7377
}
7478

79+
fn suid(proc_info: RefCell<ProcessInformation>) -> String {
80+
proc_info.borrow_mut().suid().unwrap_or(0).to_string()
81+
}
82+
7583
fn ruser(proc_info: RefCell<ProcessInformation>) -> String {
7684
let uid = proc_info.borrow_mut().uid().unwrap();
7785
uid2usr(uid).ok().unwrap_or_else(|| uid.to_string())
@@ -82,6 +90,11 @@ fn euser(proc_info: RefCell<ProcessInformation>) -> String {
8290
uid2usr(euid).ok().unwrap_or_else(|| euid.to_string())
8391
}
8492

93+
fn suser(proc_info: RefCell<ProcessInformation>) -> String {
94+
let suid = proc_info.borrow_mut().suid().unwrap_or(0);
95+
uid2usr(suid).unwrap_or_else(|_| suid.to_string())
96+
}
97+
8598
fn rgid(proc_info: RefCell<ProcessInformation>) -> String {
8699
proc_info.borrow_mut().gid().unwrap().to_string()
87100
}
@@ -90,6 +103,10 @@ fn egid(proc_info: RefCell<ProcessInformation>) -> String {
90103
proc_info.borrow_mut().egid().unwrap().to_string()
91104
}
92105

106+
fn sgid(proc_info: RefCell<ProcessInformation>) -> String {
107+
proc_info.borrow_mut().sgid().unwrap_or(0).to_string()
108+
}
109+
93110
fn rgroup(proc_info: RefCell<ProcessInformation>) -> String {
94111
let gid = proc_info.borrow_mut().gid().unwrap();
95112
gid2grp(gid).ok().unwrap_or_else(|| gid.to_string())
@@ -100,6 +117,11 @@ fn egroup(proc_info: RefCell<ProcessInformation>) -> String {
100117
gid2grp(egid).ok().unwrap_or_else(|| egid.to_string())
101118
}
102119

120+
fn sgroup(proc_info: RefCell<ProcessInformation>) -> String {
121+
let sgid = proc_info.borrow_mut().sgid().unwrap_or(0);
122+
gid2grp(sgid).unwrap_or_else(|_| sgid.to_string())
123+
}
124+
103125
fn pgid(proc_info: RefCell<ProcessInformation>) -> String {
104126
proc_info.borrow_mut().pgid().unwrap().to_string()
105127
}

0 commit comments

Comments
 (0)