From: Paul Eggert Date: Sun, 23 Aug 2020 21:59:15 +0000 (-0700) Subject: Simplify by using Gnulib sigdescr_np module X-Git-Tag: emacs-28.0.90~6438 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=df589d36817a8804d67f133890b2f453aefdf3c1;p=emacs.git Simplify by using Gnulib sigdescr_np module Inspired by a straightforward patch by Bruno Haible. * admin/merge-gnulib (GNULIB_MODULES): Add sigdescr_np. * configure.ac: Do not check for sys_siglist or __sys_siglist. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate. * lib/sigdescr_np.c, m4/sigdescr_np.m4: New files, copied from Gnulib. * src/sysdep.c (sys_siglist, sys_siglist_entries): Remove. (init_signals): Do not initialize sys_siglist. (safe_strsignal): Use sigdescr_np instead of sys_siglist. --- diff --git a/admin/CPP-DEFINES b/admin/CPP-DEFINES index ce9a44436d8..a40b4302723 100644 --- a/admin/CPP-DEFINES +++ b/admin/CPP-DEFINES @@ -124,9 +124,7 @@ HAVE_DECL_STRTOIMAX HAVE_DECL_STRTOLL HAVE_DECL_STRTOULL HAVE_DECL_STRTOUMAX -HAVE_DECL_SYS_SIGLIST HAVE_DECL_TZNAME -HAVE_DECL___SYS_SIGLIST HAVE_DIALOGS HAVE_DIFFTIME HAVE_DUP2 diff --git a/admin/merge-gnulib b/admin/merge-gnulib index 3f32536a629..164300e1db6 100755 --- a/admin/merge-gnulib +++ b/admin/merge-gnulib @@ -40,7 +40,7 @@ GNULIB_MODULES=' manywarnings memmem-simple mempcpy memrchr minmax mkostemp mktime nstrftime pathmax pipe2 pselect pthread_sigmask qcopy-acl readlink readlinkat regex - sig2str socklen stat-time std-gnu11 stdalign stddef stdio + sig2str sigdescr_np socklen stat-time std-gnu11 stdalign stddef stdio stpcpy strnlen strtoimax symlink sys_stat sys_time tempname time time_r time_rz timegm timer-time timespec-add timespec-sub update-copyright unlocked-io utimensat diff --git a/configure.ac b/configure.ac index ace1085284e..fb9aa19d6ee 100644 --- a/configure.ac +++ b/configure.ac @@ -1772,13 +1772,6 @@ dnl On Solaris 8 there's a compilation warning for term.h because dnl it doesn't define 'bool'. AC_CHECK_HEADERS(term.h, , , -) AC_HEADER_TIME -AC_CHECK_DECLS([sys_siglist], [], [], [[#include - ]]) -if test $ac_cv_have_decl_sys_siglist != yes; then - # For Tru64, at least: - AC_CHECK_DECLS([__sys_siglist], [], [], [[#include - ]]) -fi AC_HEADER_SYS_WAIT AC_CHECK_HEADERS_ONCE(sys/socket.h) diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in index 86eb14383c1..f564d501222 100644 --- a/lib/gnulib.mk.in +++ b/lib/gnulib.mk.in @@ -136,6 +136,7 @@ # readlinkat \ # regex \ # sig2str \ +# sigdescr_np \ # socklen \ # stat-time \ # std-gnu11 \ @@ -2314,6 +2315,17 @@ EXTRA_libgnu_a_SOURCES += sig2str.c endif ## end gnulib module sig2str +## begin gnulib module sigdescr_np +ifeq (,$(OMIT_GNULIB_MODULE_sigdescr_np)) + + +EXTRA_DIST += sigdescr_np.c + +EXTRA_libgnu_a_SOURCES += sigdescr_np.c + +endif +## end gnulib module sigdescr_np + ## begin gnulib module signal-h ifeq (,$(OMIT_GNULIB_MODULE_signal-h)) diff --git a/lib/sigdescr_np.c b/lib/sigdescr_np.c new file mode 100644 index 00000000000..fc9cd3c2369 --- /dev/null +++ b/lib/sigdescr_np.c @@ -0,0 +1,376 @@ +/* English descriptions of signals. + Copyright (C) 2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2020. */ + +#include + +/* Specification. */ +#include + +#include + +const char * +sigdescr_np (int sig) +{ + /* Note: Some platforms (glibc, FreeBSD, NetBSD, OpenBSD, AIX, IRIX, Haiku, + Android) have an array 'sys_siglist'. (On AIX, you need to declare it + yourself, and it has fewer than NSIG elements.) Its contents varies + depending on the OS. + On other OSes, you can invoke strsignal (sig) in the C locale. + In the code below, we show the differences. + You can see how cryptic some of these strings are. We try to pick more + understandable wordings. */ + + switch (sig) + { + /* Signals specified by ISO C. */ + case SIGABRT: + /* glibc: "Aborted". *BSD: "Abort trap". Solaris: "Abort". */ + return "Aborted"; + case SIGFPE: + /* glibc, *BSD: "Floating point exception". Solaris: "Arithmetic exception". + The latter is more correct, because of integer division by 0 or -1. */ + return "Arithmetic exception"; + case SIGILL: + return "Illegal instruction"; + case SIGINT: + return "Interrupt"; + case SIGSEGV: + return "Segmentation fault"; + case SIGTERM: + return "Terminated"; + + /* Signals specified by POSIX. + */ + #if defined SIGALRM + case SIGALRM: + return "Alarm clock"; + #endif + #if defined SIGBUS + case SIGBUS: + return "Bus error"; + #endif + #if defined SIGCHLD + case SIGCHLD: + /* glibc, *BSD: "Child exited". Solaris: "Child status changed". */ + return "Child stopped or exited"; + #endif + #if defined SIGCONT + case SIGCONT: + return "Continued"; + #endif + #if defined SIGHUP + case SIGHUP: + return "Hangup"; + #endif + #if defined SIGKILL + case SIGKILL: + return "Killed"; + #endif + #if defined SIGPIPE + case SIGPIPE: + return "Broken pipe"; + #endif + #if defined SIGQUIT + case SIGQUIT: + return "Quit"; + #endif + #if defined SIGSTOP + case SIGSTOP: + /* glibc, Solaris: "Stopped (signal)". *BSD: "Suspended (signal)". */ + return "Stopped (signal)"; + #endif + #if defined SIGTSTP + case SIGTSTP: + /* glibc: "Stopped". *BSD: "Suspended". Solaris: "Stopped (user)". */ + return "Stopped"; + #endif + #if defined SIGTTIN + case SIGTTIN: + return "Stopped (tty input)"; + #endif + #if defined SIGTTOU + case SIGTTOU: + return "Stopped (tty output)"; + #endif + #if defined SIGUSR1 + case SIGUSR1: + /* glibc, *BSD: "User defined signal 1". Solaris: "User signal 1". */ + return "User defined signal 1"; + #endif + #if defined SIGUSR2 + case SIGUSR2: + /* glibc, *BSD: "User defined signal 2". Solaris: "User signal 2". */ + return "User defined signal 2"; + #endif + #if defined SIGPOLL + case SIGPOLL: + /* glibc: "I/O possible". Solaris: "Pollable event". */ + return "I/O possible"; + #endif + #if defined SIGPROF + case SIGPROF: + return "Profiling timer expired"; + #endif + #if defined SIGSYS + case SIGSYS: + return "Bad system call"; + #endif + #if defined SIGTRAP + case SIGTRAP: + /* glibc, Solaris: "Trace/breakpoint trap". *BSD: "Trace/BPT trap". */ + return "Trace/breakpoint trap"; + #endif + #if defined SIGURG + case SIGURG: + /* glibc, *BSD: "Urgent I/O condition". Solaris: "Urgent socket condition". */ + return "Urgent I/O condition"; + #endif + #if defined SIGVTALRM + case SIGVTALRM: + return "Virtual timer expired"; + #endif + #if defined SIGXCPU + case SIGXCPU: + /* glibc, *BSD: "CPU time limit exceeded". Solaris: "Cpu limit exceeded". */ + return "CPU time limit exceeded"; + #endif + #if defined SIGXFSZ + case SIGXFSZ: + return "File size limit exceeded"; + #endif + + /* Other signals on other systems. */ + /* native Windows */ + #if defined SIGBREAK + case SIGBREAK: + return "Ctrl-Break"; + #endif + /* IRIX */ + #if defined SIGCKPT + case SIGCKPT: + return "Checkpoint"; /* See man 1 cpr, man 3C atcheckpoint */ + #endif + /* Linux, IRIX, Cygwin */ + #if defined SIGCLD && SIGCLD != SIGCHLD + case SIGCLD: + return "Child stopped or exited"; + #endif + /* AIX */ + #if defined SIGCPUFAIL + case SIGCPUFAIL: + /* AIX: "CPU failure predicted". */ + return "CPU going down"; /* See man bindprocessor */ + #endif + /* AIX */ + #if defined SIGDANGER + case SIGDANGER: + /* AIX: "Paging space low". */ + return "Swap space nearly exhausted"; + #endif + /* Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, AIX, IRIX, Cygwin, mingw */ + #if defined SIGEMT + case SIGEMT: + /* glibc/Hurd, *BSD: "EMT trap". Solaris: "Emulation trap". */ + return "Instruction emulation needed"; + #endif + /* Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix */ + #if defined SIGINFO + case SIGINFO: + return "Information request"; + #endif + /* Linux, Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, AIX, IRIX, Cygwin */ + #if defined SIGIO && SIGIO != SIGPOLL + case SIGIO: + return "I/O possible"; + #endif + /* Linux, IRIX, Cygwin, mingw */ + #if defined SIGIOT && SIGIOT != SIGABRT + case SIGIOT: + return "IOT instruction"; /* a PDP-11 instruction */ + #endif + /* AIX */ + #if defined SIGKAP + case SIGKAP: + /* Process must issue a KSKAPACK ioctl, or will be killed in 30 seconds. */ + /* AIX: "Monitor mode granted". */ + return "Keep Alive Poll"; + #endif + /* Haiku */ + #if defined SIGKILLTHR + case SIGKILLTHR: + return "Kill thread"; + #endif + /* Minix */ + #if defined SIGKMEM + case SIGKMEM: + return "Kernel memory request"; + #endif + /* Minix */ + #if defined SIGKMESS + case SIGKMESS: + return "Kernel message"; + #endif + /* Minix */ + #if defined SIGKSIG + case SIGKSIG: + return "Kernel signal"; + #endif + /* Minix */ + #if defined SIGKSIGSM + case SIGKSIGSM: + return "Kernel signal for signal manager"; + #endif + /* FreeBSD */ + #if defined SIGLIBRT + case SIGLIBRT: + return "Real-time library interrupt"; + #endif + /* Cygwin */ + #if defined SIGLOST && SIGLOST != SIGABRT && SIGLOST != SIGPWR + case SIGLOST: + /* Solaris: "Resource lost". */ + return "File lock lost"; + #endif + /* AIX */ + #if defined SIGMIGRATE + case SIGMIGRATE: + return "Process migration"; + #endif + /* AIX */ + #if defined SIGMSG + case SIGMSG: + /* AIX: "Input device data". */ + return "Message in the ring"; + #endif + /* ACM */ + #if defined SIGPLAN + case SIGPLAN: + return "Programming language anomaly"; + #endif + /* AIX */ + #if defined SIGPRE + case SIGPRE: + return "Programmed exception"; + #endif + /* IRIX */ + #if defined SIGPTINTR + case SIGPTINTR: + return "Pthread interrupt"; + #endif + /* IRIX */ + #if defined SIGPTRESCHED + case SIGPTRESCHED: + return "Pthread rescheduling"; + #endif + /* Linux, NetBSD, Minix, AIX, IRIX, Cygwin */ + #if defined SIGPWR + case SIGPWR: + /* glibc: "Power failure". NetBSD: "Power fail/restart". */ + return "Power failure"; + #endif + /* AIX */ + #if defined SIGRECONFIG + case SIGRECONFIG: + return "Dynamic logical partitioning changed"; + #endif + /* AIX */ + #if defined SIGRECOVERY + case SIGRECOVERY: + return "Kernel recovery"; + #endif + /* IRIX */ + #if defined SIGRESTART + case SIGRESTART: + return "Checkpoint restart"; /* See man 1 cpr, man 3C atrestart */ + #endif + /* AIX */ + #if defined SIGRETRACT + case SIGRETRACT: + /* AIX: "Monitor mode retracted". */ + return "Retracting Keep Alive Poll"; + #endif + /* AIX */ + #if defined SIGSAK + case SIGSAK: + /* AIX: "Secure attention". */ + return "Secure Attention Key"; + #endif + /* ACM */ + #if defined SIGSAM + case SIGSAM: + return "Symbolic computation failed"; + #endif + /* Minix */ + #if defined SIGSNDELAY + case SIGSNDELAY: + return "Done sending message"; + #endif + /* AIX */ + #if defined SIGSOUND + case SIGSOUND: + /* AIX: "Sound completed". */ + return "Sound configuration changed"; + #endif + /* Linux */ + #if defined SIGSTKFLT + case SIGSTKFLT: + return "Stack fault"; + #endif + /* AIX */ + #if defined SIGSYSERROR + case SIGSYSERROR: + return "Kernel error"; + #endif + /* AIX */ + #if defined SIGTALRM + case SIGTALRM: + return "Thread alarm clock"; + #endif + /* FreeBSD, OpenBSD */ + #if defined SIGTHR + case SIGTHR: + /* OpenBSD: "Thread AST". */ + return "Thread library interrupt"; + #endif + /* IRIX */ + #if defined SIGUME + case SIGUME: + return "Uncorrectable memory error"; + #endif + /* AIX */ + #if defined SIGVIRT + case SIGVIRT: + return "Virtual time alarm clock"; + #endif + /* AIX */ + #if defined SIGWAITING + case SIGWAITING: + /* AIX: "No runnable lwp". */ + return "Thread waiting"; + #endif + /* Linux, Mac OS X, FreeBSD, NetBSD, OpenBSD, Minix, AIX, IRIX, Cygwin, Haiku */ + #if defined SIGWINCH + case SIGWINCH: + /* glibc: "Window changed". *BSD: "Window size changed" or "Window size changes". */ + return "Window size changed"; + #endif + + default: + return NULL; + } +} diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4 index 5bfa1473edd..f3e2cc92853 100644 --- a/m4/gnulib-comp.m4 +++ b/m4/gnulib-comp.m4 @@ -145,6 +145,7 @@ AC_DEFUN([gl_EARLY], # Code from module regex: # Code from module root-uid: # Code from module sig2str: + # Code from module sigdescr_np: # Code from module signal-h: # Code from module snippet/_Noreturn: # Code from module snippet/arg-nonnull: @@ -424,6 +425,11 @@ AC_DEFUN([gl_INIT], AC_LIBOBJ([sig2str]) gl_PREREQ_SIG2STR fi + gl_FUNC_SIGDESCR_NP + if test $HAVE_SIGDESCR_NP = 0; then + AC_LIBOBJ([sigdescr_np]) + fi + gl_STRING_MODULE_INDICATOR([sigdescr_np]) gl_SIGNAL_H gl_TYPE_SOCKLEN_T gt_TYPE_SSIZE_T @@ -1059,6 +1065,7 @@ AC_DEFUN([gl_FILE_LIST], [ lib/sha512.h lib/sig2str.c lib/sig2str.h + lib/sigdescr_np.c lib/signal.in.h lib/stat-time.c lib/stat-time.h @@ -1191,6 +1198,7 @@ AC_DEFUN([gl_FILE_LIST], [ m4/sha256.m4 m4/sha512.m4 m4/sig2str.m4 + m4/sigdescr_np.m4 m4/signal_h.m4 m4/socklen.m4 m4/ssize_t.m4 diff --git a/m4/sigdescr_np.m4 b/m4/sigdescr_np.m4 new file mode 100644 index 00000000000..f0f3f979e83 --- /dev/null +++ b/m4/sigdescr_np.m4 @@ -0,0 +1,17 @@ +# sigdescr_np.m4 serial 1 +dnl Copyright (C) 2020 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_SIGDESCR_NP], +[ + dnl Persuade glibc to declare sigdescr_np(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS]) + AC_CHECK_FUNCS([sigdescr_np]) + if test $ac_cv_func_sigdescr_np = no; then + HAVE_SIGDESCR_NP=0 + fi +]) diff --git a/src/sysdep.c b/src/sysdep.c index a1050c4309a..e161172a79b 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -1761,24 +1761,6 @@ deliver_thread_signal (int sig, signal_handler_t handler) errno = old_errno; } -#if !HAVE_DECL_SYS_SIGLIST -# undef sys_siglist -# ifdef _sys_siglist -# define sys_siglist _sys_siglist -# elif HAVE_DECL___SYS_SIGLIST -# define sys_siglist __sys_siglist -# else -# define sys_siglist my_sys_siglist -static char const *sys_siglist[NSIG]; -# endif -#endif - -#ifdef _sys_nsig -# define sys_siglist_entries _sys_nsig -#else -# define sys_siglist_entries NSIG -#endif - /* Handle bus errors, invalid instruction, etc. */ static void handle_fatal_signal (int sig) @@ -1970,143 +1952,6 @@ init_signals (void) main_thread_id = pthread_self (); #endif -#if !HAVE_DECL_SYS_SIGLIST && !defined _sys_siglist - if (! initialized) - { - sys_siglist[SIGABRT] = "Aborted"; -# ifdef SIGAIO - sys_siglist[SIGAIO] = "LAN I/O interrupt"; -# endif - sys_siglist[SIGALRM] = "Alarm clock"; -# ifdef SIGBUS - sys_siglist[SIGBUS] = "Bus error"; -# endif -# ifdef SIGCHLD - sys_siglist[SIGCHLD] = "Child status changed"; -# endif -# ifdef SIGCONT - sys_siglist[SIGCONT] = "Continued"; -# endif -# ifdef SIGDANGER - sys_siglist[SIGDANGER] = "Swap space dangerously low"; -# endif -# ifdef SIGDGNOTIFY - sys_siglist[SIGDGNOTIFY] = "Notification message in queue"; -# endif -# ifdef SIGEMT - sys_siglist[SIGEMT] = "Emulation trap"; -# endif - sys_siglist[SIGFPE] = "Arithmetic exception"; -# ifdef SIGFREEZE - sys_siglist[SIGFREEZE] = "SIGFREEZE"; -# endif -# ifdef SIGGRANT - sys_siglist[SIGGRANT] = "Monitor mode granted"; -# endif - sys_siglist[SIGHUP] = "Hangup"; - sys_siglist[SIGILL] = "Illegal instruction"; - sys_siglist[SIGINT] = "Interrupt"; -# ifdef SIGIO - sys_siglist[SIGIO] = "I/O possible"; -# endif -# ifdef SIGIOINT - sys_siglist[SIGIOINT] = "I/O intervention required"; -# endif -# ifdef SIGIOT - sys_siglist[SIGIOT] = "IOT trap"; -# endif - sys_siglist[SIGKILL] = "Killed"; -# ifdef SIGLOST - sys_siglist[SIGLOST] = "Resource lost"; -# endif -# ifdef SIGLWP - sys_siglist[SIGLWP] = "SIGLWP"; -# endif -# ifdef SIGMSG - sys_siglist[SIGMSG] = "Monitor mode data available"; -# endif -# ifdef SIGPHONE - sys_siglist[SIGWIND] = "SIGPHONE"; -# endif - sys_siglist[SIGPIPE] = "Broken pipe"; -# ifdef SIGPOLL - sys_siglist[SIGPOLL] = "Pollable event occurred"; -# endif -# ifdef SIGPROF - sys_siglist[SIGPROF] = "Profiling timer expired"; -# endif -# ifdef SIGPTY - sys_siglist[SIGPTY] = "PTY I/O interrupt"; -# endif -# ifdef SIGPWR - sys_siglist[SIGPWR] = "Power-fail restart"; -# endif - sys_siglist[SIGQUIT] = "Quit"; -# ifdef SIGRETRACT - sys_siglist[SIGRETRACT] = "Need to relinquish monitor mode"; -# endif -# ifdef SIGSAK - sys_siglist[SIGSAK] = "Secure attention"; -# endif - sys_siglist[SIGSEGV] = "Segmentation violation"; -# ifdef SIGSOUND - sys_siglist[SIGSOUND] = "Sound completed"; -# endif -# ifdef SIGSTOP - sys_siglist[SIGSTOP] = "Stopped (signal)"; -# endif -# ifdef SIGSTP - sys_siglist[SIGSTP] = "Stopped (user)"; -# endif -# ifdef SIGSYS - sys_siglist[SIGSYS] = "Bad argument to system call"; -# endif - sys_siglist[SIGTERM] = "Terminated"; -# ifdef SIGTHAW - sys_siglist[SIGTHAW] = "SIGTHAW"; -# endif -# ifdef SIGTRAP - sys_siglist[SIGTRAP] = "Trace/breakpoint trap"; -# endif -# ifdef SIGTSTP - sys_siglist[SIGTSTP] = "Stopped (user)"; -# endif -# ifdef SIGTTIN - sys_siglist[SIGTTIN] = "Stopped (tty input)"; -# endif -# ifdef SIGTTOU - sys_siglist[SIGTTOU] = "Stopped (tty output)"; -# endif -# ifdef SIGURG - sys_siglist[SIGURG] = "Urgent I/O condition"; -# endif -# ifdef SIGUSR1 - sys_siglist[SIGUSR1] = "User defined signal 1"; -# endif -# ifdef SIGUSR2 - sys_siglist[SIGUSR2] = "User defined signal 2"; -# endif -# ifdef SIGVTALRM - sys_siglist[SIGVTALRM] = "Virtual timer expired"; -# endif -# ifdef SIGWAITING - sys_siglist[SIGWAITING] = "Process's LWPs are blocked"; -# endif -# ifdef SIGWINCH - sys_siglist[SIGWINCH] = "Window size changed"; -# endif -# ifdef SIGWIND - sys_siglist[SIGWIND] = "SIGWIND"; -# endif -# ifdef SIGXCPU - sys_siglist[SIGXCPU] = "CPU time limit exceeded"; -# endif -# ifdef SIGXFSZ - sys_siglist[SIGXFSZ] = "File size limit exceeded"; -# endif - } -#endif /* !HAVE_DECL_SYS_SIGLIST && !_sys_siglist */ - /* Don't alter signal handlers if dumping. On some machines, changing signal handlers sets static data that would make signals fail to work right when the dumped Emacs is run. */ @@ -2762,15 +2607,13 @@ renameat_noreplace (int srcfd, char const *src, int dstfd, char const *dst) #endif } -/* Like strsignal, except async-signal-safe, and this function typically +/* Like strsignal, except async-signal-safe, and this function returns a string in the C locale rather than the current locale. */ char const * safe_strsignal (int code) { - char const *signame = 0; + char const *signame = sigdescr_np (code); - if (0 <= code && code < sys_siglist_entries) - signame = sys_siglist[code]; if (! signame) signame = "Unknown signal";