Skip to content

Commit 5700e39

Browse files
committed
Use libc constants for signals.
1 parent c4257f8 commit 5700e39

File tree

1 file changed

+26
-103
lines changed

1 file changed

+26
-103
lines changed

src/sys/signal.rs

Lines changed: 26 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@ use std::ptr;
88
use {Error, Result};
99

1010
pub use libc::{
11-
SIGHUP, // 1
12-
SIGINT, // 2
13-
SIGQUIT, // 3
14-
SIGILL, // 4
15-
SIGABRT, // 6
16-
SIGFPE, // 8
17-
SIGKILL, // 9
18-
SIGSEGV, // 11
19-
SIGPIPE, // 13
20-
SIGALRM, // 14
21-
SIGTERM, // 15
22-
};
23-
24-
pub use self::signal::{
11+
SIGHUP,
12+
SIGINT,
13+
SIGQUIT,
14+
SIGILL,
15+
SIGABRT,
16+
SIGFPE,
17+
SIGKILL,
18+
SIGSEGV,
19+
SIGPIPE,
20+
SIGALRM,
21+
SIGTERM,
2522
SIGTRAP,
2623
SIGIOT,
2724
SIGBUS,
@@ -41,10 +38,13 @@ pub use self::signal::{
4138
SIGWINCH,
4239
SIGUSR1,
4340
SIGUSR2,
44-
45-
NSIG,
4641
};
4742

43+
// This doesn't always exist, but when it does, it's 7
44+
pub const SIGEMT: libc::c_int = 7;
45+
46+
pub const NSIG: libc::c_int = 32;
47+
4848
pub use self::signal::{
4949
SockFlag,
5050

@@ -60,9 +60,6 @@ pub use self::signal::{
6060
pub use self::signal::{HowFlag, SIG_BLOCK, SIG_UNBLOCK, SIG_SETMASK};
6161
pub use self::signal::sigset_t;
6262

63-
// This doesn't always exist, but when it does, it's 7
64-
pub const SIGEMT: libc::c_int = 7;
65-
6663
#[cfg(any(all(target_os = "linux",
6764
any(target_arch = "x86",
6865
target_arch = "x86_64",
@@ -92,32 +89,6 @@ pub mod signal {
9289
}
9390
}
9491

95-
pub const SIGTRAP: libc::c_int = 5;
96-
pub const SIGIOT: libc::c_int = 6;
97-
pub const SIGBUS: libc::c_int = 7;
98-
pub const SIGUSR1: libc::c_int = 10;
99-
pub const SIGUSR2: libc::c_int = 12;
100-
pub const SIGSTKFLT: libc::c_int = 16;
101-
pub const SIGCHLD: libc::c_int = 17;
102-
pub const SIGCONT: libc::c_int = 18;
103-
pub const SIGSTOP: libc::c_int = 19;
104-
pub const SIGTSTP: libc::c_int = 20;
105-
pub const SIGTTIN: libc::c_int = 21;
106-
pub const SIGTTOU: libc::c_int = 22;
107-
pub const SIGURG: libc::c_int = 23;
108-
pub const SIGXCPU: libc::c_int = 24;
109-
pub const SIGXFSZ: libc::c_int = 25;
110-
pub const SIGVTALRM: libc::c_int = 26;
111-
pub const SIGPROF: libc::c_int = 27;
112-
pub const SIGWINCH: libc::c_int = 28;
113-
pub const SIGIO: libc::c_int = 29;
114-
pub const SIGPOLL: libc::c_int = 29;
115-
pub const SIGPWR: libc::c_int = 30;
116-
pub const SIGSYS: libc::c_int = 31;
117-
pub const SIGUNUSED: libc::c_int = 31;
118-
119-
pub const NSIG: libc::c_int = 32;
120-
12192
// This definition is not as accurate as it could be, {pid, uid, status} is
12293
// actually a giant union. Currently we're only interested in these fields,
12394
// however.
@@ -181,31 +152,6 @@ pub mod signal {
181152
}
182153
}
183154

184-
pub const SIGTRAP: libc::c_int = 5;
185-
pub const SIGIOT: libc::c_int = 6;
186-
pub const SIGBUS: libc::c_int = 10;
187-
pub const SIGSYS: libc::c_int = 12;
188-
pub const SIGUSR1: libc::c_int = 16;
189-
pub const SIGUSR2: libc::c_int = 17;
190-
pub const SIGCHLD: libc::c_int = 18;
191-
pub const SIGCLD: libc::c_int = 18;
192-
pub const SIGPWR: libc::c_int = 19;
193-
pub const SIGWINCH: libc::c_int = 20;
194-
pub const SIGURG: libc::c_int = 21;
195-
pub const SIGIO: libc::c_int = 22;
196-
pub const SIGPOLL: libc::c_int = 22;
197-
pub const SIGSTOP: libc::c_int = 23;
198-
pub const SIGTSTP: libc::c_int = 24;
199-
pub const SIGCONT: libc::c_int = 25;
200-
pub const SIGTTIN: libc::c_int = 26;
201-
pub const SIGTTOU: libc::c_int = 27;
202-
pub const SIGVTALRM: libc::c_int = 28;
203-
pub const SIGPROF: libc::c_int = 29;
204-
pub const SIGXCPU: libc::c_int = 30;
205-
pub const SIGFSZ: libc::c_int = 31;
206-
207-
pub const NSIG: libc::c_int = 32;
208-
209155
// This definition is not as accurate as it could be, {pid, uid, status} is
210156
// actually a giant union. Currently we're only interested in these fields,
211157
// however.
@@ -263,29 +209,6 @@ pub mod signal {
263209
}
264210
}
265211

266-
pub const SIGTRAP: libc::c_int = 5;
267-
pub const SIGIOT: libc::c_int = 6;
268-
pub const SIGBUS: libc::c_int = 10;
269-
pub const SIGSYS: libc::c_int = 12;
270-
pub const SIGURG: libc::c_int = 16;
271-
pub const SIGSTOP: libc::c_int = 17;
272-
pub const SIGTSTP: libc::c_int = 18;
273-
pub const SIGCONT: libc::c_int = 19;
274-
pub const SIGCHLD: libc::c_int = 20;
275-
pub const SIGTTIN: libc::c_int = 21;
276-
pub const SIGTTOU: libc::c_int = 22;
277-
pub const SIGIO: libc::c_int = 23;
278-
pub const SIGXCPU: libc::c_int = 24;
279-
pub const SIGXFSZ: libc::c_int = 25;
280-
pub const SIGVTALRM: libc::c_int = 26;
281-
pub const SIGPROF: libc::c_int = 27;
282-
pub const SIGWINCH: libc::c_int = 28;
283-
pub const SIGINFO: libc::c_int = 29;
284-
pub const SIGUSR1: libc::c_int = 30;
285-
pub const SIGUSR2: libc::c_int = 31;
286-
287-
pub const NSIG: libc::c_int = 32;
288-
289212
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "openbsd"))]
290213
pub type sigset_t = u32;
291214
#[cfg(target_os = "freebsd")]
@@ -559,38 +482,38 @@ mod tests {
559482
#[test]
560483
fn test_contains() {
561484
let mut mask = SigSet::empty();
562-
mask.add(signal::SIGUSR1).unwrap();
485+
mask.add(SIGUSR1).unwrap();
563486

564-
assert_eq!(mask.contains(signal::SIGUSR1), Ok(true));
565-
assert_eq!(mask.contains(signal::SIGUSR2), Ok(false));
487+
assert_eq!(mask.contains(SIGUSR1), Ok(true));
488+
assert_eq!(mask.contains(SIGUSR2), Ok(false));
566489

567490
let all = SigSet::all();
568-
assert_eq!(all.contains(signal::SIGUSR1), Ok(true));
569-
assert_eq!(all.contains(signal::SIGUSR2), Ok(true));
491+
assert_eq!(all.contains(SIGUSR1), Ok(true));
492+
assert_eq!(all.contains(SIGUSR2), Ok(true));
570493
}
571494

572495
#[test]
573496
fn test_thread_signal_block() {
574497
let mut mask = SigSet::empty();
575-
mask.add(signal::SIGUSR1).unwrap();
498+
mask.add(SIGUSR1).unwrap();
576499

577500
assert!(mask.thread_block().is_ok());
578501
}
579502

580503
#[test]
581504
fn test_thread_signal_swap() {
582505
let mut mask = SigSet::empty();
583-
mask.add(signal::SIGUSR1).unwrap();
506+
mask.add(SIGUSR1).unwrap();
584507
mask.thread_block().unwrap();
585508

586509
assert!(SigSet::thread_get_mask().unwrap().contains(SIGUSR1).unwrap());
587510

588511
let mask2 = SigSet::empty();
589-
mask.add(signal::SIGUSR2).unwrap();
512+
mask.add(SIGUSR2).unwrap();
590513

591514
let oldmask = mask2.thread_swap_mask(signal::SIG_SETMASK).unwrap();
592515

593-
assert!(oldmask.contains(signal::SIGUSR1).unwrap());
594-
assert!(!oldmask.contains(signal::SIGUSR2).unwrap());
516+
assert!(oldmask.contains(SIGUSR1).unwrap());
517+
assert!(!oldmask.contains(SIGUSR2).unwrap());
595518
}
596519
}

0 commit comments

Comments
 (0)