Cleanup zombies in container - show scheme namespace in context list

This commit is contained in:
Jeremy Soller 2016-11-17 12:24:46 -07:00
parent bf292bc0d1
commit c5e0d77085
2 changed files with 16 additions and 4 deletions

View file

@ -5,7 +5,7 @@ use context;
use syscall::error::Result;
pub fn resource() -> Result<Vec<u8>> {
let mut string = format!("{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<8}{}\n",
let mut string = format!("{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<8}{:<6}{}\n",
"PID",
"PPID",
"UID",
@ -13,6 +13,7 @@ pub fn resource() -> Result<Vec<u8>> {
"STAT",
"CPU",
"MEM",
"SNS",
"NAME");
{
let contexts = context::contexts();
@ -82,7 +83,7 @@ pub fn resource() -> Result<Vec<u8>> {
let name_bytes = context.name.lock();
let name = str::from_utf8(&name_bytes).unwrap_or("");
string.push_str(&format!("{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<8}{}\n",
string.push_str(&format!("{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<8}{:<6}{}\n",
context.id.into(),
context.ppid.into(),
context.euid,
@ -90,6 +91,7 @@ pub fn resource() -> Result<Vec<u8>> {
stat_string,
cpu_string,
memory_string,
context.scheme_ns.into(),
name));
}
}

View file

@ -22,7 +22,7 @@ pub fn main() {
syscall::setns(&name_ptrs).unwrap();
println!("Entering container: {}", command);
println!("Container enter: {}", command);
let err = Command::new(command).exec();
@ -31,6 +31,16 @@ pub fn main() {
let mut status = 0;
syscall::waitpid(pid, &mut status, 0).unwrap();
println!("Exiting container: {:X}", status);
loop {
let mut c_status = 0;
let c_pid = syscall::waitpid(0, &mut c_status, syscall::WNOHANG).unwrap();
if c_pid == 0 {
break;
} else {
println!("Container zombie {}: {:X}", c_pid, c_status);
}
}
println!("Container exited: {:X}", status);
}
}