diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2021-10-27 00:26:12 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2021-10-27 00:44:28 +0200 |
commit | 6b81db6b8d42445db25ebe095f3233816c29e0d5 (patch) | |
tree | 33a1771292469248bca8e288d9da5d03018d9a64 | |
parent | 95b557b7f3b54a4685660d281bf5fc9b1fba2f70 (diff) | |
download | rebel-6b81db6b8d42445db25ebe095f3233816c29e0d5.tar rebel-6b81db6b8d42445db25ebe095f3233816c29e0d5.zip |
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.
-rw-r--r-- | crates/runner/src/tar.rs | 15 |
1 files 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<W: Write, P: AsRef<Path>>(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<W: Write, P: AsRef<Path>>(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<W: Write, P: AsRef<Path>>(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)? |