Skip to content

Commit 8f1d193

Browse files
committed
Use libc structs in sys/signal.rs.
1 parent 38c7e20 commit 8f1d193

File tree

1 file changed

+9
-177
lines changed

1 file changed

+9
-177
lines changed

src/sys/signal.rs

+9-177
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Portions of this file are Copyright 2014 The Rust Project Developers.
22
// See http://rust-lang.org/COPYRIGHT.
33

4-
use libc;
4+
use libc::{self, sigaction as sigaction_t ,siginfo_t, sigset_t};
55
use {Errno, Result};
66
use std::mem;
77
use std::ptr;
@@ -44,9 +44,6 @@ pub const SIGEMT: libc::c_int = 7;
4444

4545
pub const NSIG: libc::c_int = 32;
4646

47-
pub use self::signal::sigset_t;
48-
49-
5047
bitflags!{
5148
flags SockFlag: libc::c_int {
5249
const SA_NOCLDSTOP = libc::SA_NOCLDSTOP,
@@ -67,175 +64,14 @@ bitflags!{
6764
}
6865
}
6966

70-
#[cfg(any(all(target_os = "linux",
71-
any(target_arch = "x86",
72-
target_arch = "x86_64",
73-
target_arch = "aarch64",
74-
target_arch = "arm")),
75-
target_os = "android"))]
76-
pub mod signal {
77-
78-
use libc;
79-
use super::SockFlag;
80-
81-
// This definition is not as accurate as it could be, {pid, uid, status} is
82-
// actually a giant union. Currently we're only interested in these fields,
83-
// however.
84-
#[repr(C)]
85-
#[derive(Clone, Copy)]
86-
pub struct siginfo {
87-
pub si_signo: libc::c_int,
88-
pub si_errno: libc::c_int,
89-
pub si_code: libc::c_int,
90-
pub pid: libc::pid_t,
91-
pub uid: libc::uid_t,
92-
pub status: libc::c_int,
93-
}
94-
95-
#[repr(C)]
96-
#[allow(missing_copy_implementations)]
97-
pub struct sigaction {
98-
pub sa_handler: extern fn(libc::c_int),
99-
pub sa_mask: sigset_t,
100-
pub sa_flags: SockFlag,
101-
sa_restorer: *mut libc::c_void,
102-
}
103-
104-
#[repr(C)]
105-
#[cfg(target_pointer_width = "32")]
106-
#[derive(Clone, Copy)]
107-
pub struct sigset_t {
108-
__val: [libc::c_ulong; 32],
109-
}
110-
111-
#[repr(C)]
112-
#[cfg(target_pointer_width = "64")]
113-
#[derive(Clone, Copy)]
114-
pub struct sigset_t {
115-
__val: [libc::c_ulong; 16],
116-
}
117-
}
118-
119-
#[cfg(all(target_os = "linux",
120-
any(target_arch = "mips", target_arch = "mipsel")))]
121-
pub mod signal {
122-
use libc;
123-
use super::SockFlag;
124-
125-
// This definition is not as accurate as it could be, {pid, uid, status} is
126-
// actually a giant union. Currently we're only interested in these fields,
127-
// however.
128-
#[repr(C)]
129-
pub struct siginfo {
130-
pub si_signo: libc::c_int,
131-
pub si_code: libc::c_int,
132-
pub si_errno: libc::c_int,
133-
pub pid: libc::pid_t,
134-
pub uid: libc::uid_t,
135-
pub status: libc::c_int,
136-
}
137-
138-
#[repr(C)]
139-
pub struct sigaction {
140-
pub sa_flags: SockFlag,
141-
pub sa_handler: extern fn(libc::c_int),
142-
pub sa_mask: sigset_t,
143-
sa_restorer: *mut libc::c_void,
144-
sa_resv: [libc::c_int; 1],
145-
}
146-
147-
#[repr(C)]
148-
pub struct sigset_t {
149-
__val: [libc::c_ulong; 32],
150-
}
151-
}
152-
153-
#[cfg(any(target_os = "macos",
154-
target_os = "ios",
155-
target_os = "freebsd",
156-
target_os = "openbsd",
157-
target_os = "dragonfly",
158-
target_os = "netbsd"))]
159-
pub mod signal {
160-
use libc;
161-
use super::SockFlag;
162-
163-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "openbsd"))]
164-
pub type sigset_t = u32;
165-
#[cfg(target_os = "freebsd")]
166-
#[repr(C)]
167-
#[derive(Clone, Copy)]
168-
pub struct sigset_t {
169-
bits: [u32; 4],
170-
}
171-
#[cfg(any(target_os = "dragonfly", target_os = "netbsd"))]
172-
#[repr(C)]
173-
#[derive(Clone, Copy)]
174-
pub struct sigset_t {
175-
bits: [libc::c_uint; 4],
176-
}
177-
178-
// This structure has more fields, but we're not all that interested in
179-
// them.
180-
#[cfg(not(target_os = "dragonfly"))]
181-
#[repr(C)]
182-
#[derive(Clone, Copy)]
183-
pub struct siginfo {
184-
pub si_signo: libc::c_int,
185-
pub si_errno: libc::c_int,
186-
pub si_code: libc::c_int,
187-
pub pid: libc::pid_t,
188-
pub uid: libc::uid_t,
189-
pub status: libc::c_int,
190-
}
191-
192-
#[cfg(target_os = "dragonfly")]
193-
#[repr(C)]
194-
#[derive(Clone, Copy)]
195-
pub struct siginfo {
196-
pub si_signo: libc::c_int,
197-
pub si_errno: libc::c_int,
198-
pub si_code: libc::c_int,
199-
pub pid: libc::c_int,
200-
pub uid: libc::c_uint,
201-
pub status: libc::c_int,
202-
}
203-
204-
#[cfg(any(target_os = "macos", target_os = "ios"))]
205-
#[repr(C)]
206-
#[allow(missing_copy_implementations)]
207-
pub struct sigaction {
208-
pub sa_handler: extern fn(libc::c_int),
209-
pub sa_mask: sigset_t,
210-
pub sa_flags: SockFlag,
211-
}
212-
213-
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
214-
#[repr(C)]
215-
pub struct sigaction {
216-
pub sa_handler: extern fn(libc::c_int),
217-
pub sa_flags: SockFlag,
218-
pub sa_mask: sigset_t,
219-
}
220-
221-
#[cfg(any(target_os = "openbsd", target_os = "netbsd"))]
222-
#[repr(C)]
223-
pub struct sigaction {
224-
pub sa_handler: extern fn(libc::c_int),
225-
pub sa_mask: sigset_t,
226-
pub sa_flags: SockFlag,
227-
}
228-
}
229-
23067
mod ffi {
231-
use libc::{c_int, pid_t};
232-
use super::signal::{sigaction, sigset_t};
68+
use libc::{c_int, pid_t, sigaction as sigaction_t, sigset_t};
23369

23470
#[allow(improper_ctypes)]
23571
extern {
23672
pub fn sigaction(signum: c_int,
237-
act: *const sigaction,
238-
oldact: *mut sigaction) -> c_int;
73+
act: *const sigaction_t,
74+
oldact: *mut sigaction_t) -> c_int;
23975

24076
pub fn sigaddset(set: *mut sigset_t, signum: c_int) -> c_int;
24177
pub fn sigdelset(set: *mut sigset_t, signum: c_int) -> c_int;
@@ -341,20 +177,16 @@ impl AsRef<sigset_t> for SigSet {
341177
}
342178
}
343179

344-
pub use self::signal::siginfo;
345-
346180
#[allow(unknown_lints)]
347181
#[allow(raw_pointer_derive)]
348182
#[derive(Clone, Copy)]
349183
pub enum SigHandler {
350184
SigDfl,
351185
SigIgn,
352186
Handler(extern fn(SigNum)),
353-
SigAction(extern fn(SigNum, *mut siginfo, *mut libc::c_void))
187+
SigAction(extern fn(SigNum, *mut siginfo_t, *mut libc::c_void))
354188
}
355189

356-
type sigaction_t = self::signal::sigaction;
357-
358190
pub struct SigAction {
359191
sigaction: sigaction_t
360192
}
@@ -364,15 +196,15 @@ impl SigAction {
364196
/// type of the `handler` argument.
365197
pub fn new(handler: SigHandler, flags: SockFlag, mask: SigSet) -> SigAction {
366198
let mut s = unsafe { mem::uninitialized::<sigaction_t>() };
367-
s.sa_handler = match handler {
199+
s.sa_sigaction = match handler {
368200
SigHandler::SigDfl => unsafe { mem::transmute(libc::SIG_DFL) },
369201
SigHandler::SigIgn => unsafe { mem::transmute(libc::SIG_IGN) },
370-
SigHandler::Handler(f) => f,
202+
SigHandler::Handler(f) => unsafe { mem::transmute(f) },
371203
SigHandler::SigAction(f) => unsafe { mem::transmute(f) },
372204
};
373205
s.sa_flags = match handler {
374-
SigHandler::SigAction(_) => flags | SA_SIGINFO,
375-
_ => flags - SA_SIGINFO,
206+
SigHandler::SigAction(_) => (flags | SA_SIGINFO).bits(),
207+
_ => (flags - SA_SIGINFO).bits(),
376208
};
377209
s.sa_mask = mask.sigset;
378210

0 commit comments

Comments
 (0)