1 #include <stdio.h>
2 #include <signal.h>
3 #include <unistd.h>
4 #include <stdlib.h>
5
6 static int sigalrm_received = 0;
sigalrm_handler(int signr)7 static void sigalrm_handler(int signr)
8 {
9 sigalrm_received++;
10 }
11 static int sigrtmin_received = 0;
sigrtmin_handler(int signr)12 static void sigrtmin_handler(int signr)
13 {
14 sigrtmin_received++;
15 }
16
17 static int breakme = 0;
18 #ifndef SIGRTMIN
19 // at least on MacOS, there is no SIGRTMIN.
20 // So, use any other signal instead.
21 #define SIGRTMIN SIGUSR1
22 #endif
23
main(int argc,char * argv[])24 int main (int argc, char *argv[])
25 {
26 struct sigaction sa;
27 fprintf(stderr, "starting ...\n");
28 sa.sa_handler = sigalrm_handler;
29 sigemptyset(&sa.sa_mask);
30 sa.sa_flags = 0;
31
32 if (sigaction (SIGALRM, &sa, NULL) != 0)
33 perror("sigaction");
34 if (kill(getpid(), SIGALRM) != 0)
35 perror("kill 1");
36
37 if (sigalrm_received == 1)
38 fprintf (stderr, "ok: 1st SIGALRM received\n");
39 else
40 fprintf (stderr, "wrong 1st: unexpected value %d sigalrm_received\n",
41 sigalrm_received);
42
43 if (kill(getpid(), SIGALRM) != 0)
44 perror("kill 2");
45
46 if (sigalrm_received == 2)
47 fprintf (stderr, "ok: 2nd SIGALRM received\n");
48 else
49 fprintf (stderr, "wrong 2nd: unexpected value %d sigalrm_received\n",
50 sigalrm_received);
51
52 system("../tests/true");
53 breakme++;
54
55 sa.sa_handler = sigrtmin_handler;
56 sigemptyset(&sa.sa_mask);
57 sa.sa_flags = 0;
58
59 if (sigaction (SIGRTMIN, &sa, NULL) != 0)
60 perror("sigaction");
61 if (kill(getpid(), SIGRTMIN) != 0)
62 perror("kill sigrtmin");
63 if (sigrtmin_received == 1)
64 fprintf (stderr, "ok: SIGRTMIN received\n");
65 else
66 fprintf (stderr, "wrong sigrtmin: unexpected value %d sigrtmin_received\n",
67 sigrtmin_received);
68 return 0;
69 }
70