1 /* Convert between signal names and numbers.
2 Copyright (C) 1990-2013 Free Software Foundation, Inc.
3 This file is part of GNU Make.
5 GNU Make is free software; you can redistribute it and/or modify it under the
6 terms of the GNU General Public License as published by the Free Software
7 Foundation; either version 3 of the License, or (at your option) any later
10 GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License along with
15 this program. If not, see <http://www.gnu.org/licenses/>. */
19 /* If the system provides strsignal, we don't need it. */
23 /* If the system provides sys_siglist, we'll use that.
24 Otherwise create our own.
27 #if !HAVE_DECL_SYS_SIGLIST
29 /* Some systems do not define NSIG in <signal.h>. */
38 /* There is too much variation in Sys V signal numbers and names, so
39 we must initialize them at runtime. */
41 static const char *undoc;
43 static const char *sys_siglist[NSIG];
45 /* Table of abbreviations for signals. Note: A given number can
46 appear more than once with different abbreviations. */
47 #define SIG_TABLE_SIZE (NSIG*2)
55 static num_abbrev sig_table[SIG_TABLE_SIZE];
57 /* Number of elements of sig_table used. */
58 static int sig_table_nelts = 0;
60 /* Enter signal number NUMBER into the tables with ABBREV and NAME. */
63 init_sig (int number, const char *abbrev, const char *name)
65 /* If this value is ever greater than NSIG it seems like it'd be a bug in
66 the system headers, but... better safe than sorry. We know, for
67 example, that this isn't always true on VMS. */
69 if (number >= 0 && number < NSIG)
70 sys_siglist[number] = name;
72 if (sig_table_nelts < SIG_TABLE_SIZE)
74 sig_table[sig_table_nelts].number = number;
75 sig_table[sig_table_nelts++].abbrev = abbrev;
84 undoc = xstrdup (_("unknown signal"));
86 /* Initialize signal names. */
87 for (i = 0; i < NSIG; i++)
88 sys_siglist[i] = undoc;
90 /* Initialize signal names. */
92 init_sig (SIGHUP, "HUP", _("Hangup"));
95 init_sig (SIGINT, "INT", _("Interrupt"));
98 init_sig (SIGQUIT, "QUIT", _("Quit"));
101 init_sig (SIGILL, "ILL", _("Illegal Instruction"));
103 #if defined (SIGTRAP)
104 init_sig (SIGTRAP, "TRAP", _("Trace/breakpoint trap"));
106 /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
107 SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
108 #if defined (SIGABRT)
109 init_sig (SIGABRT, "ABRT", _("Aborted"));
112 init_sig (SIGIOT, "IOT", _("IOT trap"));
115 init_sig (SIGEMT, "EMT", _("EMT trap"));
118 init_sig (SIGFPE, "FPE", _("Floating point exception"));
120 #if defined (SIGKILL)
121 init_sig (SIGKILL, "KILL", _("Killed"));
124 init_sig (SIGBUS, "BUS", _("Bus error"));
126 #if defined (SIGSEGV)
127 init_sig (SIGSEGV, "SEGV", _("Segmentation fault"));
130 init_sig (SIGSYS, "SYS", _("Bad system call"));
132 #if defined (SIGPIPE)
133 init_sig (SIGPIPE, "PIPE", _("Broken pipe"));
135 #if defined (SIGALRM)
136 init_sig (SIGALRM, "ALRM", _("Alarm clock"));
138 #if defined (SIGTERM)
139 init_sig (SIGTERM, "TERM", _("Terminated"));
141 #if defined (SIGUSR1)
142 init_sig (SIGUSR1, "USR1", _("User defined signal 1"));
144 #if defined (SIGUSR2)
145 init_sig (SIGUSR2, "USR2", _("User defined signal 2"));
147 /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
148 is what is in POSIX.1. */
149 #if defined (SIGCHLD)
150 init_sig (SIGCHLD, "CHLD", _("Child exited"));
153 init_sig (SIGCLD, "CLD", _("Child exited"));
156 init_sig (SIGPWR, "PWR", _("Power failure"));
158 #if defined (SIGTSTP)
159 init_sig (SIGTSTP, "TSTP", _("Stopped"));
161 #if defined (SIGTTIN)
162 init_sig (SIGTTIN, "TTIN", _("Stopped (tty input)"));
164 #if defined (SIGTTOU)
165 init_sig (SIGTTOU, "TTOU", _("Stopped (tty output)"));
167 #if defined (SIGSTOP)
168 init_sig (SIGSTOP, "STOP", _("Stopped (signal)"));
170 #if defined (SIGXCPU)
171 init_sig (SIGXCPU, "XCPU", _("CPU time limit exceeded"));
173 #if defined (SIGXFSZ)
174 init_sig (SIGXFSZ, "XFSZ", _("File size limit exceeded"));
176 #if defined (SIGVTALRM)
177 init_sig (SIGVTALRM, "VTALRM", _("Virtual timer expired"));
179 #if defined (SIGPROF)
180 init_sig (SIGPROF, "PROF", _("Profiling timer expired"));
182 #if defined (SIGWINCH)
183 /* "Window size changed" might be more accurate, but even if that
184 is all that it means now, perhaps in the future it will be
185 extended to cover other kinds of window changes. */
186 init_sig (SIGWINCH, "WINCH", _("Window changed"));
188 #if defined (SIGCONT)
189 init_sig (SIGCONT, "CONT", _("Continued"));
192 init_sig (SIGURG, "URG", _("Urgent I/O condition"));
195 /* "I/O pending" has also been suggested. A disadvantage is that signal
196 only happens when the process has asked for it, not every time I/O is
197 pending. Another disadvantage is the confusion from giving it a
198 different name than under Unix. */
199 init_sig (SIGIO, "IO", _("I/O possible"));
201 #if defined (SIGWIND)
202 init_sig (SIGWIND, "WIND", _("SIGWIND"));
204 #if defined (SIGPHONE)
205 init_sig (SIGPHONE, "PHONE", _("SIGPHONE"));
207 #if defined (SIGPOLL)
208 init_sig (SIGPOLL, "POLL", _("I/O possible"));
210 #if defined (SIGLOST)
211 init_sig (SIGLOST, "LOST", _("Resource lost"));
213 #if defined (SIGDANGER)
214 init_sig (SIGDANGER, "DANGER", _("Danger signal"));
216 #if defined (SIGINFO)
217 init_sig (SIGINFO, "INFO", _("Information request"));
219 #if defined (SIGNOFP)
220 init_sig (SIGNOFP, "NOFP", _("Floating point co-processor not available"));
226 #endif /* HAVE_DECL_SYS_SIGLIST */
232 static char buf[] = "Signal 12345678901234567890";
234 #if ! HAVE_DECL_SYS_SIGLIST
235 # if HAVE_DECL__SYS_SIGLIST
236 # define sys_siglist _sys_siglist
237 # elif HAVE_DECL___SYS_SIGLIST
238 # define sys_siglist __sys_siglist
240 static char sig_initted = 0;
243 sig_initted = signame_init ();
247 if (sig > 0 && sig < NSIG)
248 return (char *) sys_siglist[sig];
250 sprintf (buf, "Signal %d", sig);
254 #endif /* HAVE_STRSIGNAL */