1
1
// Portions of this file are Copyright 2014 The Rust Project Developers.
2
2
// See http://rust-lang.org/COPYRIGHT.
3
3
4
- use libc;
4
+ use libc:: { self , sigaction as sigaction_t , siginfo_t , sigset_t } ;
5
5
use { Errno , Result } ;
6
6
use std:: mem;
7
7
use std:: ptr;
@@ -44,9 +44,6 @@ pub const SIGEMT: libc::c_int = 7;
44
44
45
45
pub const NSIG : libc:: c_int = 32 ;
46
46
47
- pub use self :: signal:: sigset_t;
48
-
49
-
50
47
bitflags ! {
51
48
flags SockFlag : libc:: c_int {
52
49
const SA_NOCLDSTOP = libc:: SA_NOCLDSTOP ,
@@ -67,175 +64,14 @@ bitflags!{
67
64
}
68
65
}
69
66
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
-
230
67
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} ;
233
69
234
70
#[ allow( improper_ctypes) ]
235
71
extern {
236
72
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 ;
239
75
240
76
pub fn sigaddset ( set : * mut sigset_t , signum : c_int ) -> c_int ;
241
77
pub fn sigdelset ( set : * mut sigset_t , signum : c_int ) -> c_int ;
@@ -341,20 +177,16 @@ impl AsRef<sigset_t> for SigSet {
341
177
}
342
178
}
343
179
344
- pub use self :: signal:: siginfo;
345
-
346
180
#[ allow( unknown_lints) ]
347
181
#[ allow( raw_pointer_derive) ]
348
182
#[ derive( Clone , Copy ) ]
349
183
pub enum SigHandler {
350
184
SigDfl ,
351
185
SigIgn ,
352
186
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 ) )
354
188
}
355
189
356
- type sigaction_t = self :: signal:: sigaction ;
357
-
358
190
pub struct SigAction {
359
191
sigaction : sigaction_t
360
192
}
@@ -364,15 +196,15 @@ impl SigAction {
364
196
/// type of the `handler` argument.
365
197
pub fn new ( handler : SigHandler , flags : SockFlag , mask : SigSet ) -> SigAction {
366
198
let mut s = unsafe { mem:: uninitialized :: < sigaction_t > ( ) } ;
367
- s. sa_handler = match handler {
199
+ s. sa_sigaction = match handler {
368
200
SigHandler :: SigDfl => unsafe { mem:: transmute ( libc:: SIG_DFL ) } ,
369
201
SigHandler :: SigIgn => unsafe { mem:: transmute ( libc:: SIG_IGN ) } ,
370
- SigHandler :: Handler ( f) => f ,
202
+ SigHandler :: Handler ( f) => unsafe { mem :: transmute ( f ) } ,
371
203
SigHandler :: SigAction ( f) => unsafe { mem:: transmute ( f) } ,
372
204
} ;
373
205
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 ( ) ,
376
208
} ;
377
209
s. sa_mask = mask. sigset ;
378
210
0 commit comments