Skip to content

Commit 4f6f119

Browse files
committed
Skip test_acct on FreeBSD if jailed.
1 parent 8d88f12 commit 4f6f119

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

test/test.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ extern crate nix;
99
extern crate lazy_static;
1010
extern crate libc;
1111
extern crate rand;
12+
#[cfg(target_os = "freebsd")]
13+
extern crate sysctl;
1214
extern crate tempfile;
1315

1416
#[cfg(any(target_os = "android", target_os = "linux"))]
@@ -27,13 +29,30 @@ macro_rules! require_capability {
2729
}
2830
}
2931

32+
#[cfg(target_os = "freebsd")]
33+
macro_rules! skip_if_jailed {
34+
($name:expr) => {
35+
use sysctl::CtlValue;
36+
37+
if let CtlValue::Int(1) = sysctl::value("security.jail.jailed")
38+
.unwrap()
39+
{
40+
use std::io::Write;
41+
let stderr = std::io::stderr();
42+
let mut handle = stderr.lock();
43+
writeln!(handle, "{} cannot run in a jail. Skipping test.", $name)
44+
.unwrap();
45+
return;
46+
}
47+
}
48+
}
49+
3050
macro_rules! skip_if_not_root {
3151
($name:expr) => {
3252
use nix::unistd::Uid;
33-
use std;
34-
use std::io::Write;
3553

3654
if !Uid::current().is_root() {
55+
use std::io::Write;
3756
let stderr = std::io::stderr();
3857
let mut handle = stderr.lock();
3958
writeln!(handle, "{} requires root privileges. Skipping test.", $name).unwrap();

test/test_unistd.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,13 @@ cfg_if!{
394394
require_capability!(CAP_SYS_PACCT);
395395
}
396396
}
397+
} else if #[cfg(target_os = "freebsd")] {
398+
macro_rules! require_acct{
399+
() => {
400+
skip_if_not_root!("test_acct");
401+
skip_if_jailed!("test_acct");
402+
}
403+
}
397404
} else {
398405
macro_rules! require_acct{
399406
() => {

0 commit comments

Comments
 (0)