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
#![cfg(target_os="linux")]
extern crate linux_api;
use linux_api::{pid_t, uid_t, gid_t};
extern "C" {
pub fn getpid() -> pid_t;
pub fn getppid() -> pid_t;
pub fn getuid() -> uid_t;
pub fn geteuid() -> uid_t;
pub fn getgid() -> gid_t;
pub fn getegid() -> gid_t;
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn ensure_not_on_process_zero() {
unsafe {
assert!(getpid() >= 0);
assert!(getppid() >= 0);
}
}
#[test]
fn ensure_group_same() {
unsafe {
assert_eq!(getgid(), getegid());
}
}
#[test]
fn ensure_user_same() {
unsafe {
assert_eq!(getuid(), geteuid());
}
}
}