diff --git a/rust/src/bwrap.rs b/rust/src/bwrap.rs index a39e7524c1..fb9f4224eb 100644 --- a/rust/src/bwrap.rs +++ b/rust/src/bwrap.rs @@ -15,6 +15,8 @@ use std::os::unix::io::AsRawFd; use std::os::unix::process::CommandExt; use std::path::Path; use std::process::Command; +use camino::Utf8Path; +use camino::Utf8PathBuf; // Links in the rootfs to /usr static USR_LINKS: &[&str] = &["lib", "lib32", "lib64", "bin", "sbin"]; @@ -114,6 +116,20 @@ impl RoFilesMount { } } +fn get_fusermount_path() -> Result { + let path = std::env::var("PATH").expect("PATH set"); + let fusermount_binaries = ["fusermount", "fusermount3"]; + for elt in path.split(':').map(Utf8Path::new) { + for bin in fusermount_binaries { + let target = elt.join(bin); + if target.try_exists()? { + return Ok(target); + } + } + } + anyhow::bail!("No fusermount path found") +} + impl Drop for RoFilesMount { fn drop(&mut self) { let tempdir = if let Some(d) = self.tempdir.take() { @@ -122,7 +138,7 @@ impl Drop for RoFilesMount { return; }; // We need to unmount before letting the tempdir cleanup run. - let success = Command::new("fusermount") + let success = Command::new(get_fusermount_path().unwrap().to_string()) .arg("-u") .arg(tempdir.path()) .status()