extracted prepare spawner #43

Merged
JakeHillion merged 1 commits from prepare-spawner into main 2022-05-21 14:55:50 +01:00
Showing only changes of commit 3069f12da0 - Show all commits

View File

@ -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<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>(
&self,
builder: &mut VoidBuilder,