diff --git a/src/spawner/mod.rs b/src/spawner/mod.rs index 06880c5..d460c41 100644 --- a/src/spawner/mod.rs +++ b/src/spawner/mod.rs @@ -105,6 +105,8 @@ impl<'a> Spawner<'a> { let pipe = self.pipes.get_mut(s).unwrap().take_read()?; builder.keep_fd(&pipe); + builder.mount("/proc", "/proc").remount_proc(); + let closure = || match self.pipe_trigger(pipe, entrypoint, name) { Ok(()) => exitcode::OK, Err(e) => { @@ -129,6 +131,8 @@ impl<'a> Spawner<'a> { let socket = self.sockets.get_mut(s).unwrap().take_read()?; builder.keep_fd(&socket); + builder.mount("/proc", "/proc").remount_proc(); + let closure = || match self.file_socket_trigger(socket, entrypoint, name) { Ok(()) => exitcode::OK, Err(e) => { @@ -327,6 +331,10 @@ impl<'a> Spawner<'a> { Environment::DomainName(name) => { builder.set_domain_name(name); } + + Environment::Procfs => { + builder.mount("/proc", "/proc").remount_proc(); + } } } } diff --git a/src/specification.rs b/src/specification.rs index 2ce9c97..18d9de7 100644 --- a/src/specification.rs +++ b/src/specification.rs @@ -117,6 +117,8 @@ pub enum Environment { Hostname(String), DomainName(String), + + Procfs, } #[derive(Serialize, Deserialize, PartialEq, Eq, Hash, Debug)] diff --git a/src/void.rs b/src/void.rs index 06a4eda..1b02e92 100644 --- a/src/void.rs +++ b/src/void.rs @@ -33,6 +33,8 @@ pub struct VoidBuilder { mounts: HashMap, fds: HashSet, + + remount_proc: bool, } impl VoidBuilder { @@ -42,6 +44,7 @@ impl VoidBuilder { domain_name: None, mounts: HashMap::new(), fds: HashSet::new(), + remount_proc: false, } } @@ -65,6 +68,11 @@ impl VoidBuilder { self } + pub fn remount_proc(&mut self) -> &mut Self { + self.remount_proc = true; + self + } + pub fn spawn(&mut self, child_fn: impl FnOnce() -> i32) -> Result { let mut args = CloneArgs::new( CloneFlags::CLONE_NEWCGROUP @@ -252,12 +260,29 @@ impl VoidBuilder { fs::write(&dst, b"")?; } - // bind mount + // rbind mount mount( Some(&src), &dst, Option::<&str>::None, - MsFlags::MS_BIND, + MsFlags::MS_BIND | MsFlags::MS_REC, + Option::<&str>::None, + ) + .map_err(|e| Error::Nix { + msg: "mount", + src: e, + })?; + } + + // remount proc + if self.remount_proc { + debug!("remounting /proc`"); + + mount( + Some("proc"), + "/proc", + Some("proc"), + MsFlags::empty(), Option::<&str>::None, ) .map_err(|e| Error::Nix {