From 62e186d51dc564c8c93634f3b32bab021e32815b Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 6 Dec 2024 16:22:54 -0500 Subject: [PATCH] utils: Add a lifecycle_bind helper for Command Followup to the previous code where we'd end up forking a copy of our own binary in the deploy path, but also preparation for more similar code. Signed-off-by: Colin Walters --- Cargo.lock | 1 + lib/src/install.rs | 3 ++- lib/src/utils.rs | 2 ++ ostree-ext/Cargo.toml | 1 + ostree-ext/src/container/deploy.rs | 2 ++ 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index df927d65d..54a998ab4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1418,6 +1418,7 @@ name = "ostree-ext" version = "0.15.3" dependencies = [ "anyhow", + "bootc-utils", "camino", "cap-std-ext", "chrono", diff --git a/lib/src/install.rs b/lib/src/install.rs index 368794ef0..8587be138 100644 --- a/lib/src/install.rs +++ b/lib/src/install.rs @@ -840,7 +840,8 @@ async fn install_container( /// Run a command in the host mount namespace pub(crate) fn run_in_host_mountns(cmd: &str) -> Command { let mut c = Command::new("/proc/self/exe"); - c.args(["exec-in-host-mount-namespace", cmd]); + c.lifecycle_bind() + .args(["exec-in-host-mount-namespace", cmd]); c } diff --git a/lib/src/utils.rs b/lib/src/utils.rs index 5d0a27c76..e8a3481d2 100644 --- a/lib/src/utils.rs +++ b/lib/src/utils.rs @@ -5,6 +5,7 @@ use std::process::Command; use std::time::Duration; use anyhow::{Context, Result}; +use bootc_utils::CommandRunExt; #[cfg(feature = "install")] use camino::Utf8Path; use cap_std_ext::cap_std::fs::Dir; @@ -119,6 +120,7 @@ pub(crate) fn spawn_editor(tmpf: &tempfile::NamedTempFile) -> Result<()> { let status = Command::new(argv0) .args(editor_args) .arg(tmpf.path()) + .lifecycle_bind() .status() .context("Spawning editor")?; if !status.success() { diff --git a/ostree-ext/Cargo.toml b/ostree-ext/Cargo.toml index 51ff650cb..f330b1de7 100644 --- a/ostree-ext/Cargo.toml +++ b/ostree-ext/Cargo.toml @@ -19,6 +19,7 @@ ostree = { features = ["v2022_6"], version = "0.19.0" } # Private dependencies anyhow = { workspace = true } +bootc-utils = { path = "../utils" } camino = { workspace = true, features = ["serde1"] } chrono = { workspace = true } olpc-cjson = "0.1.1" diff --git a/ostree-ext/src/container/deploy.rs b/ostree-ext/src/container/deploy.rs index 09627cedf..dd5a4cad7 100644 --- a/ostree-ext/src/container/deploy.rs +++ b/ostree-ext/src/container/deploy.rs @@ -5,6 +5,7 @@ use std::os::fd::BorrowedFd; use std::process::Command; use anyhow::Result; +use bootc_utils::CommandRunExt; use cap_std_ext::cmdext::CapStdExtCommandExt; use fn_error_context::context; use ocidir::cap_std::fs::Dir; @@ -148,6 +149,7 @@ pub async fn deploy( let st = Command::new("/proc/self/exe") .args(["internals", "bootc-install-completion", ".", stateroot]) .cwd_dir(sysroot_dir.try_clone()?) + .lifecycle_bind() .status()?; if !st.success() { anyhow::bail!("Failed to complete bootc install");