use crate::{JailError, RunningJail};
use log::trace;
use std::os::unix::process::CommandExt;
use std::process;
#[cfg(target_os = "freebsd")]
pub trait Jailed {
fn jail(&mut self, jail: &RunningJail) -> &mut process::Command;
}
#[cfg(target_os = "freebsd")]
impl Jailed for process::Command {
fn jail(&mut self, jail: &RunningJail) -> &mut process::Command {
trace!("process::Command::jail({:?}, jail={:?})", self, jail);
let jail = *jail;
unsafe {
self.pre_exec(move || {
trace!("pre_exec handler: attaching");
jail.attach().map_err(|err| match err {
JailError::JailAttachError(e) => e,
_ => panic!("jail.attach() failed with unexpected error"),
})
});
}
self
}
}