]>
Commit | Line | Data |
---|---|---|
28f540f4 RM |
1 | #include <signal.h> |
2 | #include <stdio.h> | |
3 | #include <stdlib.h> | |
4 | #include <string.h> | |
5 | ||
6 | int win = 0; | |
7 | ||
de149cdb | 8 | static void |
76b87c03 | 9 | handler (int sig) |
28f540f4 | 10 | { |
ebbad4cc | 11 | printf ("Received signal %d (%s).\n", sig, strsignal(sig)); |
28f540f4 RM |
12 | win = 1; |
13 | } | |
14 | ||
15 | int | |
ebbad4cc | 16 | main (void) |
28f540f4 | 17 | { |
ebbad4cc | 18 | if (signal (SIGTERM, handler) == SIG_ERR) |
28f540f4 | 19 | { |
ebbad4cc UD |
20 | perror ("signal: SIGTERM"); |
21 | exit (EXIT_FAILURE); | |
28f540f4 RM |
22 | } |
23 | ||
ebbad4cc | 24 | puts ("Set handler."); |
28f540f4 | 25 | |
ebbad4cc UD |
26 | printf ("Sending myself signal %d.\n", SIGTERM); |
27 | fflush (stdout); | |
28f540f4 | 28 | |
ebbad4cc | 29 | if (raise (SIGTERM) < 0) |
28f540f4 | 30 | { |
ebbad4cc UD |
31 | perror ("raise: SIGTERM"); |
32 | exit (EXIT_FAILURE); | |
28f540f4 RM |
33 | } |
34 | ||
35 | if (!win) | |
36 | { | |
ebbad4cc UD |
37 | puts ("Didn't get any signal. Test FAILED!"); |
38 | exit (EXIT_FAILURE); | |
28f540f4 RM |
39 | } |
40 | ||
ebbad4cc | 41 | puts ("Got a signal. Test succeeded."); |
bf4de8f3 AJ |
42 | |
43 | return EXIT_SUCCESS; | |
28f540f4 | 44 | } |