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 Free Software Foundation, Inc.
4 This file is part of GNU Make.
6 GNU Make is free software; you can redistribute it and/or modify it under the
7 terms of the GNU General Public License as published by the Free Software
8 Foundation; either version 2, or (at your option) any later version.
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 GNU Make; see the file COPYING. If not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */
20 /* If the system provides strsignal, we don't need it. */
24 /* If the system provides sys_siglist, we'll use that.
25 Otherwise create our own.
28 #if !HAVE_DECL_SYS_SIGLIST
30 /* Some systems do not define NSIG in <signal.h>. */
39 /* There is too much variation in Sys V signal numbers and names, so
40 we must initialize them at runtime. */
42 static const char *undoc
;
44 static const char *sys_siglist
[NSIG
];
46 /* Table of abbreviations for signals. Note: A given number can
47 appear more than once with different abbreviations. */
48 #define SIG_TABLE_SIZE (NSIG*2)
56 static num_abbrev sig_table
[SIG_TABLE_SIZE
];
58 /* Number of elements of sig_table used. */
59 static int sig_table_nelts
= 0;
61 /* Enter signal number NUMBER into the tables with ABBREV and NAME. */
64 init_sig (int number
, const char *abbrev
, const char *name
)
66 /* If this value is ever greater than NSIG it seems like it'd be a bug in
67 the system headers, but... better safe than sorry. We know, for
68 example, that this isn't always true on VMS. */
70 if (number
>= 0 && number
< NSIG
)
71 sys_siglist
[number
] = name
;
73 if (sig_table_nelts
< SIG_TABLE_SIZE
)
75 sig_table
[sig_table_nelts
].number
= number
;
76 sig_table
[sig_table_nelts
++].abbrev
= abbrev
;
85 undoc
= xstrdup (_("unknown signal"));
87 /* Initialize signal names. */
88 for (i
= 0; i
< NSIG
; i
++)
89 sys_siglist
[i
] = undoc
;
91 /* Initialize signal names. */
93 init_sig (SIGHUP
, "HUP", _("Hangup"));
96 init_sig (SIGINT
, "INT", _("Interrupt"));
99 init_sig (SIGQUIT
, "QUIT", _("Quit"));
102 init_sig (SIGILL
, "ILL", _("Illegal Instruction"));
104 #if defined (SIGTRAP)
105 init_sig (SIGTRAP
, "TRAP", _("Trace/breakpoint trap"));
107 /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
108 SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
109 #if defined (SIGABRT)
110 init_sig (SIGABRT
, "ABRT", _("Aborted"));
113 init_sig (SIGIOT
, "IOT", _("IOT trap"));
116 init_sig (SIGEMT
, "EMT", _("EMT trap"));
119 init_sig (SIGFPE
, "FPE", _("Floating point exception"));
121 #if defined (SIGKILL)
122 init_sig (SIGKILL
, "KILL", _("Killed"));
125 init_sig (SIGBUS
, "BUS", _("Bus error"));
127 #if defined (SIGSEGV)
128 init_sig (SIGSEGV
, "SEGV", _("Segmentation fault"));
131 init_sig (SIGSYS
, "SYS", _("Bad system call"));
133 #if defined (SIGPIPE)
134 init_sig (SIGPIPE
, "PIPE", _("Broken pipe"));
136 #if defined (SIGALRM)
137 init_sig (SIGALRM
, "ALRM", _("Alarm clock"));
139 #if defined (SIGTERM)
140 init_sig (SIGTERM
, "TERM", _("Terminated"));
142 #if defined (SIGUSR1)
143 init_sig (SIGUSR1
, "USR1", _("User defined signal 1"));
145 #if defined (SIGUSR2)
146 init_sig (SIGUSR2
, "USR2", _("User defined signal 2"));
148 /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
149 is what is in POSIX.1. */
150 #if defined (SIGCHLD)
151 init_sig (SIGCHLD
, "CHLD", _("Child exited"));
154 init_sig (SIGCLD
, "CLD", _("Child exited"));
157 init_sig (SIGPWR
, "PWR", _("Power failure"));
159 #if defined (SIGTSTP)
160 init_sig (SIGTSTP
, "TSTP", _("Stopped"));
162 #if defined (SIGTTIN)
163 init_sig (SIGTTIN
, "TTIN", _("Stopped (tty input)"));
165 #if defined (SIGTTOU)
166 init_sig (SIGTTOU
, "TTOU", _("Stopped (tty output)"));
168 #if defined (SIGSTOP)
169 init_sig (SIGSTOP
, "STOP", _("Stopped (signal)"));
171 #if defined (SIGXCPU)
172 init_sig (SIGXCPU
, "XCPU", _("CPU time limit exceeded"));
174 #if defined (SIGXFSZ)
175 init_sig (SIGXFSZ
, "XFSZ", _("File size limit exceeded"));
177 #if defined (SIGVTALRM)
178 init_sig (SIGVTALRM
, "VTALRM", _("Virtual timer expired"));
180 #if defined (SIGPROF)
181 init_sig (SIGPROF
, "PROF", _("Profiling timer expired"));
183 #if defined (SIGWINCH)
184 /* "Window size changed" might be more accurate, but even if that
185 is all that it means now, perhaps in the future it will be
186 extended to cover other kinds of window changes. */
187 init_sig (SIGWINCH
, "WINCH", _("Window changed"));
189 #if defined (SIGCONT)
190 init_sig (SIGCONT
, "CONT", _("Continued"));
193 init_sig (SIGURG
, "URG", _("Urgent I/O condition"));
196 /* "I/O pending" has also been suggested. A disadvantage is
197 that signal only happens when the process has
198 asked for it, not everytime I/O is pending. Another disadvantage
199 is the confusion from giving it a different name than under Unix. */
200 init_sig (SIGIO
, "IO", _("I/O possible"));
202 #if defined (SIGWIND)
203 init_sig (SIGWIND
, "WIND", _("SIGWIND"));
205 #if defined (SIGPHONE)
206 init_sig (SIGPHONE
, "PHONE", _("SIGPHONE"));
208 #if defined (SIGPOLL)
209 init_sig (SIGPOLL
, "POLL", _("I/O possible"));
211 #if defined (SIGLOST)
212 init_sig (SIGLOST
, "LOST", _("Resource lost"));
214 #if defined (SIGDANGER)
215 init_sig (SIGDANGER
, "DANGER", _("Danger signal"));
217 #if defined (SIGINFO)
218 init_sig (SIGINFO
, "INFO", _("Information request"));
220 #if defined (SIGNOFP)
221 init_sig (SIGNOFP
, "NOFP", _("Floating point co-processor not available"));
227 #endif /* HAVE_DECL_SYS_SIGLIST */
231 strsignal (int signal
)
233 static char buf
[] = "Signal 12345678901234567890";
235 #if ! HAVE_DECL_SYS_SIGLIST
236 # if HAVE_DECL__SYS_SIGLIST
237 # define sys_siglist _sys_siglist
238 # elif HAVE_DECL___SYS_SIGLIST
239 # define sys_siglist __sys_siglist
241 static char sig_initted
= 0;
244 sig_initted
= signame_init ();
248 if (signal
> 0 || signal
< NSIG
)
249 return (char *) sys_siglist
[signal
];
251 sprintf (buf
, "Signal %d", signal
);
255 #endif /* HAVE_STRSIGNAL */