From patchwork Mon Jun 5 13:45:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zack Weinberg X-Patchwork-Id: 771272 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3whGMj5pxGz9s2G for ; Mon, 5 Jun 2017 23:47:13 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="j6KmfdU3"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; q=dns; s= default; b=gfHRhp7ebCz1JQUkv208/k2pXr59E4m++VaLBxwELgETwr1pPx1c2 ZNq3iHBLmzq5pEFJysbKzOPGBJ2WSYbxiCNhR3XaT1Xf8FmoUCyw2u430HmXD35h HVDu/pFBWwBBVdqKiCl37rR/KcVo2XTUrtzHcy5hYVq8VTxzH915Ko= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; s=default; bh=Zx1/GGE0zK4XzCsnAEYJFImklnk=; b=j6KmfdU3TdsJ0QT6RlPnHK9VjAfd Xag5GLeD4knfOZUMJY2koGial2RW39/3l9Kzt4rhWBLGvN4qPAN0yt+uUEmJZJMQ r6kCOELFrHMOjJOO2dq9qAnfC1bhInp+cozhUSmGsNa2yG0x4fai1RWi1RQ2AhEX Xt5+/Pc7VzC6AWM= Received: (qmail 37606 invoked by alias); 5 Jun 2017 13:46:03 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 26047 invoked by uid 89); 5 Jun 2017 13:45:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_PASS, UNSUBSCRIBE_BODY autolearn=ham version=3.3.2 spammy=EMT, emt, interactive, Urgent X-HELO: mailbackend.panix.com From: Zack Weinberg To: libc-alpha@sourceware.org Subject: [PATCH 5/5] Factor out shared definitions from bits/signum.h. Date: Mon, 5 Jun 2017 09:45:24 -0400 Message-Id: <20170605134524.6460-6-zackw@panix.com> In-Reply-To: <20170605134524.6460-1-zackw@panix.com> References: <20170605134524.6460-1-zackw@panix.com> MIME-Version: 1.0 Many of the things defined by bits/signum.h are invariant across all supported operating systems. This patch factors out all of them to a new header bits/signum-generic.h, which each bits/signum.h will include and then override whichever things need adjustment. Normally that will mean, at most, adding or changing a few signal numbers. A user-visible side effect is that the obsolete signal constants SIGSTKFLT and SIGUNUSED are no longer exposed by any version of bits/signum.h. (Fun fact: SIGEMT is still used by Linux/MIPS and /SPARC.) A side effect only relevant to glibc hackers is that _NSIG is now defined in terms of __SIGRTMAX, instead of the other way around. This is because __SIGRTMAX varies from platform to platform, but _NSIG==__SIGRTMAX+1 is true universally. If your platform doesn't support realtime signals, leave __SIGRTMAX equal to __SIGRTMIN. I also added a Linux-specific test to make sure that our signal constants match the ones in , since we can't use that header (it's not even vaguely namespace-clean). * bits/signum-generic.h: Renamed from bits/signum.h. Add proper multiple include guard and misuse check. Define __SIGRTMIN = __SIGRTMAX = 32, and define _NSIG = __SIGRTMAX + 1. Move definition of SIGIO to "archaic names for compatibility" section. * bits/signum.h: New file which just includes bits/signum-generic.h. * sysdeps/unix/bsd/bits/signum.h * sysdeps/unix/sysv/linux/bits/signum.h * sysdeps/unix/sysv/linux/alpha/bits/signum.h * sysdeps/unix/sysv/linux/hppa/bits/signum.h * sysdeps/unix/sysv/linux/mips/bits/signum.h * sysdeps/unix/sysv/linux/sparc/bits/signum.h Just include and then add or adjust signal constants. Do not define SIGSTKFLT, SIGUNUSED, SIGRTMIN, or SIGRTMAX. * signal/Makefile: Install bits/signum-generic.h. * signal/signal.h: Define SIGRTMIN and SIGRTMAX here. * sysdeps/generic/siglist.h: SIGSYS and SIGWINCH are universal. Prefer SIGPOLL to SIGIO. Simplify #ifdeffage. * sysdeps/unix/sysv/linux/tst-signal-numbers.sh: New test. * sysdeps/unix/sysv/linux/Makefile: Run it. --- NEWS | 4 + bits/signum-generic.h | 102 ++++++++++++++++++++++++ bits/signum.h | 72 +++-------------- signal/Makefile | 3 +- signal/signal.h | 3 + sysdeps/generic/siglist.h | 24 +++--- sysdeps/unix/bsd/bits/signum.h | 58 +++----------- sysdeps/unix/sysv/linux/Makefile | 14 ++++ sysdeps/unix/sysv/linux/alpha/bits/signum.h | 69 ++++------------ sysdeps/unix/sysv/linux/bits/signum.h | 82 +++++++------------ sysdeps/unix/sysv/linux/hppa/bits/signum.h | 109 +++++++++++--------------- sysdeps/unix/sysv/linux/mips/bits/signum.h | 94 ++++++++++------------ sysdeps/unix/sysv/linux/sparc/bits/signum.h | 70 +++-------------- sysdeps/unix/sysv/linux/tst-signal-numbers.sh | 69 ++++++++++++++++ 14 files changed, 371 insertions(+), 402 deletions(-) create mode 100644 bits/signum-generic.h create mode 100644 sysdeps/unix/sysv/linux/tst-signal-numbers.sh diff --git a/NEWS b/NEWS index eed2b10d82..96c323c59f 100644 --- a/NEWS +++ b/NEWS @@ -75,6 +75,10 @@ Version 2.26 * The port to Native Client running on ARMv7-A (--host=arm-nacl) has been removed. +* The obsolete signal constants SIGSTKFLT and SIGUNUSED are no longer + defined by . No supported version of the Linux kernel + generates these signals, on any architecture. + * The reallocarray function has been added to libc. It is a realloc replacement with a check for integer overflow when calculating total allocation size. diff --git a/bits/signum-generic.h b/bits/signum-generic.h new file mode 100644 index 0000000000..5a5683e753 --- /dev/null +++ b/bits/signum-generic.h @@ -0,0 +1,102 @@ +/* Signal number constants. Generic template. + Copyright (C) 1991-2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _BITS_SIGNUM_GENERIC_H +#define _BITS_SIGNUM_GENERIC_H 1 + +#ifndef _SIGNAL_H +#error "Never include directly; use instead." +#endif + +/* Fake signal functions. */ + +#define SIG_ERR ((__sighandler_t) -1) /* Error return. */ +#define SIG_DFL ((__sighandler_t) 0) /* Default action. */ +#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */ + +#ifdef __USE_XOPEN +# define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */ +#endif + +/* We define here all the signal names listed in POSIX (1003.1-2008); + as of 1003.1-2013, no additional signals have been added by POSIX. + We also define here signal names that historically exist in every + real-world POSIX variant (e.g. SIGWINCH). + + Signals in the 1-15 range are defined with their historical numbers. + For other signals, we use the BSD numbers. + There are two unallocated signal numbers in the 1-31 range: 7 and 29. + Signal number 0 is reserved for use as kill(pid, 0), to test whether + a process exists without sending it a signal. */ + +/* ISO C99 signals. */ +#define SIGINT 2 /* Interactive attention signal. */ +#define SIGILL 4 /* Illegal instruction. */ +#define SIGABRT 6 /* Abnormal termination. */ +#define SIGFPE 8 /* Erroneous arithmetic operation. */ +#define SIGSEGV 11 /* Invalid access to storage. */ +#define SIGTERM 15 /* Termination request. */ + +/* Historical signals specified by POSIX. */ +#define SIGHUP 1 /* Hangup. */ +#define SIGQUIT 3 /* Quit. */ +#define SIGTRAP 5 /* Trace/breakpoint trap. */ +#define SIGKILL 9 /* Killed. */ +#define SIGBUS 10 /* Bus error. */ +#define SIGSYS 12 /* Bad system call. */ +#define SIGPIPE 13 /* Broken pipe. */ +#define SIGALRM 14 /* Alarm clock. */ + +/* New(er) POSIX signals (1003.1-2008, 1003.1-2013). */ +#define SIGURG 16 /* Urgent data is available at a socket. */ +#define SIGSTOP 17 /* Stop, unblockable. */ +#define SIGTSTP 18 /* Keyboard stop. */ +#define SIGCONT 19 /* Continue. */ +#define SIGCHLD 20 /* Child terminated or stopped. */ +#define SIGTTIN 21 /* Background read from control terminal. */ +#define SIGTTOU 22 /* Background write to control terminal. */ +#define SIGPOLL 23 /* Pollable event occurred (System V). */ +#define SIGXCPU 24 /* CPU time limit exceeded. */ +#define SIGXFSZ 25 /* File size limit exceeded. */ +#define SIGVTALRM 26 /* Virtual timer expired. */ +#define SIGPROF 27 /* Profiling timer expired. */ +#define SIGUSR1 30 /* User-defined signal 1. */ +#define SIGUSR2 31 /* User-defined signal 2. */ + +/* Nonstandard signals found in all modern POSIX systems + (including both BSD and Linux). */ +#define SIGWINCH 28 /* Window size change (4.3 BSD, Sun). */ + +/* Archaic names for compatibility. */ +#define SIGIO SIGPOLL /* I/O now possible (4.2 BSD). */ +#define SIGIOT SIGABRT /* IOT instruction, abort() on a PDP-11. */ +#define SIGCLD SIGCHLD /* Old System V name */ + +/* Not all systems support real-time signals. bits/signum.h indicates + that they are supported by overriding __SIGRTMAX to a value greater + than __SIGRTMIN. These constants give the kernel-level hard limits, + but some real-time signals may be used internally by glibc. Do not + use these constants in application code; use SIGRTMIN and SIGRTMAX + (defined in signal.h) instead. */ +#define __SIGRTMIN 32 +#define __SIGRTMAX __SIGRTMIN + +/* Biggest signal number + 1 (including real-time signals). */ +#define _NSIG (__SIGRTMAX + 1) + +#endif /* bits/signum-generic.h. */ diff --git a/bits/signum.h b/bits/signum.h index cfbc7ac8bb..8d6d03c918 100644 --- a/bits/signum.h +++ b/bits/signum.h @@ -1,5 +1,5 @@ /* Signal number constants. Generic version. - Copyright (C) 1991-2017 Free Software Foundation, Inc. + Copyright (C) 2017 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -16,69 +16,17 @@ License along with the GNU C Library; if not, see . */ -#ifdef _SIGNAL_H +#ifndef _BITS_SIGNUM_H +#define _BITS_SIGNUM_H 1 -/* Fake signal functions. */ - -#define SIG_ERR ((__sighandler_t) -1) /* Error return. */ -#define SIG_DFL ((__sighandler_t) 0) /* Default action. */ -#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */ - -#ifdef __USE_XOPEN -# define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */ +#ifndef _SIGNAL_H +#error "Never include directly; use instead." #endif -/* We define here all the signal names listed in POSIX (1003.1-2008); - as of 1003.1-2013, no additional signals have been added by POSIX. - We also define here signal names that historically exist in every - real-world POSIX variant (e.g. SIGWINCH). +#include - Signals in the 1-15 range are defined with their historical numbers. - For other signals, we use the BSD numbers. */ +/* This operating system does not need to override any of the generic + signal number assignments in bits/signum-generic.h, nor to add any + additional signal constants. */ -/* ISO C99 signals. */ -#define SIGINT 2 /* Interactive attention signal. */ -#define SIGILL 4 /* Illegal instruction. */ -#define SIGABRT 6 /* Abnormal termination. */ -#define SIGFPE 8 /* Erroneous arithmetic operation. */ -#define SIGSEGV 11 /* Invalid access to storage. */ -#define SIGTERM 15 /* Termination request. */ - -/* Historical signals specified by POSIX. */ -#define SIGHUP 1 /* Hangup. */ -#define SIGQUIT 3 /* Quit. */ -#define SIGTRAP 5 /* Trace/breakpoint trap. */ -#define SIGKILL 9 /* Killed. */ -#define SIGBUS 10 /* Bus error. */ -#define SIGSYS 12 /* Bad system call. */ -#define SIGPIPE 13 /* Broken pipe. */ -#define SIGALRM 14 /* Alarm clock. */ - -/* New(er) POSIX signals (1003.1-2008, 1003.1-2013). */ -#define SIGURG 16 /* High bandwidth data is available at a socket. */ -#define SIGSTOP 17 /* Stopped (signal). */ -#define SIGTSTP 18 /* Stopped. */ -#define SIGCONT 19 /* Continued. */ -#define SIGCHLD 20 /* Child terminated or stopped. */ -#define SIGTTIN 21 /* Background read from control terminal. */ -#define SIGTTOU 22 /* Background write to control terminal. */ -#define SIGPOLL 23 /* Pollable event occurred (System V). */ -#define SIGIO SIGPOLL /* I/O now possible (4.2 BSD). */ -#define SIGXCPU 24 /* CPU time limit exceeded. */ -#define SIGXFSZ 25 /* File size limit exceeded. */ -#define SIGVTALRM 26 /* Virtual timer expired. */ -#define SIGPROF 27 /* Profiling timer expired. */ -#define SIGUSR1 30 /* User-defined signal 1. */ -#define SIGUSR2 31 /* User-defined signal 2. */ - -/* Nonstandard signals found in all modern POSIX systems - (including both BSD and Linux). */ -#define SIGWINCH 28 /* Window size change (4.3 BSD, Sun). */ - -#define _NSIG 32 - -/* Archaic names for compatibility. */ -#define SIGIOT SIGABRT /* IOT instruction, abort() on a PDP-11. */ -#define SIGCLD SIGCHLD /* Old System V name */ - -#endif /* included. */ +#endif /* bits/signum.h. */ diff --git a/signal/Makefile b/signal/Makefile index 9ce8232d43..8c9a7d1844 100644 --- a/signal/Makefile +++ b/signal/Makefile @@ -23,7 +23,8 @@ subdir := signal include ../Makeconfig headers := signal.h sys/signal.h \ - bits/signum.h bits/sigcontext.h bits/sigaction.h \ + bits/signum.h bits/signum-generic.h \ + bits/sigcontext.h bits/sigaction.h \ bits/sigevent-consts.h bits/siginfo-consts.h \ bits/sigstack.h bits/sigthread.h bits/ss_flags.h \ bits/types/__sigset_t.h bits/types/sig_atomic_t.h \ diff --git a/signal/signal.h b/signal/signal.h index b3114736a5..7181336f99 100644 --- a/signal/signal.h +++ b/signal/signal.h @@ -359,6 +359,9 @@ extern int __libc_current_sigrtmin (void) __THROW; /* Return number of available real-time signal with lowest priority. */ extern int __libc_current_sigrtmax (void) __THROW; +#define SIGRTMIN (__libc_current_sigrtmin ()) +#define SIGRTMAX (__libc_current_sigrtmax ()) + __END_DECLS #endif /* not signal.h */ diff --git a/sysdeps/generic/siglist.h b/sysdeps/generic/siglist.h index dd72929ed5..022be56059 100644 --- a/sysdeps/generic/siglist.h +++ b/sysdeps/generic/siglist.h @@ -24,7 +24,8 @@ /* This file is included multiple times. */ -/* Standard signals */ +/* Standard signals, in the numerical order defined in + bits/signum-generic.h. */ init_sig (SIGHUP, "HUP", N_("Hangup")) init_sig (SIGINT, "INT", N_("Interrupt")) init_sig (SIGQUIT, "QUIT", N_("Quit")) @@ -34,6 +35,7 @@ init_sig (SIGFPE, "FPE", N_("Floating point exception")) init_sig (SIGKILL, "KILL", N_("Killed")) init_sig (SIGBUS, "BUS", N_("Bus error")) + init_sig (SIGSYS, "SYS", N_("Bad system call")) init_sig (SIGSEGV, "SEGV", N_("Segmentation fault")) init_sig (SIGPIPE, "PIPE", N_("Broken pipe")) init_sig (SIGALRM, "ALRM", N_("Alarm clock")) @@ -45,32 +47,28 @@ init_sig (SIGCHLD, "CHLD", N_("Child exited")) init_sig (SIGTTIN, "TTIN", N_("Stopped (tty input)")) init_sig (SIGTTOU, "TTOU", N_("Stopped (tty output)")) - init_sig (SIGIO, "IO", N_("I/O possible")) + init_sig (SIGPOLL, "POLL", N_("I/O possible")) init_sig (SIGXCPU, "XCPU", N_("CPU time limit exceeded")) init_sig (SIGXFSZ, "XFSZ", N_("File size limit exceeded")) init_sig (SIGVTALRM, "VTALRM", N_("Virtual timer expired")) init_sig (SIGPROF, "PROF", N_("Profiling timer expired")) init_sig (SIGUSR1, "USR1", N_("User defined signal 1")) init_sig (SIGUSR2, "USR2", N_("User defined signal 2")) + init_sig (SIGWINCH, "WINCH", N_("Window changed")) -/* Variations */ +/* Signals that are not present on all supported platforms. */ #ifdef SIGEMT init_sig (SIGEMT, "EMT", N_("EMT trap")) #endif -#ifdef SIGSYS - init_sig (SIGSYS, "SYS", N_("Bad system call")) -#endif #ifdef SIGSTKFLT init_sig (SIGSTKFLT, "STKFLT", N_("Stack fault")) #endif -#ifdef SIGINFO - init_sig (SIGINFO, "INFO", N_("Information request")) -#elif defined(SIGPWR) && (!defined(SIGLOST) || (SIGPWR != SIGLOST)) +#ifdef SIGPWR init_sig (SIGPWR, "PWR", N_("Power failure")) #endif -#ifdef SIGLOST +#if defined SIGINFO && (!defined SIGPWR || SIGPWR != SIGINFO) + init_sig (SIGINFO, "INFO", N_("Information request")) +#endif +#if defined SIGLOST && (!defined SIGPWR || SIGPWR != SIGLOST) init_sig (SIGLOST, "LOST", N_("Resource lost")) #endif -#ifdef SIGWINCH - init_sig (SIGWINCH, "WINCH", N_("Window changed")) -#endif diff --git a/sysdeps/unix/bsd/bits/signum.h b/sysdeps/unix/bsd/bits/signum.h index 268c24a702..f55edc93a3 100644 --- a/sysdeps/unix/bsd/bits/signum.h +++ b/sysdeps/unix/bsd/bits/signum.h @@ -16,58 +16,20 @@ License along with the GNU C Library; if not, see . */ -#ifdef _SIGNAL_H +#ifndef _BITS_SIGNUM_H +#define _BITS_SIGNUM_H 1 -/* This file defines the fake signal functions and signal - number constants for 4.2 or 4.3 BSD-derived Unix system. */ - -/* Fake signal functions. */ -#define SIG_ERR ((__sighandler_t) -1) /* Error return. */ -#define SIG_DFL ((__sighandler_t) 0) /* Default action. */ -#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */ - -#ifdef __USE_XOPEN -# define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */ +#ifndef _SIGNAL_H +#error "Never include directly; use instead." #endif +#include -/* Signals. */ -#define SIGHUP 1 /* Hangup (POSIX). */ -#define SIGINT 2 /* Interrupt (ANSI). */ -#define SIGQUIT 3 /* Quit (POSIX). */ -#define SIGILL 4 /* Illegal instruction (ANSI). */ -#define SIGABRT SIGIOT /* Abort (ANSI). */ -#define SIGTRAP 5 /* Trace trap (POSIX). */ -#define SIGIOT 6 /* IOT trap (4.2 BSD). */ -#define SIGEMT 7 /* EMT trap (4.2 BSD). */ -#define SIGFPE 8 /* Floating-point exception (ANSI). */ -#define SIGKILL 9 /* Kill, unblockable (POSIX). */ -#define SIGBUS 10 /* Bus error (4.2 BSD). */ -#define SIGSEGV 11 /* Segmentation violation (ANSI). */ -#define SIGSYS 12 /* Bad argument to system call (4.2 BSD). */ -#define SIGPIPE 13 /* Broken pipe (POSIX). */ -#define SIGALRM 14 /* Alarm clock (POSIX). */ -#define SIGTERM 15 /* Termination (ANSI). */ -#define SIGURG 16 /* Urgent condition on socket (4.2 BSD). */ -#define SIGSTOP 17 /* Stop, unblockable (POSIX). */ -#define SIGTSTP 18 /* Keyboard stop (POSIX). */ -#define SIGCONT 19 /* Continue (POSIX). */ -#define SIGCHLD 20 /* Child status has changed (POSIX). */ -#define SIGCLD SIGCHLD /* Same as SIGCHLD (System V). */ -#define SIGTTIN 21 /* Background read from tty (POSIX). */ -#define SIGTTOU 22 /* Background write to tty (POSIX). */ -#define SIGIO 23 /* I/O now possible (4.2 BSD). */ -#define SIGPOLL SIGIO /* Same as SIGIO? (SVID). */ -#define SIGXCPU 24 /* CPU limit exceeded (4.2 BSD). */ -#define SIGXFSZ 25 /* File size limit exceeded (4.2 BSD). */ -#define SIGVTALRM 26 /* Virtual alarm clock (4.2 BSD). */ -#define SIGPROF 27 /* Profiling alarm clock (4.2 BSD). */ -#define SIGWINCH 28 /* Window size change (4.3 BSD, Sun). */ +/* Adjustments and additions to the signal number constants for + 4.2 or 4.3 BSD-derived Unix systems. */ + +#define SIGEMT 7 /* Emulator trap (4.2 BSD). */ #define SIGINFO 29 /* Information request (4.4 BSD). */ -#define SIGUSR1 30 /* User-defined signal 1 (POSIX). */ -#define SIGUSR2 31 /* User-defined signal 2 (POSIX). */ #define SIGLOST 32 /* Resource lost (Sun); server died (GNU). */ -#endif /* included. */ - -#define _NSIG 33 /* Biggest signal number + 1. */ +#endif /* bits/signum.h. */ diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 99b3f9d346..7ce5b38770 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -127,6 +127,20 @@ sysdep_headers += sys/timex.h bits/timex.h sysdep_routines += ntp_gettime ntp_gettimex endif +ifeq ($(subdir),signal) +tests-special += $(objpfx)tst-signal-numbers.out +# Depending on signal.o* is a hack. What we actually want is a dependency +# on signal.h and everything it includes. That's impractical to write +# in this context, but signal.c includes signal.h and not much else so it'll +# be conservatively correct. +$(objpfx)tst-signal-numbers.out: \ + ../sysdeps/unix/sysv/linux/tst-signal-numbers.sh \ + $(objpfx)signal.o* + AWK=$(AWK) $(SHELL) ../sysdeps/unix/sysv/linux/tst-signal-numbers.sh \ + $(CC) $(patsubst -DMODULE_NAME=%,-DMODULE_NAME=testsuite,$(CPPFLAGS)) \ + < /dev/null > $@; $(evaluate-test) +endif + ifeq ($(subdir),socket) sysdep_headers += net/if_ppp.h net/ppp-comp.h \ net/ppp_defs.h net/if_arp.h net/route.h net/ethernet.h \ diff --git a/sysdeps/unix/sysv/linux/alpha/bits/signum.h b/sysdeps/unix/sysv/linux/alpha/bits/signum.h index e5cc5218e3..8227be91b5 100644 --- a/sysdeps/unix/sysv/linux/alpha/bits/signum.h +++ b/sysdeps/unix/sysv/linux/alpha/bits/signum.h @@ -16,66 +16,25 @@ License along with the GNU C Library. If not, see . */ -#ifdef _SIGNAL_H +#ifndef _BITS_SIGNUM_H +#define _BITS_SIGNUM_H 1 -/* Fake signal functions. */ -#define SIG_ERR ((__sighandler_t) -1) /* Error return. */ -#define SIG_DFL ((__sighandler_t) 0) /* Default action. */ -#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */ - -#ifdef __USE_XOPEN -# define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */ +#ifndef _SIGNAL_H +#error "Never include directly; use instead." #endif -/* - * Linux/AXP has different signal numbers that Linux/i386: I'm trying - * to make it OSF/1 binary compatible, at least for normal binaries. - */ -#define SIGHUP 1 -#define SIGINT 2 -#define SIGQUIT 3 -#define SIGILL 4 -#define SIGTRAP 5 -#define SIGABRT 6 -#define SIGEMT 7 -#define SIGFPE 8 -#define SIGKILL 9 -#define SIGBUS 10 -#define SIGSEGV 11 -#define SIGSYS 12 -#define SIGPIPE 13 -#define SIGALRM 14 -#define SIGTERM 15 -#define SIGURG 16 -#define SIGSTOP 17 -#define SIGTSTP 18 -#define SIGCONT 19 -#define SIGCHLD 20 -#define SIGCLD SIGCHLD -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGIO 23 -#define SIGXCPU 24 -#define SIGXFSZ 25 -#define SIGVTALRM 26 -#define SIGPROF 27 -#define SIGWINCH 28 -#define SIGINFO 29 -#define SIGUSR1 30 -#define SIGUSR2 31 +#include -#define SIGPOLL SIGIO -#define SIGPWR SIGINFO -#define SIGIOT SIGABRT +/* Adjustments and additions to the signal number constants for + Linux/Alpha. Signal values on this platform were chosen for OSF/1 + binary compatibility, and are therefore almost identical to the + BSD-derived defaults. */ -#define _NSIG 65 /* Biggest signal number + 1. */ +#define SIGEMT 7 /* Emulator trap (4.2 BSD). */ +#define SIGINFO 29 /* Information request (BSD). */ +#define SIGPWR SIGINFO /* Power failure imminent (System V). */ -#define SIGRTMIN (__libc_current_sigrtmin ()) -#define SIGRTMAX (__libc_current_sigrtmax ()) - -/* These are the hard limits of the kernel. These values should not be - used directly at user level. */ -#define __SIGRTMIN 32 -#define __SIGRTMAX (_NSIG - 1) +#undef __SIGRTMAX +#define __SIGRTMAX 64 #endif /* included. */ diff --git a/sysdeps/unix/sysv/linux/bits/signum.h b/sysdeps/unix/sysv/linux/bits/signum.h index e30efead0d..42bf06c510 100644 --- a/sysdeps/unix/sysv/linux/bits/signum.h +++ b/sysdeps/unix/sysv/linux/bits/signum.h @@ -16,64 +16,42 @@ License along with the GNU C Library; if not, see . */ -#ifdef _SIGNAL_H +#ifndef _BITS_SIGNUM_H +#define _BITS_SIGNUM_H 1 -/* Fake signal functions. */ -#define SIG_ERR ((__sighandler_t) -1) /* Error return. */ -#define SIG_DFL ((__sighandler_t) 0) /* Default action. */ -#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */ - -#ifdef __USE_XOPEN -# define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */ +#ifndef _SIGNAL_H +#error "Never include directly; use instead." #endif +#include -/* Signals. */ -#define SIGHUP 1 /* Hangup (POSIX). */ -#define SIGINT 2 /* Interrupt (ANSI). */ -#define SIGQUIT 3 /* Quit (POSIX). */ -#define SIGILL 4 /* Illegal instruction (ANSI). */ -#define SIGTRAP 5 /* Trace trap (POSIX). */ -#define SIGABRT 6 /* Abort (ANSI). */ -#define SIGIOT 6 /* IOT trap (4.2 BSD). */ -#define SIGBUS 7 /* BUS error (4.2 BSD). */ -#define SIGFPE 8 /* Floating-point exception (ANSI). */ -#define SIGKILL 9 /* Kill, unblockable (POSIX). */ -#define SIGUSR1 10 /* User-defined signal 1 (POSIX). */ -#define SIGSEGV 11 /* Segmentation violation (ANSI). */ -#define SIGUSR2 12 /* User-defined signal 2 (POSIX). */ -#define SIGPIPE 13 /* Broken pipe (POSIX). */ -#define SIGALRM 14 /* Alarm clock (POSIX). */ -#define SIGTERM 15 /* Termination (ANSI). */ -#define SIGSTKFLT 16 /* Stack fault. */ -#define SIGCLD SIGCHLD /* Same as SIGCHLD (System V). */ -#define SIGCHLD 17 /* Child status has changed (POSIX). */ -#define SIGCONT 18 /* Continue (POSIX). */ -#define SIGSTOP 19 /* Stop, unblockable (POSIX). */ -#define SIGTSTP 20 /* Keyboard stop (POSIX). */ -#define SIGTTIN 21 /* Background read from tty (POSIX). */ -#define SIGTTOU 22 /* Background write to tty (POSIX). */ -#define SIGURG 23 /* Urgent condition on socket (4.2 BSD). */ -#define SIGXCPU 24 /* CPU limit exceeded (4.2 BSD). */ -#define SIGXFSZ 25 /* File size limit exceeded (4.2 BSD). */ -#define SIGVTALRM 26 /* Virtual alarm clock (4.2 BSD). */ -#define SIGPROF 27 /* Profiling alarm clock (4.2 BSD). */ -#define SIGWINCH 28 /* Window size change (4.3 BSD, Sun). */ -#define SIGPOLL SIGIO /* Pollable event occurred (System V). */ -#define SIGIO 29 /* I/O now possible (4.2 BSD). */ -#define SIGPWR 30 /* Power failure restart (System V). */ -#define SIGSYS 31 /* Bad system call. */ -#define SIGUNUSED 31 +/* Adjustments and additions to the signal number constants for + most Linux systems. */ -#define _NSIG 65 /* Biggest signal number + 1 - (including real-time signals). */ +#define SIGPWR 30 /* Power failure imminent. */ -#define SIGRTMIN (__libc_current_sigrtmin ()) -#define SIGRTMAX (__libc_current_sigrtmax ()) +#undef SIGBUS +#define SIGBUS 7 +#undef SIGUSR1 +#define SIGUSR1 10 +#undef SIGUSR2 +#define SIGUSR2 12 +#undef SIGCHLD +#define SIGCHLD 17 +#undef SIGCONT +#define SIGCONT 18 +#undef SIGSTOP +#define SIGSTOP 19 +#undef SIGTSTP +#define SIGTSTP 20 +#undef SIGURG +#define SIGURG 23 +#undef SIGPOLL +#define SIGPOLL 29 +#undef SIGSYS +#define SIGSYS 31 -/* These are the hard limits of the kernel. These values should not be - used directly at user level. */ -#define __SIGRTMIN 32 -#define __SIGRTMAX (_NSIG - 1) +#undef __SIGRTMAX +#define __SIGRTMAX 64 #endif /* included. */ diff --git a/sysdeps/unix/sysv/linux/hppa/bits/signum.h b/sysdeps/unix/sysv/linux/hppa/bits/signum.h index 20c0b60c9f..128b9a8287 100644 --- a/sysdeps/unix/sysv/linux/hppa/bits/signum.h +++ b/sysdeps/unix/sysv/linux/hppa/bits/signum.h @@ -16,74 +16,59 @@ License along with the GNU C Library. If not, see . */ -#ifdef _SIGNAL_H +#ifndef _BITS_SIGNUM_H +#define _BITS_SIGNUM_H 1 -/* Fake signal functions. */ -#define SIG_ERR ((__sighandler_t) -1) /* Error return. */ -#define SIG_DFL ((__sighandler_t) 0) /* Default action. */ -#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */ - -#ifdef __USE_XOPEN -# define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */ +#ifndef _SIGNAL_H +#error "Never include directly; use instead." #endif +#include -/* Signals. */ -#define SIGHUP 1 /* Hangup (POSIX). */ -#define SIGINT 2 /* Interrupt (ANSI). */ -#define SIGQUIT 3 /* Quit (POSIX). */ -#define SIGILL 4 /* Illegal instruction (ANSI). */ -#define SIGTRAP 5 /* Trace trap (POSIX). */ -#define SIGABRT 6 /* Abort (ANSI). */ -#define SIGIOT 6 /* IOT trap (4.2 BSD). */ -#define SIGSTKFLT 7 /* Stack fault. */ -#define SIGFPE 8 /* Floating-point exception (ANSI). */ -#define SIGKILL 9 /* Kill, unblockable (POSIX). */ -#define SIGBUS 10 /* BUS error (4.2 BSD). */ -#define SIGSEGV 11 /* Segmentation violation (ANSI). */ -#define SIGXCPU 12 /* CPU limit exceeded (4.2 BSD). */ -#define SIGPIPE 13 /* Broken pipe (POSIX). */ -#define SIGALRM 14 /* Alarm clock (POSIX). */ -#define SIGTERM 15 /* Termination (ANSI). */ -#define SIGUSR1 16 /* User-defined signal 1 (POSIX). */ -#define SIGUSR2 17 /* User-defined signal 2 (POSIX). */ -#define SIGCLD SIGCHLD /* Same as SIGCHLD (System V). */ -#define SIGCHLD 18 /* Child status has changed (POSIX). */ -#define SIGPWR 19 /* Power failure restart (System V). */ -#define SIGVTALRM 20 /* Virtual alarm clock (4.2 BSD). */ -#define SIGPROF 21 /* Profiling alarm clock (4.2 BSD). */ -#define SIGPOLL SIGIO /* Pollable event occurred (System V). */ -#define SIGIO 22 /* I/O now possible (4.2 BSD). */ -#define SIGWINCH 23 /* Window size change (4.3 BSD, Sun). */ -#define SIGSTOP 24 /* Stop, unblockable (POSIX). */ -#define SIGTSTP 25 /* Keyboard stop (POSIX). */ -#define SIGCONT 26 /* Continue (POSIX). */ -#define SIGTTIN 27 /* Background read from tty (POSIX). */ -#define SIGTTOU 28 /* Background write to tty (POSIX). */ -#define SIGURG 29 /* Urgent condition on socket (4.2 BSD). */ -#define SIGXFSZ 30 /* File size limit exceeded (4.2 BSD). */ -#define SIGSYS 31 /* Bad system call. */ -#define SIGUNUSED 31 +/* Adjustments and additions to the signal number constants for + Linux/HPPA. These values were originally chosen for HP/UX + compatibility, but were renumbered as of kernel 3.17 and glibc 2.21 + to accommodate software (notably systemd) that assumed at least 29 + real-time signal numbers would be available. SIGEMT and SIGLOST + were removed, and the values of SIGSTKFLT, SIGXCPU, XIGXFSZ, and + SIGSYS were changed, enabling __SIGRTMIN to be 32. */ -#define _NSIG 65 /* Biggest signal number + 1 - (including real-time signals). */ +#define SIGPWR 19 /* Power failure imminent. */ -#define SIGRTMIN (__libc_current_sigrtmin ()) -#define SIGRTMAX (__libc_current_sigrtmax ()) +#undef SIGXCPU +#define SIGXCPU 12 +#undef SIGUSR1 +#define SIGUSR1 16 +#undef SIGUSR2 +#define SIGUSR2 17 +#undef SIGCHLD +#define SIGCHLD 18 +#undef SIGVTALRM +#define SIGVTALRM 20 +#undef SIGPROF +#define SIGPROF 21 +#undef SIGPOLL +#define SIGPOLL 22 +#undef SIGWINCH +#define SIGWINCH 23 +#undef SIGSTOP +#define SIGSTOP 24 +#undef SIGTSTP +#define SIGTSTP 25 +#undef SIGCONT +#define SIGCONT 26 +#undef SIGTTIN +#define SIGTTIN 27 +#undef SIGTTOU +#define SIGTTOU 28 +#undef SIGURG +#define SIGURG 29 +#undef SIGXFSZ +#define SIGXFSZ 30 +#undef SIGSYS +#define SIGSYS 31 -/* These are the hard limits of the kernel. These values should not be - used directly at user level. */ -/* In the Linux kernel version 3.17, and glibc 2.21, the signal numbers - were rearranged in order to make hppa like every other arch. Previously - we started __SIGRTMIN at 37, and that meant several pieces of important - software, including systemd, would fail to build. To support systemd we - removed SIGEMT and SIGLOST, and rearranged the others according to - expected values. This is technically an ABI incompatible change, but - because zero applications use SIGSTKFLT, SIGXCPU, SIGXFSZ and SIGSYS - nothing broke. Nothing uses SIGEMT and SIGLOST, and they were present - for HPUX compatibility which is no longer supported. Thus because - nothing breaks we don't do any compatibility work here. */ -#define __SIGRTMIN 32 /* Kernel > 3.17. */ -#define __SIGRTMAX (_NSIG - 1) +#undef __SIGRTMAX +#define __SIGRTMAX 64 #endif /* included. */ diff --git a/sysdeps/unix/sysv/linux/mips/bits/signum.h b/sysdeps/unix/sysv/linux/mips/bits/signum.h index 6c31e01cd7..1672847212 100644 --- a/sysdeps/unix/sysv/linux/mips/bits/signum.h +++ b/sysdeps/unix/sysv/linux/mips/bits/signum.h @@ -1,4 +1,4 @@ -/* Signal number definitions. Linux version. +/* Signal number definitions. Linux/MIPS version. Copyright (C) 1995-2017 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -16,63 +16,53 @@ License along with the GNU C Library. If not, see . */ -#ifdef _SIGNAL_H +#ifndef _BITS_SIGNUM_H +#define _BITS_SIGNUM_H 1 -/* Fake signal functions. */ -#define SIG_ERR ((__sighandler_t) -1) /* Error return. */ -#define SIG_DFL ((__sighandler_t) 0) /* Default action. */ -#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */ - -#ifdef __USE_XOPEN -# define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */ +#ifndef _SIGNAL_H +#error "Never include directly; use instead." #endif +#include -#define SIGHUP 1 /* Hangup (POSIX). */ -#define SIGINT 2 /* Interrupt (ANSI). */ -#define SIGQUIT 3 /* Quit (POSIX). */ -#define SIGILL 4 /* Illegal instruction (ANSI). */ -#define SIGTRAP 5 /* Trace trap (POSIX). */ -#define SIGIOT 6 /* IOT trap (4.2 BSD). */ -#define SIGABRT SIGIOT /* Abort (ANSI). */ -#define SIGEMT 7 -#define SIGFPE 8 /* Floating-point exception (ANSI). */ -#define SIGKILL 9 /* Kill, unblockable (POSIX). */ -#define SIGBUS 10 /* BUS error (4.2 BSD). */ -#define SIGSEGV 11 /* Segmentation violation (ANSI). */ -#define SIGSYS 12 -#define SIGPIPE 13 /* Broken pipe (POSIX). */ -#define SIGALRM 14 /* Alarm clock (POSIX). */ -#define SIGTERM 15 /* Termination (ANSI). */ -#define SIGUSR1 16 /* User-defined signal 1 (POSIX). */ -#define SIGUSR2 17 /* User-defined signal 2 (POSIX). */ -#define SIGCHLD 18 /* Child status has changed (POSIX). */ -#define SIGCLD SIGCHLD /* Same as SIGCHLD (System V). */ -#define SIGPWR 19 /* Power failure restart (System V). */ -#define SIGWINCH 20 /* Window size change (4.3 BSD, Sun). */ -#define SIGURG 21 /* Urgent condition on socket (4.2 BSD). */ -#define SIGIO 22 /* I/O now possible (4.2 BSD). */ -#define SIGPOLL SIGIO /* Pollable event occurred (System V). */ -#define SIGSTOP 23 /* Stop, unblockable (POSIX). */ -#define SIGTSTP 24 /* Keyboard stop (POSIX). */ -#define SIGCONT 25 /* Continue (POSIX). */ -#define SIGTTIN 26 /* Background read from tty (POSIX). */ -#define SIGTTOU 27 /* Background write to tty (POSIX). */ -#define SIGVTALRM 28 /* Virtual alarm clock (4.2 BSD). */ -#define SIGPROF 29 /* Profiling alarm clock (4.2 BSD). */ -#define SIGXCPU 30 /* CPU limit exceeded (4.2 BSD). */ -#define SIGXFSZ 31 /* File size limit exceeded (4.2 BSD). */ +/* Adjustments and additions to the signal number constants for + Linux/MIPS. */ +#define SIGEMT 7 /* Emulator trap. */ +#define SIGPWR 19 /* Power failure imminent. */ -#define _NSIG 128 /* Biggest signal number + 1 - (including real-time signals). */ +#undef SIGUSR1 +#define SIGUSR1 16 +#undef SIGUSR2 +#define SIGUSR2 17 +#undef SIGCHLD +#define SIGCHLD 18 +#undef SIGWINCH +#define SIGWINCH 20 +#undef SIGURG +#define SIGURG 21 +#undef SIGPOLL +#define SIGPOLL 22 +#undef SIGSTOP +#define SIGSTOP 23 +#undef SIGTSTP +#define SIGTSTP 24 +#undef SIGCONT +#define SIGCONT 25 +#undef SIGTTIN +#define SIGTTIN 26 +#undef SIGTTOU +#define SIGTTOU 27 +#undef SIGVTALRM +#define SIGVTALRM 28 +#undef SIGPROF +#define SIGPROF 29 +#undef SIGXCPU +#define SIGXCPU 30 +#undef SIGXFSZ +#define SIGXFSZ 31 -#define SIGRTMIN (__libc_current_sigrtmin ()) -#define SIGRTMAX (__libc_current_sigrtmax ()) - -/* These are the hard limits of the kernel. These values should not be - used directly at user level. */ -#define __SIGRTMIN 32 -#define __SIGRTMAX (_NSIG - 1) +#undef __SIGRTMAX +#define __SIGRTMAX 127 #endif /* included. */ diff --git a/sysdeps/unix/sysv/linux/sparc/bits/signum.h b/sysdeps/unix/sysv/linux/sparc/bits/signum.h index a0c5be5fa5..25341ee42b 100644 --- a/sysdeps/unix/sysv/linux/sparc/bits/signum.h +++ b/sysdeps/unix/sysv/linux/sparc/bits/signum.h @@ -16,68 +16,24 @@ License along with the GNU C Library; if not, see . */ -#ifdef _SIGNAL_H +#ifndef _BITS_SIGNUM_H +#define _BITS_SIGNUM_H 1 -/* Fake signal functions. */ -#define SIG_ERR ((__sighandler_t) -1) /* Error return. */ -#define SIG_DFL ((__sighandler_t) 0) /* Default action. */ -#define SIG_IGN ((__sighandler_t) 1) /* Ignore signal. */ - -#ifdef __USE_XOPEN -# define SIG_HOLD ((__sighandler_t) 2) /* Add signal to hold mask. */ +#ifndef _SIGNAL_H +#error "Never include directly; use instead." #endif -/* - * Linux/SPARC has different signal numbers that Linux/i386: I'm trying - * to make it OSF/1 binary compatible, at least for normal binaries. - */ -#define SIGHUP 1 -#define SIGINT 2 -#define SIGQUIT 3 -#define SIGILL 4 -#define SIGTRAP 5 -#define SIGABRT 6 -#define SIGIOT 6 -#define SIGEMT 7 -#define SIGFPE 8 -#define SIGKILL 9 -#define SIGBUS 10 -#define SIGSEGV 11 -#define SIGSYS 12 -#define SIGPIPE 13 -#define SIGALRM 14 -#define SIGTERM 15 -#define SIGURG 16 +#include -/* SunOS values which deviate from the Linux/i386 ones */ -#define SIGSTOP 17 -#define SIGTSTP 18 -#define SIGCONT 19 -#define SIGCHLD 20 -#define SIGCLD SIGCHLD /* Same as SIGCHLD (System V). */ -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGIO 23 -#define SIGPOLL SIGIO /* SysV name for SIGIO */ -#define SIGXCPU 24 -#define SIGXFSZ 25 -#define SIGVTALRM 26 -#define SIGPROF 27 -#define SIGWINCH 28 -#define SIGLOST 29 -#define SIGPWR SIGLOST -#define SIGUSR1 30 -#define SIGUSR2 31 +/* Adjustments and additions to the signal number constants for + Linux/SPARC systems. Signal values on this platform were chosen + for SunOS binary compatibility. */ -#define _NSIG 65 /* Biggest signal number + 1 - (including real-time signals). */ +#define SIGEMT 7 /* Emulator trap. */ +#define SIGLOST 29 /* Resource lost (Sun); server died (GNU). */ +#define SIGPWR SIGLOST /* Power failure imminent (SysV). */ -#define SIGRTMIN (__libc_current_sigrtmin ()) -#define SIGRTMAX (__libc_current_sigrtmax ()) - -/* These are the hard limits of the kernel. These values should not be - used directly at user level. */ -#define __SIGRTMIN 32 -#define __SIGRTMAX (_NSIG - 1) +#undef __SIGRTMAX +#define __SIGRTMAX 64 #endif /* included. */ diff --git a/sysdeps/unix/sysv/linux/tst-signal-numbers.sh b/sysdeps/unix/sysv/linux/tst-signal-numbers.sh new file mode 100644 index 0000000000..55dd3ddd89 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-signal-numbers.sh @@ -0,0 +1,69 @@ +#! /bin/sh + +set -e +if [ -n "$BASH_VERSION" ]; then set -o pipefail; fi +LC_ALL=C; export LC_ALL + +# We cannot use Linux's asm/signal.h to define signal numbers, because +# it isn't sufficiently namespace-clean. Instead, this test checks +# that our signal numbers match the kernel's. This script expects +# "$@" to be $(CC) $(CPPFLAGS) as set by glibc's Makefiles, and $AWK +# to be set in the environment. + +# Before doing anything else, fail if the compiler doesn't work. +"$@" -E -xc -dM - < /dev/null > /dev/null + +tmpG=`mktemp -t signums_glibc.XXXXXXXXX` +tmpK=`mktemp -t signums_kernel.XXXXXXXXX` +trap "rm -f '$tmpG' '$tmpK'" 0 + +# Filter out constants that aren't signal numbers. +# If SIGPOLL is defined as SIGIO, swap it around so SIGIO is defined as +# SIGPOLL. Similarly for SIGABRT and SIGIOT. +# Discard obsolete signal numbers and unrelated constants: +# SIGCLD, SIGIOT, SIGSTKFLT, SIGSWI, SIGUNUSED. +# SIGSTKSZ, SIGRTMIN, SIGRTMAX. +# Then sort the list. +filter_defines () +{ + $AWK ' +/^#define SIG[A-Z]+ ([0-9]+|SIG[A-Z0-9]+)$/ { signals[$2] = $3 } +END { + if ("SIGPOLL" in signals && "SIGIO" in signals && + signals["SIGPOLL"] == "SIGIO") { + signals["SIGPOLL"] = signals["SIGIO"] + signals["SIGIO"] = "SIGPOLL" + } + if ("SIGABRT" in signals && "SIGIOT" in signals && + signals["SIGABRT"] == "SIGIOT") { + signals["SIGABRT"] = signals["SIGIOT"] + signals["SIGIOT"] = "SIGABRT" + } + for (sig in signals) { + if (sig !~ /^SIG(CLD|IOT|RT(MIN|MAX)|STK(FLT|SZ)|SWI|UNUSED)$/) { + printf("#define %s %s\n", sig, signals[sig]) + } + } +}' | sort +} + +# $CC may contain command-line switches, so it should be word-split. +printf '%s' '#define _GNU_SOURCE 1 +#include +' | + "$@" -E -xc -dM - | + filter_defines > "$tmpG" + +printf '%s' '#define _GNU_SOURCE 1 +#define __ASSEMBLER__ 1 +#include +' | + "$@" -E -xc -dM - | + filter_defines > "$tmpK" + +if cmp -s "$tmpG" "$tmpK"; then + exit 0 +else + diff -u "$tmpG" "$tmpK" + exit 1 +fi