initial import
[platform/upstream/glibc.git] / signal / tst-signal.c
1 #include <ansidecl.h>
2 #include <signal.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 int win = 0;
8
9 void
10 DEFUN(handler, (sig), int sig)
11 {
12   printf("Received signal %d (%s).\n", sig, strsignal(sig));
13   win = 1;
14 }
15
16 int
17 DEFUN_VOID(main)
18 {
19   if (signal(SIGTERM, handler) == SIG_ERR)
20     {
21       perror("signal: SIGTERM");
22       exit(EXIT_FAILURE);
23     }
24
25   puts("Set handler.");
26
27   printf("Sending myself signal %d.\n", SIGTERM);
28   fflush(stdout);
29
30   if (raise(SIGTERM) < 0)
31     {
32       perror("raise: SIGTERM");
33       exit(EXIT_FAILURE);
34     }
35
36   if (!win)
37     {
38       puts("Didn't get any signal.  Test FAILED!");
39       exit(EXIT_FAILURE);
40     }
41
42   puts("Got a signal.  Test succeeded.");
43   exit(EXIT_SUCCESS);
44 }