diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/test.rs | 25 | ||||
-rw-r--r-- | test/test_unistd.rs | 34 |
2 files changed, 50 insertions, 9 deletions
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; diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 3f13883c..73ed845e 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -387,28 +387,50 @@ fn test_lseek64() { close(tmpfd).unwrap(); } -// Skip on FreeBSD because FreeBSD's CI environment is jailed, and jails -// aren't allowed to use acct(2) -#[cfg(not(target_os = "freebsd"))] +cfg_if!{ + if #[cfg(any(target_os = "android", target_os = "linux"))] { + macro_rules! require_acct{ + () => { + require_capability!(CAP_SYS_PACCT); + } + } + } else if #[cfg(target_os = "freebsd")] { + macro_rules! require_acct{ + () => { + skip_if_not_root!("test_acct"); + skip_if_jailed!("test_acct"); + } + } + } else { + macro_rules! require_acct{ + () => { + skip_if_not_root!("test_acct"); + } + } + } +} + #[test] fn test_acct() { use tempfile::NamedTempFile; use std::process::Command; use std::{thread, time}; - skip_if_not_root!("test_acct"); + let _m = ::FORK_MTX.lock().expect("Mutex got poisoned by another test"); + require_acct!(); + let file = NamedTempFile::new().unwrap(); let path = file.path().to_str().unwrap(); acct::enable(path).unwrap(); - Command::new("echo").arg("Hello world"); - acct::disable().unwrap(); loop { + Command::new("echo").arg("Hello world"); let len = fs::metadata(path).unwrap().len(); if len > 0 { break; } thread::sleep(time::Duration::from_millis(10)); } + acct::disable().unwrap(); } #[test] |