Dmitry V. Levin | 66a15a5 | 2014-01-07 19:32:32 +0000 | [diff] [blame] | 1 | #include <assert.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <unistd.h> |
| 4 | #include <signal.h> |
| 5 | |
| 6 | static void handle_signal(int no) |
| 7 | { |
| 8 | _exit(128 + no); |
| 9 | } |
| 10 | |
| 11 | int |
| 12 | main(void) |
| 13 | { |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 14 | struct sigaction sa, sa0; |
Dmitry V. Levin | 66a15a5 | 2014-01-07 19:32:32 +0000 | [diff] [blame] | 15 | |
| 16 | sa.sa_handler = SIG_IGN; |
| 17 | sigemptyset(&sa.sa_mask); |
| 18 | sigaddset(&sa.sa_mask, SIGHUP); |
| 19 | sigaddset(&sa.sa_mask, SIGINT); |
| 20 | sa.sa_flags = SA_RESTART; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 21 | assert(!sigaction(SIGUSR2, &sa, &sa0)); |
Dmitry V. Levin | 66a15a5 | 2014-01-07 19:32:32 +0000 | [diff] [blame] | 22 | |
| 23 | sa.sa_handler = handle_signal; |
| 24 | sigemptyset(&sa.sa_mask); |
| 25 | sigaddset(&sa.sa_mask, SIGQUIT); |
| 26 | sigaddset(&sa.sa_mask, SIGTERM); |
| 27 | sa.sa_flags = SA_SIGINFO; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 28 | assert(!sigaction(SIGUSR2, &sa, &sa0)); |
Dmitry V. Levin | 66a15a5 | 2014-01-07 19:32:32 +0000 | [diff] [blame] | 29 | |
| 30 | sa.sa_handler = SIG_DFL; |
| 31 | sigemptyset(&sa.sa_mask); |
| 32 | sa.sa_flags = 0; |
Dmitry V. Levin | 38593e9 | 2014-02-26 16:51:28 +0000 | [diff] [blame] | 33 | assert(!sigaction(SIGUSR2, &sa, &sa0)); |
| 34 | |
| 35 | sigfillset(&sa.sa_mask); |
| 36 | sigdelset(&sa.sa_mask, SIGHUP); |
| 37 | assert(!sigaction(SIGUSR2, &sa, &sa0)); |
Dmitry V. Levin | 66a15a5 | 2014-01-07 19:32:32 +0000 | [diff] [blame] | 38 | |
| 39 | return 0; |
| 40 | } |