@@ -206,12 +206,12 @@ bitflags!{
206
206
}
207
207
}
208
208
209
- bitflags ! {
210
- flags SigFlags : libc :: c_int {
211
- const SIG_BLOCK = libc :: SIG_BLOCK ,
212
- const SIG_UNBLOCK = libc:: SIG_UNBLOCK ,
213
- const SIG_SETMASK = libc:: SIG_SETMASK ,
214
- }
209
+ # [ repr ( i32 ) ]
210
+ # [ derive ( Clone , Copy , PartialEq ) ]
211
+ pub enum SigmaskHow {
212
+ SIG_BLOCK = libc:: SIG_BLOCK ,
213
+ SIG_UNBLOCK = libc:: SIG_UNBLOCK ,
214
+ SIG_SETMASK = libc :: SIG_SETMASK ,
215
215
}
216
216
217
217
#[ derive( Clone , Copy ) ]
@@ -268,27 +268,27 @@ impl SigSet {
268
268
/// Gets the currently blocked (masked) set of signals for the calling thread.
269
269
pub fn thread_get_mask ( ) -> Result < SigSet > {
270
270
let mut oldmask: SigSet = unsafe { mem:: uninitialized ( ) } ;
271
- try!( pthread_sigmask ( SigFlags :: empty ( ) , None , Some ( & mut oldmask) ) ) ;
271
+ try!( pthread_sigmask ( SigmaskHow :: SIG_SETMASK , None , Some ( & mut oldmask) ) ) ;
272
272
Ok ( oldmask)
273
273
}
274
274
275
275
/// Sets the set of signals as the signal mask for the calling thread.
276
276
pub fn thread_set_mask ( & self ) -> Result < ( ) > {
277
- pthread_sigmask ( SIG_SETMASK , Some ( self ) , None )
277
+ pthread_sigmask ( SigmaskHow :: SIG_SETMASK , Some ( self ) , None )
278
278
}
279
279
280
280
/// Adds the set of signals to the signal mask for the calling thread.
281
281
pub fn thread_block ( & self ) -> Result < ( ) > {
282
- pthread_sigmask ( SIG_BLOCK , Some ( self ) , None )
282
+ pthread_sigmask ( SigmaskHow :: SIG_BLOCK , Some ( self ) , None )
283
283
}
284
284
285
285
/// Removes the set of signals from the signal mask for the calling thread.
286
286
pub fn thread_unblock ( & self ) -> Result < ( ) > {
287
- pthread_sigmask ( SIG_UNBLOCK , Some ( self ) , None )
287
+ pthread_sigmask ( SigmaskHow :: SIG_UNBLOCK , Some ( self ) , None )
288
288
}
289
289
290
290
/// Sets the set of signals as the signal mask, and returns the old mask.
291
- pub fn thread_swap_mask ( & self , how : SigFlags ) -> Result < SigSet > {
291
+ pub fn thread_swap_mask ( & self , how : SigmaskHow ) -> Result < SigSet > {
292
292
let mut oldmask: SigSet = unsafe { mem:: uninitialized ( ) } ;
293
293
try!( pthread_sigmask ( how, Some ( self ) , Some ( & mut oldmask) ) ) ;
294
294
Ok ( oldmask)
@@ -368,7 +368,7 @@ pub unsafe fn sigaction(signal: Signal, sigaction: &SigAction) -> Result<SigActi
368
368
///
369
369
/// For more information, visit the [pthread_sigmask](http://man7.org/linux/man-pages/man3/pthread_sigmask.3.html),
370
370
/// or [sigprocmask](http://man7.org/linux/man-pages/man2/sigprocmask.2.html) man pages.
371
- pub fn pthread_sigmask ( how : SigFlags ,
371
+ pub fn pthread_sigmask ( how : SigmaskHow ,
372
372
set : Option < & SigSet > ,
373
373
oldset : Option < & mut SigSet > ) -> Result < ( ) > {
374
374
if set. is_none ( ) && oldset. is_none ( ) {
@@ -377,7 +377,7 @@ pub fn pthread_sigmask(how: SigFlags,
377
377
378
378
let res = unsafe {
379
379
// if set or oldset is None, pass in null pointers instead
380
- libc:: pthread_sigmask ( how. bits ( ) ,
380
+ libc:: pthread_sigmask ( how as libc :: c_int ,
381
381
set. map_or_else ( || ptr:: null :: < libc:: sigset_t > ( ) ,
382
382
|s| & s. sigset as * const libc:: sigset_t ) ,
383
383
oldset. map_or_else ( || ptr:: null_mut :: < libc:: sigset_t > ( ) ,
@@ -442,12 +442,46 @@ mod tests {
442
442
assert ! ( two_signals. contains( SIGUSR2 ) ) ;
443
443
}
444
444
445
+ // This test doesn't actually test get_mask functionality, see the set_mask test for that.
446
+ #[ test]
447
+ fn test_thread_signal_get_mask ( ) {
448
+ assert ! ( SigSet :: thread_get_mask( ) . is_ok( ) ) ;
449
+ }
450
+
451
+ #[ test]
452
+ fn test_thread_signal_set_mask ( ) {
453
+ let prev_mask = SigSet :: thread_get_mask ( ) . expect ( "Failed to get existing signal mask!" ) ;
454
+
455
+ let mut test_mask = prev_mask;
456
+ test_mask. add ( SIGUSR1 ) ;
457
+
458
+ assert ! ( test_mask. thread_set_mask( ) . is_ok( ) ) ;
459
+ let new_mask = SigSet :: thread_get_mask ( ) . expect ( "Failed to get new mask!" ) ;
460
+
461
+ assert ! ( new_mask. contains( SIGUSR1 ) ) ;
462
+ assert ! ( !new_mask. contains( SIGUSR2 ) ) ;
463
+
464
+ prev_mask. thread_set_mask ( ) . expect ( "Failed to revert signal mask!" ) ;
465
+ }
466
+
445
467
#[ test]
446
468
fn test_thread_signal_block ( ) {
447
469
let mut mask = SigSet :: empty ( ) ;
448
470
mask. add ( SIGUSR1 ) ;
449
471
450
472
assert ! ( mask. thread_block( ) . is_ok( ) ) ;
473
+
474
+ assert ! ( SigSet :: thread_get_mask( ) . unwrap( ) . contains( SIGUSR1 ) ) ;
475
+ }
476
+
477
+ #[ test]
478
+ fn test_thread_signal_unblock ( ) {
479
+ let mut mask = SigSet :: empty ( ) ;
480
+ mask. add ( SIGUSR1 ) ;
481
+
482
+ assert ! ( mask. thread_unblock( ) . is_ok( ) ) ;
483
+
484
+ assert ! ( !SigSet :: thread_get_mask( ) . unwrap( ) . contains( SIGUSR1 ) ) ;
451
485
}
452
486
453
487
#[ test]
@@ -458,13 +492,15 @@ mod tests {
458
492
459
493
assert ! ( SigSet :: thread_get_mask( ) . unwrap( ) . contains( SIGUSR1 ) ) ;
460
494
461
- let mask2 = SigSet :: empty ( ) ;
462
- mask . add ( SIGUSR2 ) ;
495
+ let mut mask2 = SigSet :: empty ( ) ;
496
+ mask2 . add ( SIGUSR2 ) ;
463
497
464
- let oldmask = mask2. thread_swap_mask ( SIG_SETMASK ) . unwrap ( ) ;
498
+ let oldmask = mask2. thread_swap_mask ( SigmaskHow :: SIG_SETMASK ) . unwrap ( ) ;
465
499
466
500
assert ! ( oldmask. contains( SIGUSR1 ) ) ;
467
501
assert ! ( !oldmask. contains( SIGUSR2 ) ) ;
502
+
503
+ assert ! ( SigSet :: thread_get_mask( ) . unwrap( ) . contains( SIGUSR2 ) ) ;
468
504
}
469
505
470
506
// TODO(#251): Re-enable after figuring out flakiness.
0 commit comments