1 /* Convert between signal names and numbers.
2 Copyright (C) 1990, 1992, 1993, 1995 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING. If not, write to
16 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
23 #include <sys/types.h> /* Some systems need this for <signal.h>. */
26 /* Some systems declare `sys_siglist in <unistd.h>; if
27 configure defined SYS_SIGLIST_DECLARED, it may expect
28 to find the declaration there. */
34 /* Some systems do not define NSIG in <signal.h>. */
49 #ifndef HAVE_SYS_SIGLIST
50 /* There is too much variation in Sys V signal numbers and names, so
51 we must initialize them at runtime. */
53 static const char undoc
[] = "unknown signal";
55 const char *sys_siglist
[NSIG
];
57 #else /* HAVE_SYS_SIGLIST. */
59 #ifndef SYS_SIGLIST_DECLARED
60 extern char *sys_siglist
[];
61 #endif /* Not SYS_SIGLIST_DECLARED. */
63 #endif /* Not HAVE_SYS_SIGLIST. */
65 /* Table of abbreviations for signals. Note: A given number can
66 appear more than once with different abbreviations. */
72 static num_abbrev sig_table
[NSIG
*2];
73 /* Number of elements of sig_table used. */
74 static int sig_table_nelts
= 0;
76 /* Enter signal number NUMBER into the tables with ABBREV and NAME. */
79 init_sig (number
, abbrev
, name
)
84 #ifndef HAVE_SYS_SIGLIST
85 sys_siglist
[number
] = name
;
87 sig_table
[sig_table_nelts
].number
= number
;
88 sig_table
[sig_table_nelts
++].abbrev
= abbrev
;
94 #ifndef HAVE_SYS_SIGLIST
96 /* Initialize signal names. */
97 for (i
= 0; i
< NSIG
; i
++)
98 sys_siglist
[i
] = undoc
;
99 #endif /* !HAVE_SYS_SIGLIST */
101 /* Initialize signal names. */
103 init_sig (SIGHUP
, "HUP", "Hangup");
106 init_sig (SIGINT
, "INT", "Interrupt");
108 #if defined (SIGQUIT)
109 init_sig (SIGQUIT
, "QUIT", "Quit");
112 init_sig (SIGILL
, "ILL", "Illegal Instruction");
114 #if defined (SIGTRAP)
115 init_sig (SIGTRAP
, "TRAP", "Trace/breakpoint trap");
117 /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
118 SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
119 #if defined (SIGABRT)
120 init_sig (SIGABRT
, "ABRT", "Aborted");
123 init_sig (SIGIOT
, "IOT", "IOT trap");
126 init_sig (SIGEMT
, "EMT", "EMT trap");
129 init_sig (SIGFPE
, "FPE", "Floating point exception");
131 #if defined (SIGKILL)
132 init_sig (SIGKILL
, "KILL", "Killed");
135 init_sig (SIGBUS
, "BUS", "Bus error");
137 #if defined (SIGSEGV)
138 init_sig (SIGSEGV
, "SEGV", "Segmentation fault");
141 init_sig (SIGSYS
, "SYS", "Bad system call");
143 #if defined (SIGPIPE)
144 init_sig (SIGPIPE
, "PIPE", "Broken pipe");
146 #if defined (SIGALRM)
147 init_sig (SIGALRM
, "ALRM", "Alarm clock");
149 #if defined (SIGTERM)
150 init_sig (SIGTERM
, "TERM", "Terminated");
152 #if defined (SIGUSR1)
153 init_sig (SIGUSR1
, "USR1", "User defined signal 1");
155 #if defined (SIGUSR2)
156 init_sig (SIGUSR2
, "USR2", "User defined signal 2");
158 /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
159 is what is in POSIX.1. */
160 #if defined (SIGCHLD)
161 init_sig (SIGCHLD
, "CHLD", "Child exited");
164 init_sig (SIGCLD
, "CLD", "Child exited");
167 init_sig (SIGPWR
, "PWR", "Power failure");
169 #if defined (SIGTSTP)
170 init_sig (SIGTSTP
, "TSTP", "Stopped");
172 #if defined (SIGTTIN)
173 init_sig (SIGTTIN
, "TTIN", "Stopped (tty input)");
175 #if defined (SIGTTOU)
176 init_sig (SIGTTOU
, "TTOU", "Stopped (tty output)");
178 #if defined (SIGSTOP)
179 init_sig (SIGSTOP
, "STOP", "Stopped (signal)");
181 #if defined (SIGXCPU)
182 init_sig (SIGXCPU
, "XCPU", "CPU time limit exceeded");
184 #if defined (SIGXFSZ)
185 init_sig (SIGXFSZ
, "XFSZ", "File size limit exceeded");
187 #if defined (SIGVTALRM)
188 init_sig (SIGVTALRM
, "VTALRM", "Virtual timer expired");
190 #if defined (SIGPROF)
191 init_sig (SIGPROF
, "PROF", "Profiling timer expired");
193 #if defined (SIGWINCH)
194 /* "Window size changed" might be more accurate, but even if that
195 is all that it means now, perhaps in the future it will be
196 extended to cover other kinds of window changes. */
197 init_sig (SIGWINCH
, "WINCH", "Window changed");
199 #if defined (SIGCONT)
200 init_sig (SIGCONT
, "CONT", "Continued");
203 init_sig (SIGURG
, "URG", "Urgent I/O condition");
206 /* "I/O pending" has also been suggested. A disadvantage is
207 that signal only happens when the process has
208 asked for it, not everytime I/O is pending. Another disadvantage
209 is the confusion from giving it a different name than under Unix. */
210 init_sig (SIGIO
, "IO", "I/O possible");
212 #if defined (SIGWIND)
213 init_sig (SIGWIND
, "WIND", "SIGWIND");
215 #if defined (SIGPHONE)
216 init_sig (SIGPHONE
, "PHONE", "SIGPHONE");
218 #if defined (SIGPOLL)
219 init_sig (SIGPOLL
, "POLL", "I/O possible");
221 #if defined (SIGLOST)
222 init_sig (SIGLOST
, "LOST", "Resource lost");
224 #if defined (SIGDANGER)
225 init_sig (SIGDANGER
, "DANGER", "Danger signal");
227 #if defined (SIGINFO)
228 init_sig (SIGINFO
, "INFO", "Information request");
232 /* Return the abbreviation for signal NUMBER. */
240 if (sig_table_nelts
== 0)
243 for (i
= 0; i
< sig_table_nelts
; i
++)
244 if (sig_table
[i
].number
== number
)
245 return (char *)sig_table
[i
].abbrev
;
249 /* Return the signal number for an ABBREV, or -1 if there is no
250 signal by that name. */
258 if (sig_table_nelts
== 0)
261 /* Skip over "SIG" if present. */
262 if (abbrev
[0] == 'S' && abbrev
[1] == 'I' && abbrev
[2] == 'G')
265 for (i
= 0; i
< sig_table_nelts
; i
++)
266 if (abbrev
[0] == sig_table
[i
].abbrev
[0]
267 && strcmp (abbrev
, sig_table
[i
].abbrev
) == 0)
268 return sig_table
[i
].number
;
273 /* Print to standard error the name of SIGNAL, preceded by MESSAGE and
274 a colon, and followed by a newline. */
277 psignal (signal
, message
)
281 if (signal
<= 0 || signal
>= NSIG
)
282 fprintf (stderr
, "%s: unknown signal", message
);
284 fprintf (stderr
, "%s: %s\n", message
, sys_siglist
[signal
]);
288 #ifndef HAVE_STRSIGNAL
289 /* Return the string associated with the signal number. */
295 static char buf
[] = "Signal 12345678901234567890";
297 if (signal
> 0 || signal
< NSIG
)
298 return (char *) sys_siglist
[signal
];
300 sprintf (buf
, "Signal %d", signal
);