Skip to content

Commit bdca86b

Browse files
committed
Fix build and tests issues on OpenBSD 6.4+
1) lutimes doesn't exist on OpenBSD so it needs to be under conditional compilation. The only "reference" that I could find related to this is the discussion here: rust-lang/libc#790 . 2) fexecve doesn't exist on OpenBSD so add conditional compilation for it in unistd and in related tests. The only "reference" that I could find is a mention that fexecve is not implemented on OpenBSD in the manual pages for signal(3) and sigaction(2): Official repository (search for "fexecve"): https://cvsweb.openbsd.org/src/lib/libc/sys/sigaction.2?rev=1.75&content-type=text/x-cvsweb-markup Github mirror: https://github.com/openbsd/src/blob/master/lib/libc/sys/sigaction.2#L619 3) AIO doesn't work on OpenBSD so put test_aio_drop under conditional compilation. 4) Add relevant changelog entries. P.S. On OpenBSD remains the issue of test_scm_rights which builds correctly but fails at runtime.
1 parent 7bcd9d2 commit bdca86b

File tree

6 files changed

+48
-15
lines changed

6 files changed

+48
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2020

2121
### Changed
2222
### Fixed
23+
- `lutimes` never worked on OpenBSD as it is not implemented on OpenBSD. It has
24+
been removed. ([#1000](https://github.com/nix-rust/nix/pull/1000))
25+
- `fexecve` never worked on NetBSD or on OpenBSD as it is not implemented on
26+
either OS. It has been removed. ([#1000](https://github.com/nix-rust/nix/pull/1000))
27+
2328
### Removed
2429

2530
## [0.12.0] 2018-11-28

src/sys/stat.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,12 @@ pub fn utimes<P: ?Sized + NixPath>(path: &P, atime: &TimeVal, mtime: &TimeVal) -
209209
/// # References
210210
///
211211
/// [lutimes(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/lutimes.html).
212-
#[cfg(not(target_os = "android"))]
212+
#[cfg(any(target_os = "linux",
213+
target_os = "haiku",
214+
target_os = "ios",
215+
target_os = "macos",
216+
target_os = "freebsd",
217+
target_os = "netbsd"))]
213218
pub fn lutimes<P: ?Sized + NixPath>(path: &P, atime: &TimeVal, mtime: &TimeVal) -> Result<()> {
214219
let times: [libc::timeval; 2] = [*atime.as_ref(), *mtime.as_ref()];
215220
let res = path.with_nix_path(|cstr| unsafe {

src/unistd.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,11 +760,12 @@ pub fn execvpe(filename: &CString, args: &[CString], env: &[CString]) -> Result<
760760
///
761761
/// This function is similar to `execve`, except that the program to be executed
762762
/// is referenced as a file descriptor instead of a path.
763+
// Note for NetBSD and OpenBSD: although rust-lang/libc includes it (under
764+
// unix/bsd/netbsdlike/) fexecve is not currently implemented on NetBSD nor on
765+
// OpenBSD.
763766
#[cfg(any(target_os = "android",
764-
target_os = "freebsd",
765767
target_os = "linux",
766-
target_os = "netbsd",
767-
target_os = "openbsd"))]
768+
target_os = "freebsd"))]
768769
#[inline]
769770
pub fn fexecve(fd: RawFd, args: &[CString], env: &[CString]) -> Result<Void> {
770771
let args_p = to_exec_array(args);

test/sys/test_aio_drop.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
extern crate nix;
22
extern crate tempfile;
33

4-
use nix::sys::aio::*;
5-
use nix::sys::signal::*;
6-
use std::os::unix::io::AsRawFd;
7-
use tempfile::tempfile;
8-
94
// Test dropping an AioCb that hasn't yet finished.
105
// This must happen in its own process, because on OSX this test seems to hose
116
// the AIO subsystem and causes subsequent tests to fail
127
#[test]
138
#[should_panic(expected = "Dropped an in-progress AioCb")]
14-
#[cfg(not(target_env = "musl"))]
9+
#[cfg(all(not(target_env = "musl"),
10+
any(target_os = "linux",
11+
target_os = "ios",
12+
target_os = "macos",
13+
target_os = "freebsd",
14+
target_os = "netbsd")))]
1515
fn test_drop() {
16+
use nix::sys::aio::*;
17+
use nix::sys::signal::*;
18+
use std::os::unix::io::AsRawFd;
19+
use tempfile::tempfile;
20+
1621
const WBUF: &[u8] = b"CDEF";
1722

1823
let f = tempfile().unwrap();

test/test_stat.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ use std::time::{Duration, UNIX_EPOCH};
77
use libc::{S_IFMT, S_IFLNK};
88

99
use nix::fcntl;
10-
use nix::sys::stat::{self, fchmod, fchmodat, futimens, lutimes, stat, utimes, utimensat};
10+
use nix::sys::stat::{self, fchmod, fchmodat, futimens, stat, utimes, utimensat};
11+
#[cfg(any(target_os = "linux",
12+
target_os = "haiku",
13+
target_os = "ios",
14+
target_os = "macos",
15+
target_os = "freebsd",
16+
target_os = "netbsd"))]
17+
use nix::sys::stat::lutimes;
1118
use nix::sys::stat::{Mode, FchmodatFlags, UtimensatFlags};
1219

1320
#[cfg(not(any(target_os = "netbsd")))]
@@ -196,6 +203,12 @@ fn test_utimes() {
196203
}
197204

198205
#[test]
206+
#[cfg(any(target_os = "linux",
207+
target_os = "haiku",
208+
target_os = "ios",
209+
target_os = "macos",
210+
target_os = "freebsd",
211+
target_os = "netbsd"))]
199212
fn test_lutimes() {
200213
let tempdir = tempfile::tempdir().unwrap();
201214
let target = tempdir.path().join("target");

test/test_unistd.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,20 @@ cfg_if!{
230230
execve_test_factory!(test_execve, execve, &CString::new("/system/bin/sh").unwrap());
231231
execve_test_factory!(test_fexecve, fexecve, File::open("/system/bin/sh").unwrap().into_raw_fd());
232232
} else if #[cfg(any(target_os = "freebsd",
233-
target_os = "linux",
234-
target_os = "openbsd"))] {
233+
target_os = "linux"))] {
235234
execve_test_factory!(test_execve, execve, &CString::new("/bin/sh").unwrap());
236235
execve_test_factory!(test_fexecve, fexecve, File::open("/bin/sh").unwrap().into_raw_fd());
237236
} else if #[cfg(any(target_os = "dragonfly",
238237
target_os = "ios",
239238
target_os = "macos",
240-
target_os = "netbsd"))] {
239+
target_os = "netbsd",
240+
target_os = "openbsd"))] {
241241
execve_test_factory!(test_execve, execve, &CString::new("/bin/sh").unwrap());
242-
// No fexecve() on DragonFly, ios, macos, and NetBSD.
242+
// No fexecve() on DragonFly, ios, macos, NetBSD, OpenBSD.
243+
//
244+
// Note for NetBSD and OpenBSD: although rust-lang/libc includes it
245+
// (under unix/bsd/netbsdlike/) fexecve is not currently implemented on
246+
// NetBSD nor on OpenBSD.
243247
}
244248
}
245249

0 commit comments

Comments
 (0)