diff --git a/test/test.rs b/test/test.rs index 1b73c4ffa4..f4942d3dc1 100644 --- a/test/test.rs +++ b/test/test.rs @@ -43,6 +43,9 @@ lazy_static! { /// Any test that changes the process's current working directory must grab /// this mutex pub static ref CWD_MTX: Mutex<()> = Mutex::new(()); + /// Any test that changes the process's supplementary groups must grab this + /// mutex + pub static ref GROUPS_MTX: Mutex<()> = Mutex::new(()); /// Any test that creates child processes must grab this mutex, regardless /// of what it does with those children. pub static ref FORK_MTX: Mutex<()> = Mutex::new(()); diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 3551e24a10..a1f14def0c 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -110,9 +110,16 @@ mod linux_android { fn test_setgroups() { // Skip this test when not run as root as `setgroups()` requires root. if !Uid::current().is_root() { + use std::io; + let stderr = io::stderr(); + let mut handle = stderr.lock(); + writeln!(handle, "test_setgroups requires root privileges. Skipping test.").unwrap(); return } + #[allow(unused_variables)] + let m = ::GROUPS_MTX.lock().expect("Mutex got poisoned by another test"); + // Save the existing groups let old_groups = getgroups().unwrap(); @@ -134,9 +141,16 @@ fn test_initgroups() { // Skip this test when not run as root as `initgroups()` and `setgroups()` // require root. if !Uid::current().is_root() { + use std::io; + let stderr = io::stderr(); + let mut handle = stderr.lock(); + writeln!(handle, "test_initgroups requires root privileges. Skipping test.").unwrap(); return } + #[allow(unused_variables)] + let m = ::GROUPS_MUTEX.lock().expect("Mutex got poisoned by another test"); + // Save the existing groups let old_groups = getgroups().unwrap();