Fix: Null pointer dereference in ldlex.l
[binutils-gdb.git] / gdb / testsuite / gdb.base / signals-state-child.c
blob4bcccdab067affdb803b1051a475cd0399cd42c5
1 /* Copyright 2016-2023 Free Software Foundation, Inc.
3 This file is part of GDB.
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.
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.
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/>. */
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <signal.h>
21 #include <assert.h>
22 #include <errno.h>
24 #ifndef OUTPUT_TXT
25 # define OUTPUT_TXT "output.txt"
26 #endif
28 static void
29 perror_and_exit (const char *s)
31 perror (s);
32 exit (1);
35 int
36 main (int argc, char **argv)
38 int i;
39 FILE *out;
40 sigset_t sigset;
41 int res;
43 res = sigprocmask (0, NULL, &sigset);
44 if (res != 0)
45 perror_and_exit ("sigprocmask");
47 if (argc > 1)
48 out = stdout;
49 else
51 out = fopen (OUTPUT_TXT, "w");
52 if (out == NULL)
53 perror_and_exit ("fopen");
56 for (i = 1; i < NSIG; i++)
58 struct sigaction oldact;
60 fprintf (out, "signal %d: ", i);
62 res = sigaction (i, NULL, &oldact);
63 if (res == -1 && errno == EINVAL)
65 /* Some signal numbers in the range are invalid. E.g.,
66 signals 32 and 33 on GNU/Linux. */
67 fprintf (out, "invalid");
69 else if (res == -1)
71 perror_and_exit ("sigaction");
73 else
75 int m;
77 fprintf (out, "sigaction={sa_handler=");
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 ();
86 fprintf (out, ", sa_mask=");
87 for (m = 1; m < NSIG; m++)
88 fprintf (out, "%c", sigismember (&oldact.sa_mask, m) ? '1' : '0');
90 fprintf (out, ", sa_flags=%d", oldact.sa_flags);
92 fprintf (out, "}, masked=%d", sigismember (&sigset, i));
94 fprintf (out, "\n");
97 if (out != stdout)
98 fclose (out);
100 return 0;