0.9.5.75:
[sbcl.git] / tools-for-build / sigaction-sa-nodefer-works-test.c
1 /*
2  * See if SA_NODEFER makes sigaction ignore sa_mask
3  * altogether. According to POSIX SA_NODEFER means: 'don't add the
4  * handler's signal to the mask'.
5  */
6
7 /*
8  * This software is part of the SBCL system. See the README file for
9  * more information.
10  *
11  * While most of SBCL is derived from the CMU CL system, many
12  * utilities for the build process (like this one) were written from
13  * scratch after the fork from CMU CL.
14  *
15  * This software is in the public domain and is provided with
16  * absolutely no warranty. See the COPYING and CREDITS files for
17  * more information.
18  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <signal.h>
24 #include <sys/types.h>
25 #include <sys/wait.h>
26 #include <unistd.h>
27
28 void
29 handler(int signal, siginfo_t *info, void *void_context)
30 {
31     sigset_t empty, current;
32     int i;
33     sigemptyset(&empty);
34     sigprocmask(SIG_BLOCK, &empty, &current);
35     for(i = 1; i < NSIG; i++)
36         if (sigismember(&current, i) != ((i == SIGABRT) ? 1 : 0))
37             exit(128 + i);
38     exit(104);
39 }
40
41 int
42 main (int argc, char *argv[])
43 {
44     struct sigaction sa;
45
46     sa.sa_flags = SA_SIGINFO | SA_NODEFER;
47     sa.sa_sigaction = handler;
48     sigemptyset(&sa.sa_mask);
49     sigaddset(&sa.sa_mask, SIGABRT);
50     sigaction(SIGTRAP, &sa, NULL);
51     kill(getpid(), SIGTRAP);
52     while (1) sleep(1);
53 }