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