@@ -5,3 +5,45 @@ use nix::sys::signal::*;
5
5
fn test_kill_none ( ) {
6
6
kill ( getpid ( ) , None ) . expect ( "Should be able to send signal to myself." ) ;
7
7
}
8
+
9
+ #[ test]
10
+ fn test_sigprocmask_noop ( ) {
11
+ sigprocmask ( SigmaskHow :: SIG_BLOCK , None , None )
12
+ . expect ( "this should be an effective noop" ) ;
13
+ }
14
+
15
+ #[ test]
16
+ fn test_sigprocmask ( ) {
17
+ #[ allow( unused_variables) ]
18
+ let m = :: SIGNAL_MTX . lock ( ) . expect ( "Mutex got poisoned by another test" ) ;
19
+
20
+ // This needs to be a signal that rust doesn't use in the test harness.
21
+ const SIGNAL : Signal = Signal :: SIGCHLD ;
22
+
23
+ let mut old_signal_set = SigSet :: empty ( ) ;
24
+ sigprocmask ( SigmaskHow :: SIG_BLOCK , None , Some ( & mut old_signal_set) )
25
+ . expect ( "expect to be able to retrieve old signals" ) ;
26
+
27
+ // Make sure the old set doesn't contain the signal, otherwise the following
28
+ // test don't make sense.
29
+ assert_eq ! ( old_signal_set. contains( SIGNAL ) , false ,
30
+ "the {:?} signal is already blocked, please change to a \
31
+ different one", SIGNAL ) ;
32
+
33
+ // Now block the signal.
34
+ let mut signal_set = SigSet :: empty ( ) ;
35
+ signal_set. add ( SIGNAL ) ;
36
+ sigprocmask ( SigmaskHow :: SIG_BLOCK , Some ( & signal_set) , None )
37
+ . expect ( "expect to be able to block signals" ) ;
38
+
39
+ // And test it again, to make sure the change was effective.
40
+ old_signal_set. clear ( ) ;
41
+ sigprocmask ( SigmaskHow :: SIG_BLOCK , None , Some ( & mut old_signal_set) )
42
+ . expect ( "expect to be able to retrieve old signals" ) ;
43
+ assert_eq ! ( old_signal_set. contains( SIGNAL ) , true ,
44
+ "expected the {:?} to be blocked" , SIGNAL ) ;
45
+
46
+ // Reset the signal.
47
+ sigprocmask ( SigmaskHow :: SIG_UNBLOCK , Some ( & signal_set) , None )
48
+ . expect ( "expect to be able to block signals" ) ;
49
+ }
0 commit comments