Skip to content

Commit

Permalink
test: Grab FORK_MTX when unmounting or forking in the mount tests (#2386
Browse files Browse the repository at this point in the history
)

* mount tests: take FORK_MTX when forking or unmounting

unmounting can fail if a child process inherited a file a file descriptor
we opened in temporary mount point

Should fix #2369

* tests: clarify the meaning of the FORK_MTX

* tests: clarify the meaning of FORK_MTX

Co-authored-by: SteveLauC <stevelauc@outlook.com>

* here no one accesses the file system to be unmounted, so no fork lock needed

---------

Co-authored-by: SteveLauC <stevelauc@outlook.com>
  • Loading branch information
TheJonny and SteveLauC committed Apr 24, 2024
1 parent e046897 commit 395906e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions test/mount/test_mount.rs
Expand Up @@ -53,6 +53,8 @@ fn test_mount_tmpfs_without_flags_allows_rwx() {
.unwrap_or_else(|e| panic!("read failed: {e}"));
assert_eq!(buf, SCRIPT_CONTENTS);

// while forking and unmounting prevent other child processes
let _m = FORK_MTX.lock();
// Verify execute.
assert_eq!(
EXPECTED_STATUS,
Expand Down Expand Up @@ -129,6 +131,8 @@ fn test_mount_noexec_disallows_exec() {
&test_path
);

// while forking and unmounting prevent other child processes
let _m = FORK_MTX.lock();
// EACCES: Permission denied
assert_eq!(
EACCES,
Expand Down Expand Up @@ -168,6 +172,8 @@ fn test_mount_bind() {
.and_then(|mut f| f.write(SCRIPT_CONTENTS))
.unwrap_or_else(|e| panic!("write failed: {e}"));

// wait for child processes to prevent EBUSY
let _m = FORK_MTX.lock();
umount(mount_point.path())
.unwrap_or_else(|e| panic!("umount failed: {e}"));
}
Expand Down
5 changes: 3 additions & 2 deletions test/test.rs
Expand Up @@ -57,8 +57,9 @@ fn read_exact<Fd: AsFd>(f: Fd, buf: &mut [u8]) {
}
}

/// Any test that creates child processes must grab this mutex, regardless
/// of what it does with those children.
/// Any test that creates child processes or can be affected by child processes must grab this mutex, regardless
/// of what it does with those children. It must hold the mutex until the
/// child processes are waited upon.
pub static FORK_MTX: Mutex<()> = Mutex::new(());
/// Any test that changes the process's current working directory must grab
/// the RwLock exclusively. Any process that cares about the current
Expand Down

0 comments on commit 395906e

Please sign in to comment.