diff --git a/Cargo.toml b/Cargo.toml index 182aa55..6f802c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,4 +12,4 @@ name = "izoli" path = "src/bin/izoli.rs" [dependencies] -nix = { version = "0.29.0", features = ["sched"] } +nix = { version = "0.29.0", features = ["sched", "hostname"] } diff --git a/src/bin/izoli.rs b/src/bin/izoli.rs index 00d36c6..09f2136 100644 --- a/src/bin/izoli.rs +++ b/src/bin/izoli.rs @@ -1,7 +1,13 @@ +use std::{ffi::CString, process::Command}; + use izolilib::{ cgroup::{cgroup::CGroup, cgroup_option::CGroupOption, cpu_limit::CpuLimit}, izolibox::IzoliBox, }; +use nix::{ + sys::wait::waitpid, + unistd::{execvp, sethostname}, +}; fn main() { let cgroup = CGroup::new("izoli").unwrap(); @@ -25,17 +31,34 @@ fn main() { 1, Some(CGroupOption { cpu_max: Some(CpuLimit { - max: izolilib::cgroup::limit_value::CGroupLimitValue::Value(1000), + max: izolilib::cgroup::limit_value::CGroupLimitValue::Max, period: 100000, }), }), ); let pid = izolibox .enter(Box::new(|| { + sethostname(format!("IzoliBox")).unwrap(); println!("Isolated process: {}", std::process::id()); println!("cgroup: {:?}", CGroup::get_self_cgroup()); + + let cmd = CString::new("bash").unwrap(); + let args = vec![ + CString::new("containered bash").unwrap(), + CString::new("-l").unwrap(), + ]; + if let Err(e) = execvp(&cmd, &args.as_ref()) { + eprintln!("execvp failed: {:?}", e); + return 127; + } + 127 })) .unwrap(); + + if let Ok(status) = waitpid(pid, None) { + println!("{:?}", status); + } + println!("Box real PID: {:?}", pid); }