forked from containers/bootc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We'll use this even in cases where we don't have the `install` feature. Signed-off-by: Colin Walters <[email protected]>
- Loading branch information
Showing
6 changed files
with
43 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//! Run a command in the host mount namespace | ||
use std::os::fd::AsFd; | ||
use std::os::unix::process::CommandExt; | ||
use std::process::Command; | ||
|
||
use anyhow::{Context, Result}; | ||
use camino::Utf8Path; | ||
use fn_error_context::context; | ||
|
||
/// 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 | ||
} | ||
|
||
#[context("Re-exec in host mountns")] | ||
pub(crate) fn exec_in_host_mountns(args: &[std::ffi::OsString]) -> Result<()> { | ||
let (cmd, args) = args | ||
.split_first() | ||
.ok_or_else(|| anyhow::anyhow!("Missing command"))?; | ||
tracing::trace!("{cmd:?} {args:?}"); | ||
let pid1mountns = std::fs::File::open("/proc/1/ns/mnt").context("open pid1 mountns")?; | ||
nix::sched::setns(pid1mountns.as_fd(), nix::sched::CloneFlags::CLONE_NEWNS).context("setns")?; | ||
rustix::process::chdir("/").context("chdir")?; | ||
// Work around supermin doing chroot() and not pivot_root | ||
// https://github.com/libguestfs/supermin/blob/5230e2c3cd07e82bd6431e871e239f7056bf25ad/init/init.c#L288 | ||
if !Utf8Path::new("/usr").try_exists().context("/usr")? | ||
&& Utf8Path::new("/root/usr") | ||
.try_exists() | ||
.context("/root/usr")? | ||
{ | ||
tracing::debug!("Using supermin workaround"); | ||
rustix::process::chroot("/root").context("chroot")?; | ||
} | ||
Err(Command::new(cmd).args(args).exec()).context("exec")? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters