7 /* delay/resume signal delivery
9 /* #include <sigdelay.h>
15 /* sigdelay() delays delivery of signals. Signals that
16 /* arrive in the mean time will be queued.
18 /* sigresume() resumes delivery of signals. Signals that have
19 /* arrived in the mean time will be delivered.
21 /* All errors are fatal.
23 /* The signal queue may be really short (as in: one per signal type).
25 /* Some signals such as SIGKILL cannot be blocked.
29 /* The Secure Mailer license must be distributed with this software.
32 /* IBM T.J. Watson Research
34 /* Yorktown Heights, NY 10598, USA
42 /* Utility library. */
45 #include "posix_signals.h"
48 /* Application-specific. */
50 static sigset_t saved_sigmask
;
51 static sigset_t block_sigmask
;
52 static int suspending
;
53 static int siginit_done
;
55 /* siginit - compute signal mask only once */
57 static void siginit(void)
62 sigemptyset(&block_sigmask
);
63 for (sig
= 1; sig
< NSIG
; sig
++)
64 sigaddset(&block_sigmask
, sig
);
67 /* sigresume - deliver delayed signals and disable signal delay */
71 if (suspending
!= 0) {
73 if (sigprocmask(SIG_SETMASK
, &saved_sigmask
, (sigset_t
*) 0) < 0)
74 msg_fatal("sigresume: sigprocmask: %m");
78 /* sigdelay - save signal mask and block all signals */
82 if (siginit_done
== 0)
84 if (suspending
== 0) {
86 if (sigprocmask(SIG_BLOCK
, &block_sigmask
, &saved_sigmask
) < 0)
87 msg_fatal("sigdelay: sigprocmask: %m");
94 * Test program - press Ctrl-C twice while signal delivery is delayed, and
95 * see how many signals are delivered when signal delivery is resumed.
102 static void gotsig(int sig
)
104 printf("Got signal %d\n", sig
);
107 int main(int unused_argc
, char **unused_argv
)
109 signal(SIGINT
, gotsig
);
110 signal(SIGQUIT
, gotsig
);
112 printf("Delaying signal delivery\n");
115 printf("Resuming signal delivery\n");