use libc;
use std::process;
use std::io::{Error, ErrorKind};
use std::os::unix::process::CommandExt;
#[cfg(target_os = "freebsd")]
pub trait Jailed {
fn jail(&mut self, jid: i32) -> &mut process::Command;
}
#[cfg(target_os = "freebsd")]
impl Jailed for process::Command {
fn jail(&mut self, jid: i32) -> &mut process::Command {
self.before_exec(move || {
let ret = unsafe { libc::jail_attach(jid) };
match ret {
0 => Ok(()),
-1 => Err(Error::last_os_error()),
_ => Err(Error::new(
ErrorKind::Other,
"invalid return value from jail_attach",
)),
}
});
self
}
}