4 * Luiz Fernando N. Capitulino <lcapitulino@mandriva.com.br>
11 volatile sig_atomic_t quitflag
; /* set by the handler */
13 static void sig_int(int signo
)
16 printf("interrupt\n");
17 else if (signo
== SIGQUIT
)
23 sigset_t newmask
, oldmask
, zeromask
;
25 if (signal(SIGINT
, sig_int
) == SIG_ERR
) {
26 perror("signal(SIGINT)");
30 if (signal(SIGQUIT
, sig_int
) == SIG_ERR
) {
31 perror("signal(SIGQUIT)");
35 sigemptyset(&zeromask
);
36 sigemptyset(&newmask
);
37 sigaddset(&newmask
, SIGQUIT
);
40 * Block SIGQUIT and save current signal mask
42 if (sigprocmask(SIG_BLOCK
, &newmask
, &oldmask
) < 0) {
43 perror("sigprocmask()");
48 sigsuspend(&zeromask
);
51 * SIGQUIT has been caught and is now blocked; do whatever
53 printf("SIGQUIT caught!\n");
56 * Reset signal mask which unblocks SIGQUIT
58 if (sigprocmask(SIG_SETMASK
, &oldmask
, NULL
) < 0) {
59 perror("sigprocmask()");