Skip to content

Commit

Permalink
Merge pull request #411 from jeckersb/host-mountns-context
Browse files Browse the repository at this point in the history
Add more failure contexts for exec_in_host_mountns
  • Loading branch information
cgwalters committed Mar 21, 2024
2 parents e01a518 + 9f3c0e9 commit 74fbfa3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,12 +704,16 @@ pub(crate) fn exec_in_host_mountns(args: &[std::ffi::OsString]) -> Result<()> {
.split_first()
.ok_or_else(|| anyhow::anyhow!("Missing command"))?;
tracing::trace!("{cmd:?} {args:?}");
let pid1mountns = std::fs::File::open("/proc/1/ns/mnt")?;
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()? && Utf8Path::new("/root/usr").try_exists()? {
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")?;
}
Expand Down

0 comments on commit 74fbfa3

Please sign in to comment.