1 | /* Convert between signal names and numbers.
|
---|
2 | Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
|
---|
3 | 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
|
---|
4 | Foundation, Inc.
|
---|
5 | This file is part of GNU Make.
|
---|
6 |
|
---|
7 | GNU Make is free software; you can redistribute it and/or modify it under the
|
---|
8 | terms of the GNU General Public License as published by the Free Software
|
---|
9 | Foundation; either version 3 of the License, or (at your option) any later
|
---|
10 | version.
|
---|
11 |
|
---|
12 | GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
|
---|
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
---|
14 | A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU General Public License along with
|
---|
17 | this program. If not, see <http://www.gnu.org/licenses/>. */
|
---|
18 |
|
---|
19 | #include "make.h"
|
---|
20 |
|
---|
21 | /* If the system provides strsignal, we don't need it. */
|
---|
22 |
|
---|
23 | #if !HAVE_STRSIGNAL
|
---|
24 |
|
---|
25 | /* If the system provides sys_siglist, we'll use that.
|
---|
26 | Otherwise create our own.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #if !HAVE_DECL_SYS_SIGLIST
|
---|
30 |
|
---|
31 | /* Some systems do not define NSIG in <signal.h>. */
|
---|
32 | #ifndef NSIG
|
---|
33 | #ifdef _NSIG
|
---|
34 | #define NSIG _NSIG
|
---|
35 | #else
|
---|
36 | #define NSIG 32
|
---|
37 | #endif
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | /* There is too much variation in Sys V signal numbers and names, so
|
---|
41 | we must initialize them at runtime. */
|
---|
42 |
|
---|
43 | static const char *undoc;
|
---|
44 |
|
---|
45 | static const char *sys_siglist[NSIG];
|
---|
46 |
|
---|
47 | /* Table of abbreviations for signals. Note: A given number can
|
---|
48 | appear more than once with different abbreviations. */
|
---|
49 | #define SIG_TABLE_SIZE (NSIG*2)
|
---|
50 |
|
---|
51 | typedef struct
|
---|
52 | {
|
---|
53 | int number;
|
---|
54 | const char *abbrev;
|
---|
55 | } num_abbrev;
|
---|
56 |
|
---|
57 | static num_abbrev sig_table[SIG_TABLE_SIZE];
|
---|
58 |
|
---|
59 | /* Number of elements of sig_table used. */
|
---|
60 | static int sig_table_nelts = 0;
|
---|
61 |
|
---|
62 | /* Enter signal number NUMBER into the tables with ABBREV and NAME. */
|
---|
63 |
|
---|
64 | static void
|
---|
65 | init_sig (int number, const char *abbrev, const char *name)
|
---|
66 | {
|
---|
67 | /* If this value is ever greater than NSIG it seems like it'd be a bug in
|
---|
68 | the system headers, but... better safe than sorry. We know, for
|
---|
69 | example, that this isn't always true on VMS. */
|
---|
70 |
|
---|
71 | if (number >= 0 && number < NSIG)
|
---|
72 | sys_siglist[number] = name;
|
---|
73 |
|
---|
74 | if (sig_table_nelts < SIG_TABLE_SIZE)
|
---|
75 | {
|
---|
76 | sig_table[sig_table_nelts].number = number;
|
---|
77 | sig_table[sig_table_nelts++].abbrev = abbrev;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | static int
|
---|
82 | signame_init (void)
|
---|
83 | {
|
---|
84 | int i;
|
---|
85 |
|
---|
86 | undoc = xstrdup (_("unknown signal"));
|
---|
87 |
|
---|
88 | /* Initialize signal names. */
|
---|
89 | for (i = 0; i < NSIG; i++)
|
---|
90 | sys_siglist[i] = undoc;
|
---|
91 |
|
---|
92 | /* Initialize signal names. */
|
---|
93 | #if defined (SIGHUP)
|
---|
94 | init_sig (SIGHUP, "HUP", _("Hangup"));
|
---|
95 | #endif
|
---|
96 | #if defined (SIGINT)
|
---|
97 | init_sig (SIGINT, "INT", _("Interrupt"));
|
---|
98 | #endif
|
---|
99 | #if defined (SIGQUIT)
|
---|
100 | init_sig (SIGQUIT, "QUIT", _("Quit"));
|
---|
101 | #endif
|
---|
102 | #if defined (SIGILL)
|
---|
103 | init_sig (SIGILL, "ILL", _("Illegal Instruction"));
|
---|
104 | #endif
|
---|
105 | #if defined (SIGTRAP)
|
---|
106 | init_sig (SIGTRAP, "TRAP", _("Trace/breakpoint trap"));
|
---|
107 | #endif
|
---|
108 | /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
|
---|
109 | SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
|
---|
110 | #if defined (SIGABRT)
|
---|
111 | init_sig (SIGABRT, "ABRT", _("Aborted"));
|
---|
112 | #endif
|
---|
113 | #if defined (SIGIOT)
|
---|
114 | init_sig (SIGIOT, "IOT", _("IOT trap"));
|
---|
115 | #endif
|
---|
116 | #if defined (SIGEMT)
|
---|
117 | init_sig (SIGEMT, "EMT", _("EMT trap"));
|
---|
118 | #endif
|
---|
119 | #if defined (SIGFPE)
|
---|
120 | init_sig (SIGFPE, "FPE", _("Floating point exception"));
|
---|
121 | #endif
|
---|
122 | #if defined (SIGKILL)
|
---|
123 | init_sig (SIGKILL, "KILL", _("Killed"));
|
---|
124 | #endif
|
---|
125 | #if defined (SIGBUS)
|
---|
126 | init_sig (SIGBUS, "BUS", _("Bus error"));
|
---|
127 | #endif
|
---|
128 | #if defined (SIGSEGV)
|
---|
129 | init_sig (SIGSEGV, "SEGV", _("Segmentation fault"));
|
---|
130 | #endif
|
---|
131 | #if defined (SIGSYS)
|
---|
132 | init_sig (SIGSYS, "SYS", _("Bad system call"));
|
---|
133 | #endif
|
---|
134 | #if defined (SIGPIPE)
|
---|
135 | init_sig (SIGPIPE, "PIPE", _("Broken pipe"));
|
---|
136 | #endif
|
---|
137 | #if defined (SIGALRM)
|
---|
138 | init_sig (SIGALRM, "ALRM", _("Alarm clock"));
|
---|
139 | #endif
|
---|
140 | #if defined (SIGTERM)
|
---|
141 | init_sig (SIGTERM, "TERM", _("Terminated"));
|
---|
142 | #endif
|
---|
143 | #if defined (SIGUSR1)
|
---|
144 | init_sig (SIGUSR1, "USR1", _("User defined signal 1"));
|
---|
145 | #endif
|
---|
146 | #if defined (SIGUSR2)
|
---|
147 | init_sig (SIGUSR2, "USR2", _("User defined signal 2"));
|
---|
148 | #endif
|
---|
149 | /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
|
---|
150 | is what is in POSIX.1. */
|
---|
151 | #if defined (SIGCHLD)
|
---|
152 | init_sig (SIGCHLD, "CHLD", _("Child exited"));
|
---|
153 | #endif
|
---|
154 | #if defined (SIGCLD)
|
---|
155 | init_sig (SIGCLD, "CLD", _("Child exited"));
|
---|
156 | #endif
|
---|
157 | #if defined (SIGPWR)
|
---|
158 | init_sig (SIGPWR, "PWR", _("Power failure"));
|
---|
159 | #endif
|
---|
160 | #if defined (SIGTSTP)
|
---|
161 | init_sig (SIGTSTP, "TSTP", _("Stopped"));
|
---|
162 | #endif
|
---|
163 | #if defined (SIGTTIN)
|
---|
164 | init_sig (SIGTTIN, "TTIN", _("Stopped (tty input)"));
|
---|
165 | #endif
|
---|
166 | #if defined (SIGTTOU)
|
---|
167 | init_sig (SIGTTOU, "TTOU", _("Stopped (tty output)"));
|
---|
168 | #endif
|
---|
169 | #if defined (SIGSTOP)
|
---|
170 | init_sig (SIGSTOP, "STOP", _("Stopped (signal)"));
|
---|
171 | #endif
|
---|
172 | #if defined (SIGXCPU)
|
---|
173 | init_sig (SIGXCPU, "XCPU", _("CPU time limit exceeded"));
|
---|
174 | #endif
|
---|
175 | #if defined (SIGXFSZ)
|
---|
176 | init_sig (SIGXFSZ, "XFSZ", _("File size limit exceeded"));
|
---|
177 | #endif
|
---|
178 | #if defined (SIGVTALRM)
|
---|
179 | init_sig (SIGVTALRM, "VTALRM", _("Virtual timer expired"));
|
---|
180 | #endif
|
---|
181 | #if defined (SIGPROF)
|
---|
182 | init_sig (SIGPROF, "PROF", _("Profiling timer expired"));
|
---|
183 | #endif
|
---|
184 | #if defined (SIGWINCH)
|
---|
185 | /* "Window size changed" might be more accurate, but even if that
|
---|
186 | is all that it means now, perhaps in the future it will be
|
---|
187 | extended to cover other kinds of window changes. */
|
---|
188 | init_sig (SIGWINCH, "WINCH", _("Window changed"));
|
---|
189 | #endif
|
---|
190 | #if defined (SIGCONT)
|
---|
191 | init_sig (SIGCONT, "CONT", _("Continued"));
|
---|
192 | #endif
|
---|
193 | #if defined (SIGURG)
|
---|
194 | init_sig (SIGURG, "URG", _("Urgent I/O condition"));
|
---|
195 | #endif
|
---|
196 | #if defined (SIGIO)
|
---|
197 | /* "I/O pending" has also been suggested. A disadvantage is
|
---|
198 | that signal only happens when the process has
|
---|
199 | asked for it, not everytime I/O is pending. Another disadvantage
|
---|
200 | is the confusion from giving it a different name than under Unix. */
|
---|
201 | init_sig (SIGIO, "IO", _("I/O possible"));
|
---|
202 | #endif
|
---|
203 | #if defined (SIGWIND)
|
---|
204 | init_sig (SIGWIND, "WIND", _("SIGWIND"));
|
---|
205 | #endif
|
---|
206 | #if defined (SIGPHONE)
|
---|
207 | init_sig (SIGPHONE, "PHONE", _("SIGPHONE"));
|
---|
208 | #endif
|
---|
209 | #if defined (SIGPOLL)
|
---|
210 | init_sig (SIGPOLL, "POLL", _("I/O possible"));
|
---|
211 | #endif
|
---|
212 | #if defined (SIGLOST)
|
---|
213 | init_sig (SIGLOST, "LOST", _("Resource lost"));
|
---|
214 | #endif
|
---|
215 | #if defined (SIGDANGER)
|
---|
216 | init_sig (SIGDANGER, "DANGER", _("Danger signal"));
|
---|
217 | #endif
|
---|
218 | #if defined (SIGINFO)
|
---|
219 | init_sig (SIGINFO, "INFO", _("Information request"));
|
---|
220 | #endif
|
---|
221 | #if defined (SIGNOFP)
|
---|
222 | init_sig (SIGNOFP, "NOFP", _("Floating point co-processor not available"));
|
---|
223 | #endif
|
---|
224 |
|
---|
225 | return 1;
|
---|
226 | }
|
---|
227 |
|
---|
228 | #endif /* HAVE_DECL_SYS_SIGLIST */
|
---|
229 |
|
---|
230 |
|
---|
231 | char *
|
---|
232 | strsignal (int sig)
|
---|
233 | {
|
---|
234 | static char buf[] = "Signal 12345678901234567890";
|
---|
235 |
|
---|
236 | #if ! HAVE_DECL_SYS_SIGLIST
|
---|
237 | # if HAVE_DECL__SYS_SIGLIST
|
---|
238 | # define sys_siglist _sys_siglist
|
---|
239 | # elif HAVE_DECL___SYS_SIGLIST
|
---|
240 | # define sys_siglist __sys_siglist
|
---|
241 | # else
|
---|
242 | static char sig_initted = 0;
|
---|
243 |
|
---|
244 | if (!sig_initted)
|
---|
245 | sig_initted = signame_init ();
|
---|
246 | # endif
|
---|
247 | #endif
|
---|
248 |
|
---|
249 | if (sig > 0 || sig < NSIG)
|
---|
250 | return (char *) sys_siglist[sig];
|
---|
251 |
|
---|
252 | sprintf (buf, "Signal %d", sig);
|
---|
253 | return buf;
|
---|
254 | }
|
---|
255 |
|
---|
256 | #endif /* HAVE_STRSIGNAL */
|
---|