summaryrefslogtreecommitdiff
path: root/test/test_signalfd.rs
blob: ee14d69a5fcdc865c72bf1c0671499f1cb77f6fa (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
extern crate nix;

#[cfg(feature = "signalfd")]

use nix::sys::signalfd::*;

#[cfg(feature = "signalfd")]
fn main() {
    let mut mask = 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!(res.is_ok());

    let opt = res.ok().unwrap();
    assert!(opt.is_some());

    let info = opt.unwrap();
    assert_eq!(info.ssi_signo as i32, signal::SIGUSR1);
}

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