Skip to content

Commit 395906e

Browse files
TheJonnySteveLauC
andauthored
test: Grab FORK_MTX when unmounting or forking in the mount tests (#2386)
* 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>
1 parent e046897 commit 395906e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

test/mount/test_mount.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ fn test_mount_tmpfs_without_flags_allows_rwx() {
5353
.unwrap_or_else(|e| panic!("read failed: {e}"));
5454
assert_eq!(buf, SCRIPT_CONTENTS);
5555

56+
// while forking and unmounting prevent other child processes
57+
let _m = FORK_MTX.lock();
5658
// Verify execute.
5759
assert_eq!(
5860
EXPECTED_STATUS,
@@ -129,6 +131,8 @@ fn test_mount_noexec_disallows_exec() {
129131
&test_path
130132
);
131133

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

175+
// wait for child processes to prevent EBUSY
176+
let _m = FORK_MTX.lock();
171177
umount(mount_point.path())
172178
.unwrap_or_else(|e| panic!("umount failed: {e}"));
173179
}

test/test.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ fn read_exact<Fd: AsFd>(f: Fd, buf: &mut [u8]) {
5757
}
5858
}
5959

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

0 commit comments

Comments
 (0)