library: Move runtime signal count check to compile time
Since the value of number_of_signals is known at compile time, we can
use a compile-time check instead. This also adds SIGLOST for the Hurd,
uses the correct signal counts for the Hurd and FreeBSD, and only gives
a compile-time warning when compiled on an unknown platform that it does
not know whether the number of signals is correct.
Author: James Clarke <jrtc27@jrtc27.com>
References:
commit bd72ba3a4b
(jrtc27/procps-cross-platform)
procps-ng/procps~!52
This commit is contained in:
parent
55a42ae040
commit
98a5332de2
@ -34,8 +34,10 @@
|
||||
* You get SIGSTKFLT and SIGUNUSED instead on i386, m68k, ppc, and arm.
|
||||
* (this is a Linux & libc bug -- both must be fixed)
|
||||
*
|
||||
* Total garbage: SIGIO SIGINFO SIGIOT SIGLOST SIGCLD
|
||||
* Total garbage: SIGIO SIGINFO SIGIOT SIGCLD
|
||||
* (popular ones are handled as aliases)
|
||||
* SIGLOST
|
||||
* (except on the Hurd; reused to mean a server died)
|
||||
* Nearly garbage: SIGSTKFLT SIGUNUSED (nothing else to fill slots)
|
||||
*/
|
||||
|
||||
@ -50,6 +52,10 @@
|
||||
# undef SIGSTKFLT
|
||||
#endif
|
||||
|
||||
#if !defined(__GNU__) && defined(SIGLOST)
|
||||
# undef SIGLOST
|
||||
#endif
|
||||
|
||||
#ifndef SIGRTMIN
|
||||
# warning Standards require that <signal.h> define SIGRTMIN; assuming 32
|
||||
# define SIGRTMIN 32
|
||||
@ -81,6 +87,9 @@ static const mapstruct sigtable[] = {
|
||||
{"ILL", SIGILL},
|
||||
{"INT", SIGINT},
|
||||
{"KILL", SIGKILL},
|
||||
#ifdef SIGLOST
|
||||
{"LOST", SIGLOST}, /* Hurd-specific */
|
||||
#endif
|
||||
{"PIPE", SIGPIPE},
|
||||
{"POLL", SIGPOLL}, /* IO */
|
||||
{"PROF", SIGPROF},
|
||||
@ -108,7 +117,25 @@ static const mapstruct sigtable[] = {
|
||||
{"XFSZ", SIGXFSZ}
|
||||
};
|
||||
|
||||
const int number_of_signals = sizeof(sigtable)/sizeof(mapstruct);
|
||||
|
||||
#define number_of_signals (sizeof(sigtable)/sizeof(mapstruct))
|
||||
|
||||
#define XJOIN(a, b) JOIN(a, b)
|
||||
#define JOIN(a, b) a##b
|
||||
#define STATIC_ASSERT(x) typedef int XJOIN(static_assert_on_line_,__LINE__)[(x) ? 1 : -1]
|
||||
|
||||
/* sanity check */
|
||||
#if defined(__linux__)
|
||||
STATIC_ASSERT(number_of_signals == 31);
|
||||
#elif defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
|
||||
STATIC_ASSERT(number_of_signals == 30);
|
||||
#elif defined(__GNU__)
|
||||
STATIC_ASSERT(number_of_signals == 31);
|
||||
#elif defined(__CYGWIN__)
|
||||
STATIC_ASSERT(number_of_signals == 31);
|
||||
#else
|
||||
# warning Unknown operating system; assuming number_of_signals is correct
|
||||
#endif
|
||||
|
||||
static int compare_signal_names(const void *a, const void *b){
|
||||
return strcasecmp( ((const mapstruct*)a)->name, ((const mapstruct*)b)->name );
|
||||
|
Loading…
Reference in New Issue
Block a user