Skip to content

Commit

Permalink
Add NO_UNSHARE envvar support to avoid calling unshare for default do…
Browse files Browse the repository at this point in the history
…cker configs which block the syscall (closes #34)

Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX committed Jun 27, 2024
1 parent 966528a commit ef296f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
12 changes: 11 additions & 1 deletion fuc_engine/src/ops/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ mod compat {
use std::{
borrow::Cow,
cell::{Cell, LazyCell},
env,
ffi::{CStr, CString},
fmt::{Debug, Formatter},
fs::File,
Expand Down Expand Up @@ -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<TreeNode>) -> Result<(), Error> {
unshare_files()?;

let mut available_parallelism = thread::available_parallelism()
.map(NonZeroUsize::get)
.unwrap_or(1)
Expand Down Expand Up @@ -281,7 +291,7 @@ mod compat {

#[cfg_attr(feature = "tracing", tracing::instrument(level = "trace", skip(tasks)))]
fn worker_thread(tasks: Receiver<TreeNode>, root_to_inode: u64) -> Result<(), Error> {
unshare(UnshareFlags::FILES).map_io_err(|| "Failed to unshare FD table.")?;
unshare_files()?;

let mut buf = [MaybeUninit::<u8>::uninit(); 8192];
let symlink_buf_cache = Cell::new(Vec::new());
Expand Down
13 changes: 11 additions & 2 deletions fuc_engine/src/ops/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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<TreeNode>) -> 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)
Expand Down Expand Up @@ -236,7 +245,7 @@ mod compat {

#[cfg_attr(feature = "tracing", tracing::instrument(level = "trace", skip(tasks)))]
fn worker_thread(tasks: Receiver<TreeNode>) -> Result<(), Error> {
unshare(UnshareFlags::FILES | UnshareFlags::FS).map_io_err(|| "Failed to unshare I/O.")?;
unshare_io()?;

let mut buf = [MaybeUninit::<u8>::uninit(); 8192];
for message in tasks {
Expand Down

0 comments on commit ef296f1

Please sign in to comment.