forwarded necessary fds in spawners
Some checks are pending
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is running

This commit is contained in:
Jake Hillion 2022-05-19 18:01:58 +01:00
parent 01f8f096c6
commit 8943d56a46
3 changed files with 27 additions and 0 deletions

View File

@ -199,4 +199,8 @@ impl SocketPair {
// SAFETY: valid new fd as dup(2) returned successfully
Ok(unsafe { File::from_raw_fd(dup_fd) })
}
fn write_ref(&self) -> &File {
&self.write
}
}

View File

@ -101,6 +101,7 @@ impl<'a> Spawner<'a> {
let mut builder = VoidBuilder::new();
self.mount_entrypoint(&mut builder, self.binary)?;
self.forward_mounts(&mut builder, &entrypoint.environment, &entrypoint.args);
self.forward_files(&mut builder, &entrypoint.args);
let pipe = self.pipes.get_mut(s).unwrap().take_read()?;
builder.keep_fd(&pipe);
@ -127,6 +128,7 @@ impl<'a> Spawner<'a> {
let mut builder = VoidBuilder::new();
self.mount_entrypoint(&mut builder, self.binary)?;
self.forward_mounts(&mut builder, &entrypoint.environment, &entrypoint.args);
self.forward_files(&mut builder, &entrypoint.args);
let socket = self.sockets.get_mut(s).unwrap().take_read()?;
builder.keep_fd(&socket);
@ -311,6 +313,18 @@ impl<'a> Spawner<'a> {
}
}
fn forward_files<'b>(
&self,
builder: &mut VoidBuilder,
arguments: impl IntoIterator<Item = &'b Arg>,
) {
for arg in arguments {
if let Arg::FileSocket(socket) = arg {
builder.keep_fd(self.sockets.get(socket.get_name()).unwrap().write_ref());
}
}
}
fn prepare_env<'b>(
&self,
builder: &mut VoidBuilder,

View File

@ -99,6 +99,15 @@ pub enum FileSocket {
Tx(String),
}
impl FileSocket {
pub fn get_name(&self) -> &str {
match self {
FileSocket::Rx(n) => n,
FileSocket::Tx(n) => n,
}
}
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Hash, Debug)]
pub enum Environment {
Filesystem {