-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathfakeroot.rs
27 lines (22 loc) · 830 Bytes
/
fakeroot.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
extern crate unshare;
use std::process::exit;
fn main() {
let mut cmd = unshare::Command::new("/usr/bin/ls");
cmd.arg("-l");
cmd.arg("/");
cmd.fakeroot_enable("/dev/shm/sandbox_root");
cmd.fakeroot_mount("/bin", "/bin", true);
cmd.fakeroot_mount_file("/dev/urandom", "/dev/urandom", false);
cmd.fakeroot_mount("/etc", "/etc", true);
cmd.fakeroot_mount("/lib", "/lib", true);
cmd.fakeroot_mount("/lib64", "/lib64", true);
cmd.fakeroot_filesystem("proc", "/proc");
cmd.fakeroot_filesystem("tmpfs", "/tmp");
cmd.fakeroot_mount("/usr", "/usr", true);
cmd.current_dir("/");
match cmd.status().unwrap() {
// propagate signal
unshare::ExitStatus::Exited(x) => exit(x as i32),
unshare::ExitStatus::Signaled(x, _) => exit((128+x as i32) as i32),
}
}