summaryrefslogtreecommitdiff
path: root/test/test_signalfd.rs
blob: 28a6decb9ee18c40af0b072debec1141faede801 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
extern crate nix;

#[cfg(feature = "signalfd")]
use nix::sys::signalfd::SignalFd;
#[cfg(feature = "signalfd")]
use nix::sys::signal;
#[cfg(feature = "signalfd")]
use nix::unistd;

#[cfg(feature = "signalfd")]
fn main() {
    print!("test test_signalfd ... ");

    let mut mask = signal::SigSet::empty();
    mask.add(signal::SIGUSR1).unwrap();
    mask.thread_block().unwrap();

    let mut fd = SignalFd::new(&mask).unwrap();

    let pid = unistd::getpid();
    signal::kill(pid, signal::SIGUSR1).unwrap();

    let res = fd.read_signal();

    assert_eq!(res.unwrap().unwrap().ssi_signo as i32, signal::SIGUSR1);
    println!("ok");
}

#[cfg(not(feature = "signalfd"))]
fn main() {}