From 6b81db6b8d42445db25ebe095f3233816c29e0d5 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 27 Oct 2021 00:26:12 +0200 Subject: runner: tar: simplify spawn call The writing end of the pipe is moved to the child process, there is no need to funnel it back to the parent process just to drop it. --- crates/runner/src/tar.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/crates/runner/src/tar.rs b/crates/runner/src/tar.rs index 1fc4bbb..4bc343f 100644 --- a/crates/runner/src/tar.rs +++ b/crates/runner/src/tar.rs @@ -1,5 +1,4 @@ use std::{ - fs::File, io::{self, Read, Write}, os::unix::prelude::CommandExt, path::Path, @@ -23,7 +22,7 @@ use crate::paths; pub fn pack>(archive: &mut W, source: P) -> Result<()> { let (mut piper, pipew) = fs::pipe()?; - let exec_tar = |stdout: File| -> Result<()> { + let exec_tar = || -> Result<()> { // We are in our own mount namespace, so mounting into the shared ROOTFS_DIR is fine let mount_target = paths::join(&[paths::ROOTFS_DIR, paths::TASK_BUILDDIR]); mount::mount::<_, _, str, str>( @@ -47,7 +46,7 @@ pub fn pack>(archive: &mut W, source: P) -> Result<()> ".", ]) .stdin(Stdio::null()) - .stdout(stdout) + .stdout(pipew) .current_dir(paths::TASK_BUILDDIR) .env_clear() .env("PATH", "/usr/sbin:/usr/bin:/sbin:/bin") @@ -56,14 +55,10 @@ pub fn pack>(archive: &mut W, source: P) -> Result<()> process::exit(127); }; - let (pid, pipew) = unsafe { - ns::spawn(CloneFlags::CLONE_NEWNS, pipew, |pipew| { - exec_tar(pipew).unwrap() - }) - } - .context("Failed to run tar")?; + let pid = unsafe { ns::spawn(CloneFlags::CLONE_NEWNS, (), |()| exec_tar().unwrap()) } + .context("Failed to run tar")? + .0; - drop(pipew); let result = io::copy(&mut piper, archive).context("Failed to write TAR archive"); wait::waitpid(pid, None)? -- cgit v1.2.3