Expand PMF_FN_* macros.
[netbsd-mini2440.git] / regress / lib / libpthread / sigmask2 / sigmask2.c
blobcd329396ff772c2a2099c493e5789c311efafaba
1 #include <stdio.h>
2 #include <signal.h>
3 #include <stdlib.h>
4 #include <unistd.h>
6 /* Test that signal masks are respected before threads are started */
7 volatile sig_atomic_t flag;
9 void handler1(int sig, siginfo_t *info, void *ctx);
10 void handler2(int sig, siginfo_t *info, void *ctx);
12 void
13 handler1(int sig, siginfo_t *info, void *ctx)
16 kill(getpid(), SIGUSR2);
18 * If the mask is properly set, SIGUSR2 will not be handled
19 * until this handler returns.
21 flag = 1;
24 void
25 handler2(int sig, siginfo_t *info, void *ctx)
27 if (flag == 1)
28 flag = 2;
31 int
32 main(void)
34 struct sigaction act;
35 int ret;
37 act.sa_sigaction = handler1;
38 sigemptyset(&act.sa_mask);
39 sigaddset(&act.sa_mask, SIGUSR2);
40 act.sa_flags = SA_SIGINFO;
42 ret = sigaction(SIGUSR1, &act, NULL);
43 if (ret) {
44 printf("sigaction: %d\n", ret);
45 exit(1);
48 act.sa_sigaction = handler2;
49 sigemptyset(&act.sa_mask);
50 act.sa_flags = SA_SIGINFO;
51 ret = sigaction(SIGUSR2, &act, NULL);
53 kill(getpid(), SIGUSR1);
55 if (flag == 2)
56 printf("Success: Both handlers ran in order\n");
57 else {
58 printf("Failure: flag was %d\n", (int)flag);
59 exit(1);
62 return 0;