/
id.rs
102 lines (94 loc) · 2.6 KB
/
id.rs
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
90
91
92
93
94
95
96
97
98
99
100
101
102
use rustix::process;
#[test]
fn test_getuid() {
assert_eq!(process::getuid(), process::getuid());
unsafe {
assert_eq!(process::getuid().as_raw(), libc::getuid());
assert_eq!(process::getuid().is_root(), libc::getuid() == 0);
}
}
#[test]
fn test_getgid() {
assert_eq!(process::getgid(), process::getgid());
unsafe {
assert_eq!(process::getgid().as_raw(), libc::getgid());
assert_eq!(process::getgid().is_root(), libc::getgid() == 0);
}
}
#[test]
fn test_geteuid() {
assert_eq!(process::geteuid(), process::geteuid());
unsafe {
assert_eq!(process::geteuid().as_raw(), libc::geteuid());
assert_eq!(process::geteuid().is_root(), libc::geteuid() == 0);
}
}
#[test]
fn test_getegid() {
assert_eq!(process::getegid(), process::getegid());
unsafe {
assert_eq!(process::getegid().as_raw(), libc::getegid());
assert_eq!(process::getegid().is_root(), libc::getegid() == 0);
}
}
#[test]
fn test_getpid() {
assert_eq!(process::getpid(), process::getpid());
unsafe {
assert_eq!(
process::getpid().as_raw_nonzero().get() as libc::pid_t,
libc::getpid()
);
assert_eq!(process::getpid().is_init(), libc::getpid() == 1);
}
}
#[test]
fn test_getppid() {
assert_eq!(process::getppid(), process::getppid());
unsafe {
assert_eq!(
process::Pid::as_raw(process::getppid()) as libc::pid_t,
libc::getppid()
);
if let Some(ppid) = process::getppid() {
assert_eq!(ppid.is_init(), libc::getppid() == 1);
} else {
assert_eq!(libc::getppid(), 0);
}
}
}
#[test]
fn test_getpgid() {
assert_eq!(process::getpgid(None), process::getpgid(None));
assert_eq!(
process::getpgid(Some(process::getpid())),
process::getpgid(Some(process::getpid()))
);
unsafe {
assert_eq!(
process::getpgid(None).unwrap().as_raw_nonzero().get() as libc::pid_t,
libc::getpgid(0)
);
assert_eq!(
process::getpgid(None).unwrap().is_init(),
libc::getpgid(0) == 1
);
assert_eq!(
process::getpgid(Some(process::getpid()))
.unwrap()
.as_raw_nonzero()
.get() as libc::pid_t,
libc::getpgid(libc::getpid())
);
}
}
#[test]
fn test_getpgrp() {
assert_eq!(process::getpgrp(), process::getpgrp());
unsafe {
assert_eq!(
process::getpgrp().as_raw_nonzero().get() as libc::pid_t,
libc::getpgrp()
);
}
}