-
-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathuid.rs
More file actions
89 lines (75 loc) · 2.33 KB
/
Copy pathuid.rs
File metadata and controls
89 lines (75 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use crate::process::ProcessInfo;
#[cfg(target_os = "windows")]
use crate::util::format_sid;
use crate::{column_default, Column};
use std::cmp;
use std::collections::HashMap;
pub struct Uid {
header: String,
unit: String,
fmt_contents: HashMap<i32, String>,
raw_contents: HashMap<i32, u32>,
width: usize,
#[allow(dead_code)]
abbr_sid: bool,
}
impl Uid {
pub fn new(header: Option<String>, abbr_sid: bool) -> Self {
let header = header.unwrap_or_else(|| String::from("UID"));
let unit = String::new();
Self {
fmt_contents: HashMap::new(),
raw_contents: HashMap::new(),
width: 0,
header,
unit,
abbr_sid,
}
}
}
#[cfg(any(target_os = "linux", target_os = "android"))]
impl Column for Uid {
fn add(&mut self, proc: &ProcessInfo) {
let (fmt_content, raw_content) = if let Some(ref status) = proc.curr_status {
let uid = status.euid;
(format!("{uid}"), uid)
} else {
(String::new(), 0)
};
self.fmt_contents.insert(proc.pid, fmt_content);
self.raw_contents.insert(proc.pid, raw_content);
}
column_default!(u32, true);
}
#[cfg(target_os = "macos")]
impl Column for Uid {
fn add(&mut self, proc: &ProcessInfo) {
let uid = proc.curr_task.pbsd.pbi_uid;
let fmt_content = format!("{}", uid);
let raw_content = uid;
self.fmt_contents.insert(proc.pid, fmt_content);
self.raw_contents.insert(proc.pid, raw_content);
}
column_default!(u32, true);
}
#[cfg(target_os = "windows")]
impl Column for Uid {
fn add(&mut self, proc: &ProcessInfo) {
let fmt_content = format_sid(&proc.user.sid, self.abbr_sid);
let raw_content = proc.user.sid[proc.user.sid.len() - 1] as u32;
self.fmt_contents.insert(proc.pid, fmt_content);
self.raw_contents.insert(proc.pid, raw_content);
}
column_default!(u32, true);
}
#[cfg(target_os = "freebsd")]
impl Column for Uid {
fn add(&mut self, proc: &ProcessInfo) {
let uid = proc.curr_proc.info.uid;
let fmt_content = format!("{}", uid);
let raw_content = uid;
self.fmt_contents.insert(proc.pid, fmt_content);
self.raw_contents.insert(proc.pid, raw_content);
}
column_default!(u32, true);
}