extracted prepare spawner #43

Merged
JakeHillion merged 1 commits from prepare-spawner into main 2022-05-21 14:55:50 +01:00

View File

@ -99,15 +99,11 @@ impl<'a> Spawner<'a> {
Trigger::Pipe(s) => { Trigger::Pipe(s) => {
let mut builder = VoidBuilder::new(); let mut builder = VoidBuilder::new();
self.mount_entrypoint(&mut builder, self.binary)?; self.prepare_spawner(&mut builder, &entrypoint.environment, &entrypoint.args)?;
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()?; let pipe = self.pipes.get_mut(s).unwrap().take_read()?;
builder.keep_fd(&pipe); builder.keep_fd(&pipe);
builder.mount("/proc", "/proc").remount_proc();
let closure = || match self.pipe_trigger(pipe, entrypoint, name) { let closure = || match self.pipe_trigger(pipe, entrypoint, name) {
Ok(()) => exitcode::OK, Ok(()) => exitcode::OK,
Err(e) => { Err(e) => {
@ -126,15 +122,11 @@ impl<'a> Spawner<'a> {
Trigger::FileSocket(s) => { Trigger::FileSocket(s) => {
let mut builder = VoidBuilder::new(); let mut builder = VoidBuilder::new();
self.mount_entrypoint(&mut builder, self.binary)?; self.prepare_spawner(&mut builder, &entrypoint.environment, &entrypoint.args)?;
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()?; let socket = self.sockets.get_mut(s).unwrap().take_read()?;
builder.keep_fd(&socket); builder.keep_fd(&socket);
builder.mount("/proc", "/proc").remount_proc();
let closure = || match self.file_socket_trigger(socket, entrypoint, name) { let closure = || match self.file_socket_trigger(socket, entrypoint, name) {
Ok(()) => exitcode::OK, Ok(()) => exitcode::OK,
Err(e) => { Err(e) => {
@ -325,6 +317,20 @@ impl<'a> Spawner<'a> {
} }
} }
fn prepare_spawner<'b>(
&self,
builder: &mut VoidBuilder,
environment: impl IntoIterator<Item = &'b Environment>,
args: impl IntoIterator<Item = &'b Arg> + 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>( fn prepare_env<'b>(
&self, &self,
builder: &mut VoidBuilder, builder: &mut VoidBuilder,