diff --git a/Cargo.toml b/Cargo.toml index 3a211a8..182aa55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,4 @@ name = "izoli" path = "src/bin/izoli.rs" [dependencies] +nix = { version = "0.29.0", features = ["sched"] } diff --git a/src/izolibox.rs b/src/izolibox.rs index d1fed94..b84416d 100644 --- a/src/izolibox.rs +++ b/src/izolibox.rs @@ -1 +1,25 @@ +use nix::{ + libc::SIGCHLD, + sched::{self, CloneCb, CloneFlags}, + unistd::Pid, +}; + +const STACK_SIZE: usize = 8192; + pub struct IzoliBox {} + +impl IzoliBox { + pub fn new() -> Self { + Self {} + } + + pub fn enter(&self, callback: CloneCb<'_>) -> Result { + let mut stack = [0u8; STACK_SIZE]; + let flags = CloneFlags::CLONE_NEWNS + | CloneFlags::CLONE_NEWUTS + | CloneFlags::CLONE_NEWIPC + | CloneFlags::CLONE_NEWPID; + + unsafe { sched::clone(callback, &mut stack, flags, Some(SIGCHLD)) } + } +}