]>
Commit | Line | Data |
---|---|---|
8082d91e ZW |
1 | #! /bin/sh |
2 | # Test that glibc's signal numbers match the kernel's. | |
688903eb | 3 | # Copyright (C) 2017-2018 Free Software Foundation, Inc. |
8082d91e ZW |
4 | # This file is part of the GNU C Library. |
5 | ||
6 | # The GNU C Library is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU Lesser General Public | |
8 | # License as published by the Free Software Foundation; either | |
9 | # version 2.1 of the License, or (at your option) any later version. | |
10 | ||
11 | # The GNU C Library is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | # Lesser General Public License for more details. | |
15 | ||
16 | # You should have received a copy of the GNU Lesser General Public | |
17 | # License along with the GNU C Library; if not, see | |
18 | # <http://www.gnu.org/licenses/>. | |
19 | ||
20 | set -e | |
21 | if [ -n "$BASH_VERSION" ]; then set -o pipefail; fi | |
22 | LC_ALL=C; export LC_ALL | |
23 | ||
24 | # We cannot use Linux's asm/signal.h to define signal numbers, because | |
25 | # it isn't sufficiently namespace-clean. Instead, this test checks | |
26 | # that our signal numbers match the kernel's. This script expects | |
27 | # "$@" to be $(CC) $(CPPFLAGS) as set by glibc's Makefiles, and $AWK | |
28 | # to be set in the environment. | |
29 | ||
30 | # Before doing anything else, fail if the compiler doesn't work. | |
31 | "$@" -E -xc -dM - < /dev/null > /dev/null | |
32 | ||
33 | tmpG=`mktemp -t signums_glibc.XXXXXXXXX` | |
34 | tmpK=`mktemp -t signums_kernel.XXXXXXXXX` | |
35 | trap "rm -f '$tmpG' '$tmpK'" 0 | |
36 | ||
37 | # Filter out constants that aren't signal numbers. | |
38 | # If SIGPOLL is defined as SIGIO, swap it around so SIGIO is defined as | |
39 | # SIGPOLL. Similarly for SIGABRT and SIGIOT. | |
40 | # Discard obsolete signal numbers and unrelated constants: | |
41 | # SIGCLD, SIGIOT, SIGSWI, SIGUNUSED. | |
42 | # SIGSTKSZ, SIGRTMIN, SIGRTMAX. | |
43 | # Then sort the list. | |
44 | filter_defines () | |
45 | { | |
46 | $AWK ' | |
47 | /^#define SIG[A-Z]+ ([0-9]+|SIG[A-Z0-9]+)$/ { signals[$2] = $3 } | |
48 | END { | |
49 | if ("SIGPOLL" in signals && "SIGIO" in signals && | |
50 | signals["SIGPOLL"] == "SIGIO") { | |
51 | signals["SIGPOLL"] = signals["SIGIO"] | |
52 | signals["SIGIO"] = "SIGPOLL" | |
53 | } | |
54 | if ("SIGABRT" in signals && "SIGIOT" in signals && | |
55 | signals["SIGABRT"] == "SIGIOT") { | |
56 | signals["SIGABRT"] = signals["SIGIOT"] | |
57 | signals["SIGIOT"] = "SIGABRT" | |
58 | } | |
59 | for (sig in signals) { | |
60 | if (sig !~ /^SIG(CLD|IOT|RT(MIN|MAX)|STKSZ|SWI|UNUSED)$/) { | |
61 | printf("#define %s %s\n", sig, signals[sig]) | |
62 | } | |
63 | } | |
64 | }' | sort | |
65 | } | |
66 | ||
67 | # $CC may contain command-line switches, so it should be word-split. | |
68 | printf '%s' '#define _GNU_SOURCE 1 | |
69 | #include <signal.h> | |
70 | ' | | |
71 | "$@" -E -xc -dM - | | |
72 | filter_defines > "$tmpG" | |
73 | ||
74 | printf '%s' '#define _GNU_SOURCE 1 | |
75 | #define __ASSEMBLER__ 1 | |
76 | #include <asm/signal.h> | |
77 | ' | | |
78 | "$@" -E -xc -dM - | | |
79 | filter_defines > "$tmpK" | |
80 | ||
81 | if cmp -s "$tmpG" "$tmpK"; then | |
82 | exit 0 | |
83 | else | |
84 | diff -u "$tmpG" "$tmpK" | |
85 | exit 1 | |
86 | fi |