More advanced setns syscall

This commit is contained in:
Jeremy Soller 2016-11-16 22:14:02 -07:00
parent d294d56b52
commit b551b30300
7 changed files with 88 additions and 35 deletions

View file

@ -1,18 +1,27 @@
extern crate syscall;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::io::{BufRead, BufReader, Read};
pub fn main() {
let pid = unsafe { syscall::clone(syscall::CLONE_NEWNS).unwrap() };
let pid = unsafe { syscall::clone(0).unwrap() };
if pid == 0 {
let rand = b"rand";
syscall::setns(&[[rand.as_ptr() as usize, rand.len()]]).unwrap();
println!("Child Namespace:");
let file = BufReader::new(File::open("sys:scheme").unwrap());
for line in file.lines() {
let line = line.unwrap();
println!("{}", line);
}
println!("");
let mut rand = File::open("rand:").unwrap();
let mut byte = [0];
rand.read(&mut byte).unwrap();
println!("Rand: {}", byte[0]);
} else {
let mut status = 0;
syscall::waitpid(pid, &mut status, 0).unwrap();
@ -23,6 +32,5 @@ pub fn main() {
let line = line.unwrap();
println!("{}", line);
}
println!("");
}
}