1 /* Convert between signal names and numbers.
2 Copyright (C) 1990,92,93,95,96,99 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
21 /* In the GNU make version, all the headers we need are provided by make.h. */
25 /* Some systems do not define NSIG in <signal.h>. */
40 #ifndef HAVE_SYS_SIGLIST
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 const char *sys_siglist
[NSIG
];
48 #else /* HAVE_SYS_SIGLIST. */
50 #ifndef SYS_SIGLIST_DECLARED
51 extern char *sys_siglist
[];
52 #endif /* Not SYS_SIGLIST_DECLARED. */
54 #endif /* Not HAVE_SYS_SIGLIST. */
56 /* Table of abbreviations for signals. Note: A given number can
57 appear more than once with different abbreviations. */
58 #define SIG_TABLE_SIZE (NSIG*2)
65 static num_abbrev sig_table
[SIG_TABLE_SIZE
];
66 /* Number of elements of sig_table used. */
67 static int sig_table_nelts
= 0;
69 /* Enter signal number NUMBER into the tables with ABBREV and NAME. */
72 init_sig (number
, abbrev
, name
)
77 #ifndef HAVE_SYS_SIGLIST
78 /* If this value is ever greater than NSIG it seems like it'd be a bug in
79 the system headers, but... better safe than sorry. We know, for
80 example, that this isn't always true on VMS. */
82 if (number
>= 0 && number
< NSIG
)
83 sys_siglist
[number
] = name
;
85 if (sig_table_nelts
< SIG_TABLE_SIZE
)
87 sig_table
[sig_table_nelts
].number
= number
;
88 sig_table
[sig_table_nelts
++].abbrev
= abbrev
;
95 #ifndef HAVE_SYS_SIGLIST
97 char *u
= _("unknown signal");
101 /* Initialize signal names. */
102 for (i
= 0; i
< NSIG
; i
++)
103 sys_siglist
[i
] = undoc
;
104 #endif /* !HAVE_SYS_SIGLIST */
106 /* Initialize signal names. */
108 init_sig (SIGHUP
, "HUP", _("Hangup"));
111 init_sig (SIGINT
, "INT", _("Interrupt"));
113 #if defined (SIGQUIT)
114 init_sig (SIGQUIT
, "QUIT", _("Quit"));
117 init_sig (SIGILL
, "ILL", _("Illegal Instruction"));
119 #if defined (SIGTRAP)
120 init_sig (SIGTRAP
, "TRAP", _("Trace/breakpoint trap"));
122 /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
123 SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
124 #if defined (SIGABRT)
125 init_sig (SIGABRT
, "ABRT", _("Aborted"));
128 init_sig (SIGIOT
, "IOT", _("IOT trap"));
131 init_sig (SIGEMT
, "EMT", _("EMT trap"));
134 init_sig (SIGFPE
, "FPE", _("Floating point exception"));
136 #if defined (SIGKILL)
137 init_sig (SIGKILL
, "KILL", _("Killed"));
140 init_sig (SIGBUS
, "BUS", _("Bus error"));
142 #if defined (SIGSEGV)
143 init_sig (SIGSEGV
, "SEGV", _("Segmentation fault"));
146 init_sig (SIGSYS
, "SYS", _("Bad system call"));
148 #if defined (SIGPIPE)
149 init_sig (SIGPIPE
, "PIPE", _("Broken pipe"));
151 #if defined (SIGALRM)
152 init_sig (SIGALRM
, "ALRM", _("Alarm clock"));
154 #if defined (SIGTERM)
155 init_sig (SIGTERM
, "TERM", _("Terminated"));
157 #if defined (SIGUSR1)
158 init_sig (SIGUSR1
, "USR1", _("User defined signal 1"));
160 #if defined (SIGUSR2)
161 init_sig (SIGUSR2
, "USR2", _("User defined signal 2"));
163 /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
164 is what is in POSIX.1. */
165 #if defined (SIGCHLD)
166 init_sig (SIGCHLD
, "CHLD", _("Child exited"));
169 init_sig (SIGCLD
, "CLD", _("Child exited"));
172 init_sig (SIGPWR
, "PWR", _("Power failure"));
174 #if defined (SIGTSTP)
175 init_sig (SIGTSTP
, "TSTP", _("Stopped"));
177 #if defined (SIGTTIN)
178 init_sig (SIGTTIN
, "TTIN", _("Stopped (tty input)"));
180 #if defined (SIGTTOU)
181 init_sig (SIGTTOU
, "TTOU", _("Stopped (tty output)"));
183 #if defined (SIGSTOP)
184 init_sig (SIGSTOP
, "STOP", _("Stopped (signal)"));
186 #if defined (SIGXCPU)
187 init_sig (SIGXCPU
, "XCPU", _("CPU time limit exceeded"));
189 #if defined (SIGXFSZ)
190 init_sig (SIGXFSZ
, "XFSZ", _("File size limit exceeded"));
192 #if defined (SIGVTALRM)
193 init_sig (SIGVTALRM
, "VTALRM", _("Virtual timer expired"));
195 #if defined (SIGPROF)
196 init_sig (SIGPROF
, "PROF", _("Profiling timer expired"));
198 #if defined (SIGWINCH)
199 /* "Window size changed" might be more accurate, but even if that
200 is all that it means now, perhaps in the future it will be
201 extended to cover other kinds of window changes. */
202 init_sig (SIGWINCH
, "WINCH", _("Window changed"));
204 #if defined (SIGCONT)
205 init_sig (SIGCONT
, "CONT", _("Continued"));
208 init_sig (SIGURG
, "URG", _("Urgent I/O condition"));
211 /* "I/O pending" has also been suggested. A disadvantage is
212 that signal only happens when the process has
213 asked for it, not everytime I/O is pending. Another disadvantage
214 is the confusion from giving it a different name than under Unix. */
215 init_sig (SIGIO
, "IO", _("I/O possible"));
217 #if defined (SIGWIND)
218 init_sig (SIGWIND
, "WIND", _("SIGWIND"));
220 #if defined (SIGPHONE)
221 init_sig (SIGPHONE
, "PHONE", _("SIGPHONE"));
223 #if defined (SIGPOLL)
224 init_sig (SIGPOLL
, "POLL", _("I/O possible"));
226 #if defined (SIGLOST)
227 init_sig (SIGLOST
, "LOST", _("Resource lost"));
229 #if defined (SIGDANGER)
230 init_sig (SIGDANGER
, "DANGER", _("Danger signal"));
232 #if defined (SIGINFO)
233 init_sig (SIGINFO
, "INFO", _("Information request"));
235 #if defined (SIGNOFP)
236 init_sig (SIGNOFP
, "NOFP", _("Floating point co-processor not available"));
240 /* Return the abbreviation for signal NUMBER. */
248 if (sig_table_nelts
== 0)
251 for (i
= 0; i
< sig_table_nelts
; i
++)
252 if (sig_table
[i
].number
== number
)
253 return (char *)sig_table
[i
].abbrev
;
257 /* Return the signal number for an ABBREV, or -1 if there is no
258 signal by that name. */
266 if (sig_table_nelts
== 0)
269 /* Skip over "SIG" if present. */
270 if (abbrev
[0] == 'S' && abbrev
[1] == 'I' && abbrev
[2] == 'G')
273 for (i
= 0; i
< sig_table_nelts
; i
++)
274 if (abbrev
[0] == sig_table
[i
].abbrev
[0]
275 && strcmp (abbrev
, sig_table
[i
].abbrev
) == 0)
276 return sig_table
[i
].number
;
281 /* Print to standard error the name of SIGNAL, preceded by MESSAGE and
282 a colon, and followed by a newline. */
285 psignal (signal
, message
)
289 if (signal
<= 0 || signal
>= NSIG
)
290 fprintf (stderr
, "%s: unknown signal", message
);
292 fprintf (stderr
, "%s: %s\n", message
, sys_siglist
[signal
]);
296 #ifndef HAVE_STRSIGNAL
297 /* Return the string associated with the signal number. */
303 static char buf
[] = "Signal 12345678901234567890";
305 if (signal
> 0 || signal
< NSIG
)
306 return (char *) sys_siglist
[signal
];
308 sprintf (buf
, "Signal %d", signal
);