--- /dev/null
+/* 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 <https://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2020. */
+
+#include <config.h>
+
+/* Specification. */
+#include <string.h>
+
+#include <signal.h>
+
+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.
+ <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html> */
+ #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;
+ }
+}
errno = old_errno;
}
\f
-#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)
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. */
#endif
}
\f
-/* 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";