Skip to content

Commit 531863a

Browse files
committed
Use pthread_sigmask from "nix" crate (since 0.4.1)
1 parent 4a497c8 commit 531863a

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ repository = "http://github.com/tailhook/signal"
1111
documentation = "http://tailhook.github.io/signal/"
1212

1313
[dependencies]
14-
nix = "0.4.0"
14+
nix = "0.4.1"
1515
libc = "0.1.10"
1616
time = "0.1.32"

src/exec_handler.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99
1010
use std::io::Write;
1111
use std::mem::{forget, transmute};
12-
use std::ptr::{null, null_mut};
12+
use std::ptr::{null};
1313
use std::ffi::CString;
1414
use std::env::{current_exe, args_os, vars_os};
1515

1616
use nix;
1717
use libc::{execve, c_char};
1818
use nix::sys::signal::{sigaction, SigAction, SigNum, SigSet, SockFlag};
19+
use nix::sys::signal::{pthread_sigmask, SIG_UNBLOCK};
1920

20-
use ffi::{ToCString, pthread_sigmask, SIG_UNBLOCK};
21+
use ffi::{ToCString};
2122

2223

2324
static mut exec_command_line: *const ExecCommandLine =
@@ -125,7 +126,7 @@ pub fn set_handler(signals: &[SigNum], avoid_race_condition: bool)
125126
}
126127
// TODO(tailhook) is this error reporting is ok? or maybe just panic?
127128
if avoid_race_condition && res.is_ok() {
128-
pthread_sigmask(SIG_UNBLOCK, &sigset, null_mut());
129+
pthread_sigmask(SIG_UNBLOCK, Some(&sigset), None).unwrap();
129130
}
130131
res
131132
}

src/ffi.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::ffi::{CString, OsStr};
22
use std::os::unix::ffi::OsStrExt;
33

4-
use nix::sys::signal::{SigSet, SigNum};
4+
use nix::sys::signal::{sigset_t, SigNum};
55
use libc::{c_int, c_void, timespec};
66

77

@@ -22,14 +22,8 @@ impl<T:AsRef<OsStr>> ToCString for T {
2222

2323

2424
// All the following should be moved to nix-rust
25-
26-
pub const SIG_BLOCK: c_int = 0;
27-
pub const SIG_UNBLOCK: c_int = 1;
28-
pub const SIG_SETMASK: c_int = 2;
2925
extern {
30-
pub fn pthread_sigmask(how: c_int, set: *const SigSet,
31-
oldset: *mut SigSet) -> c_int;
32-
pub fn sigwait(set: *const SigSet, sig: *mut SigNum) -> c_int;
33-
pub fn sigtimedwait(set: *const SigSet, info: *mut c_void,
26+
pub fn sigwait(set: *const sigset_t, sig: *mut SigNum) -> c_int;
27+
pub fn sigtimedwait(set: *const sigset_t, info: *mut c_void,
3428
timeout: *const timespec) -> c_int;
3529
}

src/trap.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ use std::ptr::null_mut;
1515

1616
use time::{SteadyTime, Duration};
1717
use nix::sys::signal::{sigaction, SigAction, SigNum, SigSet, SockFlag};
18+
use nix::sys::signal::{pthread_sigmask, SIG_BLOCK, SIG_SETMASK};
1819
use nix::errno::{Errno, errno};
1920
use libc::timespec;
2021

21-
use ffi::{pthread_sigmask, sigwait, sigtimedwait, SIG_BLOCK, SIG_SETMASK};
22+
use ffi::{sigwait, sigtimedwait};
2223

2324
/// A RAII guard for masking out signals and waiting for them synchronously
2425
pub struct Trap {
@@ -40,7 +41,8 @@ impl Trap {
4041
}
4142
let mut oldset = uninitialized();
4243
let mut oldsigs = Vec::new();
43-
pthread_sigmask(SIG_BLOCK, &sigset, &mut oldset);
44+
pthread_sigmask(SIG_BLOCK, Some(&sigset), Some(&mut oldset))
45+
.unwrap();
4446
for &sig in signals {
4547
oldsigs.push((sig, sigaction(sig,
4648
&SigAction::new(empty_handler, SockFlag::empty(), sigset))
@@ -67,7 +69,8 @@ impl Trap {
6769
tv_nsec: (timeout - Duration::seconds(timeout.num_seconds()))
6870
.num_nanoseconds().unwrap(),
6971
};
70-
let sig = unsafe { sigtimedwait(&self.sigset, null_mut(), &tm) };
72+
let sig = unsafe { sigtimedwait(self.sigset.as_ref(),
73+
null_mut(), &tm) };
7174
if sig > 0 {
7275
return Some(sig);
7376
} else {
@@ -92,7 +95,7 @@ impl Iterator for Trap {
9295
fn next(&mut self) -> Option<SigNum> {
9396
let mut sig: SigNum = 0;
9497
loop {
95-
if unsafe { sigwait(&self.sigset, &mut sig) } == 0 {
98+
if unsafe { sigwait(self.sigset.as_ref(), &mut sig) } == 0 {
9699
return Some(sig);
97100
} else {
98101
if Errno::last() == Errno::EINTR {
@@ -110,7 +113,8 @@ impl Drop for Trap {
110113
for &(sig, ref sigact) in self.oldsigs.iter() {
111114
sigaction(sig, sigact).unwrap();
112115
}
113-
pthread_sigmask(SIG_SETMASK, &self.oldset, null_mut());
116+
pthread_sigmask(SIG_SETMASK, Some(&self.oldset), None)
117+
.unwrap();
114118
}
115119
}
116120
}

0 commit comments

Comments
 (0)