mirror of
https://github.com/mii443/izoli.git
synced 2025-08-22 16:05:40 +00:00
refactor prelude
This commit is contained in:
@ -48,7 +48,7 @@ impl IzoliBox {
|
|||||||
|
|
||||||
let mut callback = callback;
|
let mut callback = callback;
|
||||||
let new_callback = Box::new(|| {
|
let new_callback = Box::new(|| {
|
||||||
IzoliBox::prelude(self.id).unwrap();
|
self.prelude().unwrap();
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
|
|
||||||
@ -58,11 +58,28 @@ impl IzoliBox {
|
|||||||
unsafe { sched::clone(new_callback, &mut stack, flags, Some(SIGCHLD)) }
|
unsafe { sched::clone(new_callback, &mut stack, flags, Some(SIGCHLD)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prelude(id: usize) -> Result<(), Box<dyn std::error::Error>> {
|
fn prelude(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
info!("box prelude");
|
info!("box prelude");
|
||||||
let root = format!("/var/local/lib/izoli/{}", id);
|
let root = self.get_root();
|
||||||
fs::create_dir_all(Path::new(&root))?;
|
fs::create_dir_all(Path::new(&root))?;
|
||||||
|
|
||||||
|
self.prelude_mount()?;
|
||||||
|
|
||||||
|
info!("chroot to {}", root);
|
||||||
|
chroot(&root)?;
|
||||||
|
set_current_dir("/")?;
|
||||||
|
|
||||||
|
sethostname(format!("IzoliBox"))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_root(&self) -> String {
|
||||||
|
format!("/var/local/lib/izoli/{}", self.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn prelude_mount(&self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let root = self.get_root();
|
||||||
|
|
||||||
Self::umount_mount(
|
Self::umount_mount(
|
||||||
Some("none"),
|
Some("none"),
|
||||||
"/",
|
"/",
|
||||||
@ -118,12 +135,6 @@ impl IzoliBox {
|
|||||||
None::<&str>,
|
None::<&str>,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("chroot to {}", root);
|
|
||||||
chroot(&root)?;
|
|
||||||
set_current_dir("/")?;
|
|
||||||
|
|
||||||
sethostname(format!("IzoliBox"))?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user