Skip to content

Commit b3b221e

Browse files
committed
Remove signalfd feature in favor of conditional compilation
Note that this is now only available for Linux as support is missing in libc for Android (see rust-lang/libc#671).
1 parent d3e6934 commit b3b221e

File tree

7 files changed

+60
-47
lines changed

7 files changed

+60
-47
lines changed

Cargo.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ exclude = [
1717

1818
[features]
1919
execvpe = []
20-
signalfd = []
2120

2221
[dependencies]
2322
libc = "0.2.25"
@@ -36,12 +35,6 @@ nix-test = { path = "nix-test", version = "0.0.1" }
3635
name = "test"
3736
path = "test/test.rs"
3837

39-
[[test]]
40-
name = "test-signalfd"
41-
path = "test/test_signalfd.rs"
42-
harness = false
43-
test = true
44-
4538
[[test]]
4639
name = "test-mount"
4740
path = "test/test_mount.rs"

src/sys/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ pub mod sendfile;
2323

2424
pub mod signal;
2525

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

3030
pub mod socket;

src/sys/signalfd.rs

Lines changed: 3 additions & 7 deletions
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
/// ```

test/sys/mod.rs

Lines changed: 2 additions & 0 deletions
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_signalfd.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#[cfg(target_os = "linux")]
2+
#[test]
3+
// FIXME: Fails with "fatal runtime error: failed to initiate panic, error 5" on i686-unknown-linux-musl
4+
#[cfg_attr(all(target_env = "musl", target_arch = "x86"), ignore)]
5+
fn test_signalfd() {
6+
use nix::sys::signalfd::{SFD_NONBLOCK, SignalFd};
7+
use nix::sys::signal;
8+
use nix::unistd;
9+
use nix::unistd::*;
10+
use nix::unistd::ForkResult::*;
11+
use nix::sys::signal::*;
12+
use nix::sys::wait::*;
13+
14+
// Set up a signalfd to listen for SIGUSR1 on this thread
15+
let mut mask = SigSet::empty();
16+
mask.add(SIGUSR1);
17+
mask.thread_block().unwrap();
18+
19+
// Start a child process
20+
match unistd::fork() {
21+
Ok(Child) => {
22+
// Get a signalfd for listening. This should inherit from the parent process, so no
23+
// need to pass a mask in here as well.
24+
let mask = SigSet::empty();
25+
let mut fd = SignalFd::with_flags(&mask, SFD_NONBLOCK).unwrap();
26+
27+
let mut counter = 0u8;
28+
loop {
29+
sleep(1);
30+
if let Ok(sig) = fd.read_signal() {
31+
let signo = Signal::from_c_int(sig.unwrap().ssi_signo as i32).unwrap();
32+
assert_eq!(signo, SIGUSR1);
33+
} else {
34+
assert!(false);
35+
}
36+
if counter >= 10 {
37+
assert!(false);
38+
} else {
39+
counter += 1;
40+
}
41+
}
42+
}
43+
// Send a SIGUSR1 signal to the calling process
44+
Ok(Parent { child }) => {
45+
sleep(1);
46+
kill(child, signal::SIGUSR1).ok().expect("Error: Kill Failed");
47+
assert_eq!(waitpid(child, None), Ok(WaitStatus::Exited(child, 0)));
48+
},
49+
// panic, fork should never fail unless there is a serious problem with the OS
50+
Err(_) => panic!("Error: Fork Failed")
51+
}
52+
}

test/test.rs

Lines changed: 1 addition & 1 deletion
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;

test/test_signalfd.rs

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)