From 3069f12da0a0d18658ec292871bfd7cc6806232d Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Sat, 21 May 2022 14:30:26 +0100 Subject: [PATCH] extracted prepare spawner --- src/spawner/mod.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/spawner/mod.rs b/src/spawner/mod.rs index aa3688e..77f28cc 100644 --- a/src/spawner/mod.rs +++ b/src/spawner/mod.rs @@ -99,15 +99,11 @@ impl<'a> Spawner<'a> { Trigger::Pipe(s) => { 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); + self.prepare_spawner(&mut builder, &entrypoint.environment, &entrypoint.args)?; 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) => { @@ -126,15 +122,11 @@ impl<'a> Spawner<'a> { Trigger::FileSocket(s) => { 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); + self.prepare_spawner(&mut builder, &entrypoint.environment, &entrypoint.args)?; 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) => { @@ -325,6 +317,20 @@ impl<'a> Spawner<'a> { } } + fn prepare_spawner<'b>( + &self, + builder: &mut VoidBuilder, + environment: impl IntoIterator, + args: impl IntoIterator + Copy, + ) -> Result<()> { + self.mount_entrypoint(builder, self.binary)?; + self.forward_mounts(builder, environment, args); + self.forward_files(builder, args); + builder.mount("/proc", "/proc").remount_proc(); + + Ok(()) + } + fn prepare_env<'b>( &self, builder: &mut VoidBuilder, -- 2.47.0