Skip to content

Commit 07e6c2f

Browse files
committed
Merge #681
681: Remove feature flags r=Susurrus These are vestiges of the initial push to get this working on Rust 1.0. These feature flags are undocumented and so hard to discover (only learned about them today!), prevent functions being included that should be and this also affects documentation on docs.rs, and none of the features are tested in CI and the `execvpe` has been broken for forever. The solution is to conditionally compile everything supported for a given platform and do away completely with the feature flags. The `execvpe` function is completely removed as it's not available for *nix platforms in libc and is already broken, so no loss removing it. We'll add it back once it's back in libc (rust-lang/libc#670). Closes #98. Closes #206. Closes #306. Closes #308.
2 parents 3d24ae9 + bee13c8 commit 07e6c2f

14 files changed

+49
-92
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4646
Also file system type constants like `nix::sys::statfs::ADFS_SUPER_MAGIC` were removed in favor of the libc equivalent.
4747
([#561](https://github.com/nix-rust/nix/pull/561))
4848
- Revised the termios API including additional tests and documentation and exposed it on iOS. ([#527](https://github.com/nix-rust/nix/pull/527))
49+
- `eventfd`, `signalfd`, and `pwritev`/`preadv` functionality is now included by default for all
50+
supported platforms. ([#681](https://github.com/nix-rust/nix/pull/561))
4951

5052
### Removed
5153
- Removed `io::Error` from `nix::Error` and the conversion from `nix::Error` to `Errno`
5254
([#614](https://github.com/nix-rust/nix/pull/614))
55+
- All feature flags have been removed in favor of conditional compilation on supported platforms.
56+
`execvpe` is no longer supported, but this was already broken and will be added back in the next
57+
release. ([#681](https://github.com/nix-rust/nix/pull/561))
5358

5459
### Fixed
5560
- Fixed multiple issues compiling under different archetectures and OSes.

Cargo.toml

-12
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ exclude = [
1515
"test/**/*"
1616
]
1717

18-
[features]
19-
eventfd = []
20-
execvpe = []
21-
preadv_pwritev = []
22-
signalfd = []
23-
2418
[dependencies]
2519
libc = "0.2.25"
2620
bitflags = "0.9"
@@ -38,12 +32,6 @@ nix-test = { path = "nix-test", version = "0.0.1" }
3832
name = "test"
3933
path = "test/test.rs"
4034

41-
[[test]]
42-
name = "test-signalfd"
43-
path = "test/test_signalfd.rs"
44-
harness = false
45-
test = true
46-
4735
[[test]]
4836
name = "test-mount"
4937
path = "test/test_mount.rs"

src/sys/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ pub mod epoll;
99
target_os = "dragonfly", target_os = "openbsd", target_os = "netbsd"))]
1010
pub mod event;
1111

12-
// TODO: switch from feature flags to conditional builds
13-
#[cfg(feature = "eventfd")]
12+
#[cfg(target_os = "linux")]
1413
pub mod eventfd;
1514

1615
#[cfg(target_os = "linux")]
@@ -24,8 +23,8 @@ pub mod sendfile;
2423

2524
pub mod signal;
2625

27-
#[cfg(any(target_os = "linux", target_os = "android"))]
28-
#[cfg(feature = "signalfd")]
26+
// FIXME: Add to Android once libc#671 lands in a release
27+
#[cfg(target_os = "linux")]
2928
pub mod signalfd;
3029

3130
pub mod socket;

src/sys/signalfd.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,10 @@ pub fn signalfd(fd: RawFd, mask: &SigSet, flags: SfdFlags) -> Result<RawFd> {
6060
/// # Examples
6161
///
6262
/// ```
63-
/// use nix::sys::signalfd::*;
64-
///
63+
/// # use nix::sys::signalfd::*;
64+
/// // Set the thread to block the SIGUSR1 signal, otherwise the default handler will be used
6565
/// let mut mask = SigSet::empty();
66-
/// mask.add(signal::SIGUSR1).unwrap();
67-
///
68-
/// // Block the signal, otherwise the default handler will be invoked instead.
66+
/// mask.add(signal::SIGUSR1);
6967
/// mask.thread_block().unwrap();
7068
///
7169
/// // Signals are queued up on the file descriptor
@@ -74,11 +72,9 @@ pub fn signalfd(fd: RawFd, mask: &SigSet, flags: SfdFlags) -> Result<RawFd> {
7472
/// match sfd.read_signal() {
7573
/// // we caught a signal
7674
/// Ok(Some(sig)) => (),
77-
///
7875
/// // there were no signals waiting (only happens when the SFD_NONBLOCK flag is set,
7976
/// // otherwise the read_signal call blocks)
8077
/// Ok(None) => (),
81-
///
8278
/// Err(err) => (), // some error happend
8379
/// }
8480
/// ```

src/sys/uio.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn readv(fd: RawFd, iov: &mut [IoVec<&mut [u8]>]) -> Result<usize> {
1818
Errno::result(res).map(|r| r as usize)
1919
}
2020

21-
#[cfg(feature = "preadv_pwritev")]
21+
#[cfg(target_os = "linux")]
2222
pub fn pwritev(fd: RawFd, iov: &[IoVec<&[u8]>],
2323
offset: off_t) -> Result<usize> {
2424
let res = unsafe {
@@ -28,7 +28,7 @@ pub fn pwritev(fd: RawFd, iov: &[IoVec<&[u8]>],
2828
Errno::result(res).map(|r| r as usize)
2929
}
3030

31-
#[cfg(feature = "preadv_pwritev")]
31+
#[cfg(target_os = "linux")]
3232
pub fn preadv(fd: RawFd, iov: &mut [IoVec<&mut [u8]>],
3333
offset: off_t) -> Result<usize> {
3434
let res = unsafe {
@@ -57,7 +57,7 @@ pub fn pread(fd: RawFd, buf: &mut [u8], offset: off_t) -> Result<usize>{
5757
}
5858

5959
#[repr(C)]
60-
pub struct IoVec<T>(libc::iovec, PhantomData<T>);
60+
pub struct IoVec<T>(libc::iovec, PhantomData<T>);
6161

6262
impl<T> IoVec<T> {
6363
#[inline]

src/unistd.rs

-22
Original file line numberDiff line numberDiff line change
@@ -1596,9 +1596,6 @@ mod linux {
15961596
use {Errno, Result, NixPath};
15971597
use super::{Uid, Gid};
15981598

1599-
#[cfg(feature = "execvpe")]
1600-
use std::ffi::CString;
1601-
16021599
pub fn pivot_root<P1: ?Sized + NixPath, P2: ?Sized + NixPath>(
16031600
new_root: &P1, put_old: &P2) -> Result<()> {
16041601
let res = try!(try!(new_root.with_nix_path(|new_root| {
@@ -1643,23 +1640,4 @@ mod linux {
16431640

16441641
Errno::result(res).map(drop)
16451642
}
1646-
1647-
#[inline]
1648-
#[cfg(feature = "execvpe")]
1649-
pub fn execvpe(filename: &CString, args: &[CString], env: &[CString]) -> Result<()> {
1650-
use std::ptr;
1651-
use libc::c_char;
1652-
1653-
let mut args_p: Vec<*const c_char> = args.iter().map(|s| s.as_ptr()).collect();
1654-
args_p.push(ptr::null());
1655-
1656-
let mut env_p: Vec<*const c_char> = env.iter().map(|s| s.as_ptr()).collect();
1657-
env_p.push(ptr::null());
1658-
1659-
unsafe {
1660-
super::ffi::execvpe(filename.as_ptr(), args_p.as_ptr(), env_p.as_ptr())
1661-
};
1662-
1663-
Err(Error::Sys(Errno::last()))
1664-
}
16651643
}

test/sys/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ mod test_signal;
22
#[cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "ios",
33
target_os = "netbsd", target_os = "macos", target_os = "linux"))]
44
mod test_aio;
5+
#[cfg(target_os = "linux")]
6+
mod test_signalfd;
57
mod test_socket;
68
mod test_sockopt;
79
mod test_termios;

test/sys/test_aio.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ extern fn sigfunc(_: c_int) {
244244
#[cfg_attr(any(all(target_env = "musl", target_arch = "x86_64"), target_arch = "mips"), ignore)]
245245
fn test_write_sigev_signal() {
246246
#[allow(unused_variables)]
247-
let m = ::SIGUSR2_MTX.lock().expect("Mutex got poisoned by another test");
247+
let m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
248248
let sa = SigAction::new(SigHandler::Handler(sigfunc),
249249
SA_RESETHAND,
250250
SigSet::empty());
@@ -375,7 +375,7 @@ fn test_lio_listio_nowait() {
375375
#[cfg_attr(any(target_arch = "mips", target_env = "musl"), ignore)]
376376
fn test_lio_listio_signal() {
377377
#[allow(unused_variables)]
378-
let m = ::SIGUSR2_MTX.lock().expect("Mutex got poisoned by another test");
378+
let m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
379379
const INITIAL: &'static [u8] = b"abcdef123456";
380380
const WBUF: &'static [u8] = b"CDEF";
381381
let rbuf = Rc::new(vec![0; 4].into_boxed_slice());

test/sys/test_signalfd.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#[test]
2+
fn test_signalfd() {
3+
use nix::sys::signalfd::SignalFd;
4+
use nix::sys::signal::{self, raise, Signal, SigSet};
5+
6+
// Grab the mutex for altering signals so we don't interfere with other tests.
7+
#[allow(unused_variables)]
8+
let m = ::SIGNAL_MTX.lock().expect("Mutex got poisoned by another test");
9+
10+
// Block the SIGUSR1 signal from automatic processing for this thread
11+
let mut mask = SigSet::empty();
12+
mask.add(signal::SIGUSR1);
13+
mask.thread_block().unwrap();
14+
15+
let mut fd = SignalFd::new(&mask).unwrap();
16+
17+
// Send a SIGUSR1 signal to the current process. Note that this uses `raise` instead of `kill`
18+
// because `kill` with `getpid` isn't correct during multi-threaded execution like during a
19+
// cargo test session. Instead use `raise` which does the correct thing by default.
20+
raise(signal::SIGUSR1).ok().expect("Error: raise(SIGUSR1) failed");
21+
22+
// And now catch that same signal.
23+
let res = fd.read_signal().unwrap().unwrap();
24+
let signo = Signal::from_c_int(res.ssi_signo as i32).unwrap();
25+
assert_eq!(signo, signal::SIGUSR1);
26+
}

test/sys/test_uio.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn test_pread() {
129129
}
130130

131131
#[test]
132-
#[cfg(feature = "preadv_pwritev")]
132+
#[cfg(target_os = "linux")]
133133
fn test_pwritev() {
134134
use std::io::Read;
135135

@@ -159,7 +159,7 @@ fn test_pwritev() {
159159
}
160160

161161
#[test]
162-
#[cfg(feature = "preadv_pwritev")]
162+
#[cfg(target_os = "linux")]
163163
fn test_preadv() {
164164
use std::io::Write;
165165

test/test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern crate nix_test as nixtest;
1111

1212
mod sys;
1313
mod test_fcntl;
14-
#[cfg(any(target_os = "linux"))]
14+
#[cfg(target_os = "linux")]
1515
mod test_mq;
1616
mod test_net;
1717
mod test_nix_path;
@@ -45,8 +45,8 @@ lazy_static! {
4545
/// Any test that creates child processes must grab this mutex, regardless
4646
/// of what it does with those children.
4747
pub static ref FORK_MTX: Mutex<()> = Mutex::new(());
48-
/// Any test that registers a SIGUSR2 handler must grab this mutex
49-
pub static ref SIGUSR2_MTX: Mutex<()> = Mutex::new(());
48+
/// Any test that alters signal handling must grab this mutex.
49+
pub static ref SIGNAL_MTX: Mutex<()> = Mutex::new(());
5050
}
5151

5252
#[test]

test/test_mq.rs

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ use std::ffi::CString;
88
use std::str;
99
use libc::c_long;
1010

11-
use nix::unistd::{fork, read, write, pipe};
12-
use nix::unistd::ForkResult::*;
13-
use nix::sys::wait::*;
1411
use nix::errno::Errno::*;
1512
use nix::Error::Sys;
1613

test/test_signalfd.rs

-30
This file was deleted.

test/test_unistd.rs

-4
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,6 @@ fn test_lseek64() {
227227

228228
execve_test_factory!(test_execve, execve, b"/bin/sh", b"/system/bin/sh");
229229

230-
#[cfg(any(target_os = "linux", target_os = "android"))]
231-
#[cfg(feature = "execvpe")]
232-
execve_test_factory!(test_execvpe, execvpe, b"sh", b"sh");
233-
234230
#[test]
235231
fn test_fpathconf_limited() {
236232
let f = tempfile().unwrap();

0 commit comments

Comments
 (0)