1
/* Convert between signal names and numbers.
2
Copyright (C) 1990, 1992, 1993, 1995, 1996 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. */
23
#include <sys/types.h> /* Some systems need this for <signal.h>. */
30
/* Some systems declare `sys_siglist in <unistd.h>; if
31
configure defined SYS_SIGLIST_DECLARED, it may expect
32
to find the declaration there. */
38
/* Some systems do not define NSIG in <signal.h>. */
53
#ifndef HAVE_SYS_SIGLIST
54
/* There is too much variation in Sys V signal numbers and names, so
55
we must initialize them at runtime. */
57
static const char *undoc;
59
const char *sys_siglist[NSIG];
61
#else /* HAVE_SYS_SIGLIST. */
63
#ifndef SYS_SIGLIST_DECLARED
64
extern char *sys_siglist[];
65
#endif /* Not SYS_SIGLIST_DECLARED. */
67
#endif /* Not HAVE_SYS_SIGLIST. */
69
/* Table of abbreviations for signals. Note: A given number can
70
appear more than once with different abbreviations. */
71
#define SIG_TABLE_SIZE (NSIG*2)
78
static num_abbrev sig_table[SIG_TABLE_SIZE];
79
/* Number of elements of sig_table used. */
80
static int sig_table_nelts = 0;
82
/* Enter signal number NUMBER into the tables with ABBREV and NAME. */
85
init_sig (number, abbrev, name)
90
#ifndef HAVE_SYS_SIGLIST
91
/* If this value is ever greater than NSIG it seems like it'd be a bug in
92
the system headers, but... better safe than sorry. We know, for
93
example, that this isn't always true on VMS. */
95
if (number >= 0 && number < NSIG)
96
sys_siglist[number] = name;
98
if (sig_table_nelts < SIG_TABLE_SIZE)
100
sig_table[sig_table_nelts].number = number;
101
sig_table[sig_table_nelts++].abbrev = abbrev;
108
#ifndef HAVE_SYS_SIGLIST
110
char *u = _("unknown signal");
114
/* Initialize signal names. */
115
for (i = 0; i < NSIG; i++)
116
sys_siglist[i] = undoc;
117
#endif /* !HAVE_SYS_SIGLIST */
119
/* Initialize signal names. */
121
init_sig (SIGHUP, "HUP", _("Hangup"));
124
init_sig (SIGINT, "INT", _("Interrupt"));
126
#if defined (SIGQUIT)
127
init_sig (SIGQUIT, "QUIT", _("Quit"));
130
init_sig (SIGILL, "ILL", _("Illegal Instruction"));
132
#if defined (SIGTRAP)
133
init_sig (SIGTRAP, "TRAP", _("Trace/breakpoint trap"));
135
/* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
136
SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
137
#if defined (SIGABRT)
138
init_sig (SIGABRT, "ABRT", _("Aborted"));
141
init_sig (SIGIOT, "IOT", _("IOT trap"));
144
init_sig (SIGEMT, "EMT", _("EMT trap"));
147
init_sig (SIGFPE, "FPE", _("Floating point exception"));
149
#if defined (SIGKILL)
150
init_sig (SIGKILL, "KILL", _("Killed"));
153
init_sig (SIGBUS, "BUS", _("Bus error"));
155
#if defined (SIGSEGV)
156
init_sig (SIGSEGV, "SEGV", _("Segmentation fault"));
159
init_sig (SIGSYS, "SYS", _("Bad system call"));
161
#if defined (SIGPIPE)
162
init_sig (SIGPIPE, "PIPE", _("Broken pipe"));
164
#if defined (SIGALRM)
165
init_sig (SIGALRM, "ALRM", _("Alarm clock"));
167
#if defined (SIGTERM)
168
init_sig (SIGTERM, "TERM", _("Terminated"));
170
#if defined (SIGUSR1)
171
init_sig (SIGUSR1, "USR1", _("User defined signal 1"));
173
#if defined (SIGUSR2)
174
init_sig (SIGUSR2, "USR2", _("User defined signal 2"));
176
/* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
177
is what is in POSIX.1. */
178
#if defined (SIGCHLD)
179
init_sig (SIGCHLD, "CHLD", _("Child exited"));
182
init_sig (SIGCLD, "CLD", _("Child exited"));
185
init_sig (SIGPWR, "PWR", _("Power failure"));
187
#if defined (SIGTSTP)
188
init_sig (SIGTSTP, "TSTP", _("Stopped"));
190
#if defined (SIGTTIN)
191
init_sig (SIGTTIN, "TTIN", _("Stopped (tty input)"));
193
#if defined (SIGTTOU)
194
init_sig (SIGTTOU, "TTOU", _("Stopped (tty output)"));
196
#if defined (SIGSTOP)
197
init_sig (SIGSTOP, "STOP", _("Stopped (signal)"));
199
#if defined (SIGXCPU)
200
init_sig (SIGXCPU, "XCPU", _("CPU time limit exceeded"));
202
#if defined (SIGXFSZ)
203
init_sig (SIGXFSZ, "XFSZ", _("File size limit exceeded"));
205
#if defined (SIGVTALRM)
206
init_sig (SIGVTALRM, "VTALRM", _("Virtual timer expired"));
208
#if defined (SIGPROF)
209
init_sig (SIGPROF, "PROF", _("Profiling timer expired"));
211
#if defined (SIGWINCH)
212
/* "Window size changed" might be more accurate, but even if that
213
is all that it means now, perhaps in the future it will be
214
extended to cover other kinds of window changes. */
215
init_sig (SIGWINCH, "WINCH", _("Window changed"));
217
#if defined (SIGCONT)
218
init_sig (SIGCONT, "CONT", _("Continued"));
221
init_sig (SIGURG, "URG", _("Urgent I/O condition"));
224
/* "I/O pending" has also been suggested. A disadvantage is
225
that signal only happens when the process has
226
asked for it, not everytime I/O is pending. Another disadvantage
227
is the confusion from giving it a different name than under Unix. */
228
init_sig (SIGIO, "IO", _("I/O possible"));
230
#if defined (SIGWIND)
231
init_sig (SIGWIND, "WIND", _("SIGWIND"));
233
#if defined (SIGPHONE)
234
init_sig (SIGPHONE, "PHONE", _("SIGPHONE"));
236
#if defined (SIGPOLL)
237
init_sig (SIGPOLL, "POLL", _("I/O possible"));
239
#if defined (SIGLOST)
240
init_sig (SIGLOST, "LOST", _("Resource lost"));
242
#if defined (SIGDANGER)
243
init_sig (SIGDANGER, "DANGER", _("Danger signal"));
245
#if defined (SIGINFO)
246
init_sig (SIGINFO, "INFO", _("Information request"));
248
#if defined (SIGNOFP)
249
init_sig (SIGNOFP, "NOFP", _("Floating point co-processor not available"));
253
/* Return the abbreviation for signal NUMBER. */
261
if (sig_table_nelts == 0)
264
for (i = 0; i < sig_table_nelts; i++)
265
if (sig_table[i].number == number)
266
return (char *)sig_table[i].abbrev;
270
/* Return the signal number for an ABBREV, or -1 if there is no
271
signal by that name. */
279
if (sig_table_nelts == 0)
282
/* Skip over "SIG" if present. */
283
if (abbrev[0] == 'S' && abbrev[1] == 'I' && abbrev[2] == 'G')
286
for (i = 0; i < sig_table_nelts; i++)
287
if (abbrev[0] == sig_table[i].abbrev[0]
288
&& strcmp (abbrev, sig_table[i].abbrev) == 0)
289
return sig_table[i].number;
294
/* Print to standard error the name of SIGNAL, preceded by MESSAGE and
295
a colon, and followed by a newline. */
298
psignal (signal, message)
302
if (signal <= 0 || signal >= NSIG)
303
fprintf (stderr, "%s: unknown signal", message);
305
fprintf (stderr, "%s: %s\n", message, sys_siglist[signal]);
309
#ifndef HAVE_STRSIGNAL
310
/* Return the string associated with the signal number. */
316
static char buf[] = "Signal 12345678901234567890";
318
if (signal > 0 || signal < NSIG)
319
return (char *) sys_siglist[signal];
321
sprintf (buf, "Signal %d", signal);