From 129485cfa3455b7eda3217e36ee89d4ca75d38b2 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 26 May 2019 18:20:04 -0600 Subject: Fix multiple problems with the test_acct test * On Linux, it requires the CAP_SYS_PACCT capability. * Reenable the test on FreeBSD, because our FreeBSD CI environment is no longer jailed (since we switched from BuildBot to CirrusCI), but check at runtime whether the process is jailed. * test_acct needs the FORK_MTX because it uses Command::new . * Fix a race condition. acct(2) isn't synchronous. It starts a kernel thread but does not wait for it to become ready. Fix it by running the test command within the polling loop. --- test/test.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'test/test.rs') diff --git a/test/test.rs b/test/test.rs index 0a3d3b74..c8b8717f 100644 --- a/test/test.rs +++ b/test/test.rs @@ -9,6 +9,8 @@ extern crate nix; extern crate lazy_static; extern crate libc; extern crate rand; +#[cfg(target_os = "freebsd")] +extern crate sysctl; extern crate tempfile; #[cfg(any(target_os = "android", target_os = "linux"))] @@ -27,14 +29,31 @@ macro_rules! require_capability { } } +#[cfg(target_os = "freebsd")] +macro_rules! skip_if_jailed { + ($name:expr) => { + use ::sysctl::CtlValue; + + if let CtlValue::Int(1) = ::sysctl::value("security.jail.jailed") + .unwrap() + { + use ::std::io::Write; + let stderr = ::std::io::stderr(); + let mut handle = stderr.lock(); + writeln!(handle, "{} cannot run in a jail. Skipping test.", $name) + .unwrap(); + return; + } + } +} + macro_rules! skip_if_not_root { ($name:expr) => { use nix::unistd::Uid; - use std; - use std::io::Write; if !Uid::current().is_root() { - let stderr = std::io::stderr(); + use ::std::io::Write; + let stderr = ::std::io::stderr(); let mut handle = stderr.lock(); writeln!(handle, "{} requires root privileges. Skipping test.", $name).unwrap(); return; -- cgit v1.2.3