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
5 This file is part of GNU Make.
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
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.
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/>. */
21 /* If the system provides strsignal, we don't need it. */
25 /* If the system provides sys_siglist, we'll use that.
26 Otherwise create our own.
29 #if !HAVE_DECL_SYS_SIGLIST
31 /* Some systems do not define NSIG in <signal.h>. */
40 /* There is too much variation in Sys V signal numbers and names, so
41 we must initialize them at runtime. */
43 static const char *undoc
;
45 static const char *sys_siglist
[NSIG
];
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)
57 static num_abbrev sig_table
[SIG_TABLE_SIZE
];
59 /* Number of elements of sig_table used. */
60 static int sig_table_nelts
= 0;
62 /* Enter signal number NUMBER into the tables with ABBREV and NAME. */
65 init_sig (int number
, const char *abbrev
, const char *name
)
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. */
71 if (number
>= 0 && number
< NSIG
)
72 sys_siglist
[number
] = name
;
74 if (sig_table_nelts
< SIG_TABLE_SIZE
)
76 sig_table
[sig_table_nelts
].number
= number
;
77 sig_table
[sig_table_nelts
++].abbrev
= abbrev
;
86 undoc
= xstrdup (_("unknown signal"));
88 /* Initialize signal names. */
89 for (i
= 0; i
< NSIG
; i
++)
90 sys_siglist
[i
] = undoc
;
92 /* Initialize signal names. */
94 init_sig (SIGHUP
, "HUP", _("Hangup"));
97 init_sig (SIGINT
, "INT", _("Interrupt"));
100 init_sig (SIGQUIT
, "QUIT", _("Quit"));
103 init_sig (SIGILL
, "ILL", _("Illegal Instruction"));
105 #if defined (SIGTRAP)
106 init_sig (SIGTRAP
, "TRAP", _("Trace/breakpoint trap"));
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"));
114 init_sig (SIGIOT
, "IOT", _("IOT trap"));
117 init_sig (SIGEMT
, "EMT", _("EMT trap"));
120 init_sig (SIGFPE
, "FPE", _("Floating point exception"));
122 #if defined (SIGKILL)
123 init_sig (SIGKILL
, "KILL", _("Killed"));
126 init_sig (SIGBUS
, "BUS", _("Bus error"));
128 #if defined (SIGSEGV)
129 init_sig (SIGSEGV
, "SEGV", _("Segmentation fault"));
132 init_sig (SIGSYS
, "SYS", _("Bad system call"));
134 #if defined (SIGPIPE)
135 init_sig (SIGPIPE
, "PIPE", _("Broken pipe"));
137 #if defined (SIGALRM)
138 init_sig (SIGALRM
, "ALRM", _("Alarm clock"));
140 #if defined (SIGTERM)
141 init_sig (SIGTERM
, "TERM", _("Terminated"));
143 #if defined (SIGUSR1)
144 init_sig (SIGUSR1
, "USR1", _("User defined signal 1"));
146 #if defined (SIGUSR2)
147 init_sig (SIGUSR2
, "USR2", _("User defined signal 2"));
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"));
155 init_sig (SIGCLD
, "CLD", _("Child exited"));
158 init_sig (SIGPWR
, "PWR", _("Power failure"));
160 #if defined (SIGTSTP)
161 init_sig (SIGTSTP
, "TSTP", _("Stopped"));
163 #if defined (SIGTTIN)
164 init_sig (SIGTTIN
, "TTIN", _("Stopped (tty input)"));
166 #if defined (SIGTTOU)
167 init_sig (SIGTTOU
, "TTOU", _("Stopped (tty output)"));
169 #if defined (SIGSTOP)
170 init_sig (SIGSTOP
, "STOP", _("Stopped (signal)"));
172 #if defined (SIGXCPU)
173 init_sig (SIGXCPU
, "XCPU", _("CPU time limit exceeded"));
175 #if defined (SIGXFSZ)
176 init_sig (SIGXFSZ
, "XFSZ", _("File size limit exceeded"));
178 #if defined (SIGVTALRM)
179 init_sig (SIGVTALRM
, "VTALRM", _("Virtual timer expired"));
181 #if defined (SIGPROF)
182 init_sig (SIGPROF
, "PROF", _("Profiling timer expired"));
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"));
190 #if defined (SIGCONT)
191 init_sig (SIGCONT
, "CONT", _("Continued"));
194 init_sig (SIGURG
, "URG", _("Urgent I/O condition"));
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"));
203 #if defined (SIGWIND)
204 init_sig (SIGWIND
, "WIND", _("SIGWIND"));
206 #if defined (SIGPHONE)
207 init_sig (SIGPHONE
, "PHONE", _("SIGPHONE"));
209 #if defined (SIGPOLL)
210 init_sig (SIGPOLL
, "POLL", _("I/O possible"));
212 #if defined (SIGLOST)
213 init_sig (SIGLOST
, "LOST", _("Resource lost"));
215 #if defined (SIGDANGER)
216 init_sig (SIGDANGER
, "DANGER", _("Danger signal"));
218 #if defined (SIGINFO)
219 init_sig (SIGINFO
, "INFO", _("Information request"));
221 #if defined (SIGNOFP)
222 init_sig (SIGNOFP
, "NOFP", _("Floating point co-processor not available"));
228 #endif /* HAVE_DECL_SYS_SIGLIST */
234 static char buf
[] = "Signal 12345678901234567890";
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
242 static char sig_initted
= 0;
245 sig_initted
= signame_init ();
249 if (sig
> 0 || sig
< NSIG
)
250 return (char *) sys_siglist
[sig
];
252 sprintf (buf
, "Signal %d", sig
);
256 #endif /* HAVE_STRSIGNAL */