diff --git a/fuc_engine/src/ops/copy.rs b/fuc_engine/src/ops/copy.rs index 82f4141..7a96825 100644 --- a/fuc_engine/src/ops/copy.rs +++ b/fuc_engine/src/ops/copy.rs @@ -142,6 +142,7 @@ mod compat { use std::{ borrow::Cow, cell::{Cell, LazyCell}, + env, ffi::{CStr, CString}, fmt::{Debug, Formatter}, fs::File, @@ -213,8 +214,17 @@ mod compat { } } + fn unshare_files() -> Result<(), Error> { + if env::var_os("NO_UNSHARE").is_none() { + unshare(UnshareFlags::FILES).map_io_err(|| "Failed to unshare FD table.")?; + } + Ok(()) + } + #[cfg_attr(feature = "tracing", tracing::instrument(level = "trace", skip(tasks)))] fn root_worker_thread(tasks: Receiver) -> Result<(), Error> { + unshare_files()?; + let mut available_parallelism = thread::available_parallelism() .map(NonZeroUsize::get) .unwrap_or(1) @@ -281,7 +291,7 @@ mod compat { #[cfg_attr(feature = "tracing", tracing::instrument(level = "trace", skip(tasks)))] fn worker_thread(tasks: Receiver, root_to_inode: u64) -> Result<(), Error> { - unshare(UnshareFlags::FILES).map_io_err(|| "Failed to unshare FD table.")?; + unshare_files()?; let mut buf = [MaybeUninit::::uninit(); 8192]; let symlink_buf_cache = Cell::new(Vec::new()); diff --git a/fuc_engine/src/ops/remove.rs b/fuc_engine/src/ops/remove.rs index feaf463..aaf80ca 100644 --- a/fuc_engine/src/ops/remove.rs +++ b/fuc_engine/src/ops/remove.rs @@ -117,6 +117,7 @@ mod compat { use std::{ borrow::Cow, cell::LazyCell, + env, env::{current_dir, set_current_dir}, ffi::{CStr, CString, OsStr}, fmt::{Debug, Formatter}, @@ -190,9 +191,17 @@ mod compat { } } + fn unshare_io() -> Result<(), Error> { + if env::var_os("NO_UNSHARE").is_none() { + unshare(UnshareFlags::FILES | UnshareFlags::FS) + .map_io_err(|| "Failed to unshare I/O.")?; + } + Ok(()) + } + #[cfg_attr(feature = "tracing", tracing::instrument(level = "trace", skip(tasks)))] fn root_worker_thread(tasks: Receiver) -> Result<(), Error> { - unshare(UnshareFlags::FILES | UnshareFlags::FS).map_io_err(|| "Failed to unshare I/O.")?; + unshare_io()?; let mut available_parallelism = thread::available_parallelism() .map(NonZeroUsize::get) @@ -236,7 +245,7 @@ mod compat { #[cfg_attr(feature = "tracing", tracing::instrument(level = "trace", skip(tasks)))] fn worker_thread(tasks: Receiver) -> Result<(), Error> { - unshare(UnshareFlags::FILES | UnshareFlags::FS).map_io_err(|| "Failed to unshare I/O.")?; + unshare_io()?; let mut buf = [MaybeUninit::::uninit(); 8192]; for message in tasks {