Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | /* Copyright 2016-2020 Free Software Foundation, Inc. |
f348d89a PA |
2 | |
3 | This file is part of GDB. | |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 3 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
18 | #include <stdlib.h> | |
19 | #include <stdio.h> | |
20 | #include <signal.h> | |
21 | #include <assert.h> | |
22 | #include <errno.h> | |
23 | ||
24 | #ifndef OUTPUT_TXT | |
25 | # define OUTPUT_TXT "output.txt" | |
26 | #endif | |
27 | ||
28 | static void | |
29 | perror_and_exit (const char *s) | |
30 | { | |
31 | perror (s); | |
32 | exit (1); | |
33 | } | |
34 | ||
35 | int | |
36 | main (int argc, char **argv) | |
37 | { | |
38 | int i; | |
39 | FILE *out; | |
40 | sigset_t sigset; | |
41 | int res; | |
42 | ||
43 | res = sigprocmask (0, NULL, &sigset); | |
44 | if (res != 0) | |
45 | perror_and_exit ("sigprocmask"); | |
46 | ||
47 | if (argc > 1) | |
48 | out = stdout; | |
49 | else | |
50 | { | |
51 | out = fopen (OUTPUT_TXT, "w"); | |
52 | if (out == NULL) | |
53 | perror_and_exit ("fopen"); | |
54 | } | |
55 | ||
56 | for (i = 1; i < NSIG; i++) | |
57 | { | |
58 | struct sigaction oldact; | |
59 | ||
60 | fprintf (out, "signal %d: ", i); | |
61 | ||
62 | res = sigaction (i, NULL, &oldact); | |
63 | if (res == -1 && errno == EINVAL) | |
64 | { | |
65 | /* Some signal numbers in the range are invalid. E.g., | |
66 | signals 32 and 33 on GNU/Linux. */ | |
67 | fprintf (out, "invalid"); | |
68 | } | |
69 | else if (res == -1) | |
70 | { | |
71 | perror_and_exit ("sigaction"); | |
72 | } | |
73 | else | |
74 | { | |
75 | int m; | |
76 | ||
7b17065f | 77 | fprintf (out, "sigaction={sa_handler="); |
f348d89a PA |
78 | |
79 | if (oldact.sa_handler == SIG_DFL) | |
80 | fprintf (out, "SIG_DFL"); | |
81 | else if (oldact.sa_handler == SIG_IGN) | |
82 | fprintf (out, "SIG_IGN"); | |
83 | else | |
84 | abort (); | |
85 | ||
86 | fprintf (out, ", sa_mask="); | |
87 | for (m = 1; m < NSIG; m++) | |
88 | fprintf (out, "%c", sigismember (&oldact.sa_mask, m) ? '1' : '0'); | |
89 | ||
90 | fprintf (out, ", sa_flags=%d", oldact.sa_flags); | |
91 | ||
92 | fprintf (out, "}, masked=%d", sigismember (&sigset, i)); | |
93 | } | |
94 | fprintf (out, "\n"); | |
95 | } | |
96 | ||
97 | if (out != stdout) | |
98 | fclose (out); | |
99 | ||
100 | return 0; | |
101 | } |