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. */
25 #include <sys/types.h> /* Some systems need this for <signal.h>. */
32 /* Some systems declare `sys_siglist in <unistd.h>; if
33 configure defined SYS_SIGLIST_DECLARED, it may expect
34 to find the declaration there. */
40 /* Some systems do not define NSIG in <signal.h>. */
55 #ifndef HAVE_SYS_SIGLIST
56 /* There is too much variation in Sys V signal numbers and names, so
57 we must initialize them at runtime. */
59 static const char undoc
[] = "unknown signal";
61 const char *sys_siglist
[NSIG
];
63 #else /* HAVE_SYS_SIGLIST. */
65 #ifndef SYS_SIGLIST_DECLARED
66 extern char *sys_siglist
[];
67 #endif /* Not SYS_SIGLIST_DECLARED. */
69 #endif /* Not HAVE_SYS_SIGLIST. */
71 /* Table of abbreviations for signals. Note: A given number can
72 appear more than once with different abbreviations. */
78 static num_abbrev sig_table
[NSIG
*2];
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 sys_siglist
[number
] = name
;
93 sig_table
[sig_table_nelts
].number
= number
;
94 sig_table
[sig_table_nelts
++].abbrev
= abbrev
;
100 #ifndef HAVE_SYS_SIGLIST
102 /* Initialize signal names. */
103 for (i
= 0; i
< NSIG
; i
++)
104 sys_siglist
[i
] = undoc
;
105 #endif /* !HAVE_SYS_SIGLIST */
107 /* Initialize signal names. */
109 init_sig (SIGHUP
, "HUP", "Hangup");
112 init_sig (SIGINT
, "INT", "Interrupt");
114 #if defined (SIGQUIT)
115 init_sig (SIGQUIT
, "QUIT", "Quit");
118 init_sig (SIGILL
, "ILL", "Illegal Instruction");
120 #if defined (SIGTRAP)
121 init_sig (SIGTRAP
, "TRAP", "Trace/breakpoint trap");
123 /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
124 SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
125 #if defined (SIGABRT)
126 init_sig (SIGABRT
, "ABRT", "Aborted");
129 init_sig (SIGIOT
, "IOT", "IOT trap");
132 init_sig (SIGEMT
, "EMT", "EMT trap");
135 init_sig (SIGFPE
, "FPE", "Floating point exception");
137 #if defined (SIGKILL)
138 init_sig (SIGKILL
, "KILL", "Killed");
141 init_sig (SIGBUS
, "BUS", "Bus error");
143 #if defined (SIGSEGV)
144 init_sig (SIGSEGV
, "SEGV", "Segmentation fault");
147 init_sig (SIGSYS
, "SYS", "Bad system call");
149 #if defined (SIGPIPE)
150 init_sig (SIGPIPE
, "PIPE", "Broken pipe");
152 #if defined (SIGALRM)
153 init_sig (SIGALRM
, "ALRM", "Alarm clock");
155 #if defined (SIGTERM)
156 init_sig (SIGTERM
, "TERM", "Terminated");
158 #if defined (SIGUSR1)
159 init_sig (SIGUSR1
, "USR1", "User defined signal 1");
161 #if defined (SIGUSR2)
162 init_sig (SIGUSR2
, "USR2", "User defined signal 2");
164 /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
165 is what is in POSIX.1. */
166 #if defined (SIGCHLD)
167 init_sig (SIGCHLD
, "CHLD", "Child exited");
170 init_sig (SIGCLD
, "CLD", "Child exited");
173 init_sig (SIGPWR
, "PWR", "Power failure");
175 #if defined (SIGTSTP)
176 init_sig (SIGTSTP
, "TSTP", "Stopped");
178 #if defined (SIGTTIN)
179 init_sig (SIGTTIN
, "TTIN", "Stopped (tty input)");
181 #if defined (SIGTTOU)
182 init_sig (SIGTTOU
, "TTOU", "Stopped (tty output)");
184 #if defined (SIGSTOP)
185 init_sig (SIGSTOP
, "STOP", "Stopped (signal)");
187 #if defined (SIGXCPU)
188 init_sig (SIGXCPU
, "XCPU", "CPU time limit exceeded");
190 #if defined (SIGXFSZ)
191 init_sig (SIGXFSZ
, "XFSZ", "File size limit exceeded");
193 #if defined (SIGVTALRM)
194 init_sig (SIGVTALRM
, "VTALRM", "Virtual timer expired");
196 #if defined (SIGPROF)
197 init_sig (SIGPROF
, "PROF", "Profiling timer expired");
199 #if defined (SIGWINCH)
200 /* "Window size changed" might be more accurate, but even if that
201 is all that it means now, perhaps in the future it will be
202 extended to cover other kinds of window changes. */
203 init_sig (SIGWINCH
, "WINCH", "Window changed");
205 #if defined (SIGCONT)
206 init_sig (SIGCONT
, "CONT", "Continued");
209 init_sig (SIGURG
, "URG", "Urgent I/O condition");
212 /* "I/O pending" has also been suggested. A disadvantage is
213 that signal only happens when the process has
214 asked for it, not everytime I/O is pending. Another disadvantage
215 is the confusion from giving it a different name than under Unix. */
216 init_sig (SIGIO
, "IO", "I/O possible");
218 #if defined (SIGWIND)
219 init_sig (SIGWIND
, "WIND", "SIGWIND");
221 #if defined (SIGPHONE)
222 init_sig (SIGPHONE
, "PHONE", "SIGPHONE");
224 #if defined (SIGPOLL)
225 init_sig (SIGPOLL
, "POLL", "I/O possible");
227 #if defined (SIGLOST)
228 init_sig (SIGLOST
, "LOST", "Resource lost");
230 #if defined (SIGDANGER)
231 init_sig (SIGDANGER
, "DANGER", "Danger signal");
233 #if defined (SIGINFO)
234 init_sig (SIGINFO
, "INFO", "Information request");
236 #if defined (SIGNOFP)
237 init_sig (SIGNOFP
, "NOFP", "Floating point co-processor not available");
241 /* Return the abbreviation for signal NUMBER. */
249 if (sig_table_nelts
== 0)
252 for (i
= 0; i
< sig_table_nelts
; i
++)
253 if (sig_table
[i
].number
== number
)
254 return (char *)sig_table
[i
].abbrev
;
258 /* Return the signal number for an ABBREV, or -1 if there is no
259 signal by that name. */
267 if (sig_table_nelts
== 0)
270 /* Skip over "SIG" if present. */
271 if (abbrev
[0] == 'S' && abbrev
[1] == 'I' && abbrev
[2] == 'G')
274 for (i
= 0; i
< sig_table_nelts
; i
++)
275 if (abbrev
[0] == sig_table
[i
].abbrev
[0]
276 && strcmp (abbrev
, sig_table
[i
].abbrev
) == 0)
277 return sig_table
[i
].number
;
282 /* Print to standard error the name of SIGNAL, preceded by MESSAGE and
283 a colon, and followed by a newline. */
286 psignal (signal
, message
)
290 if (signal
<= 0 || signal
>= NSIG
)
291 fprintf (stderr
, "%s: unknown signal", message
);
293 fprintf (stderr
, "%s: %s\n", message
, sys_siglist
[signal
]);
297 #ifndef HAVE_STRSIGNAL
298 /* Return the string associated with the signal number. */
304 static char buf
[] = "Signal 12345678901234567890";
306 if (signal
> 0 || signal
< NSIG
)
307 return (char *) sys_siglist
[signal
];
309 sprintf (buf
, "Signal %d", signal
);