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. */
73 #define SIG_TABLE_SIZE (NSIG*2)
80 static num_abbrev sig_table
[SIG_TABLE_SIZE
];
81 /* Number of elements of sig_table used. */
82 static int sig_table_nelts
= 0;
84 /* Enter signal number NUMBER into the tables with ABBREV and NAME. */
87 init_sig (number
, abbrev
, name
)
92 #ifndef HAVE_SYS_SIGLIST
93 /* If this value is ever greater than NSIG it seems like it'd be a bug in
94 the system headers, but... better safe than sorry. We know, for
95 example, that this isn't always true on VMS. */
97 if (number
>= 0 && number
< NSIG
)
98 sys_siglist
[number
] = name
;
100 if (sig_table_nelts
< SIG_TABLE_SIZE
)
102 sig_table
[sig_table_nelts
].number
= number
;
103 sig_table
[sig_table_nelts
++].abbrev
= abbrev
;
110 #ifndef HAVE_SYS_SIGLIST
112 /* Initialize signal names. */
113 for (i
= 0; i
< NSIG
; i
++)
114 sys_siglist
[i
] = undoc
;
115 #endif /* !HAVE_SYS_SIGLIST */
117 /* Initialize signal names. */
119 init_sig (SIGHUP
, "HUP", "Hangup");
122 init_sig (SIGINT
, "INT", "Interrupt");
124 #if defined (SIGQUIT)
125 init_sig (SIGQUIT
, "QUIT", "Quit");
128 init_sig (SIGILL
, "ILL", "Illegal Instruction");
130 #if defined (SIGTRAP)
131 init_sig (SIGTRAP
, "TRAP", "Trace/breakpoint trap");
133 /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
134 SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
135 #if defined (SIGABRT)
136 init_sig (SIGABRT
, "ABRT", "Aborted");
139 init_sig (SIGIOT
, "IOT", "IOT trap");
142 init_sig (SIGEMT
, "EMT", "EMT trap");
145 init_sig (SIGFPE
, "FPE", "Floating point exception");
147 #if defined (SIGKILL)
148 init_sig (SIGKILL
, "KILL", "Killed");
151 init_sig (SIGBUS
, "BUS", "Bus error");
153 #if defined (SIGSEGV)
154 init_sig (SIGSEGV
, "SEGV", "Segmentation fault");
157 init_sig (SIGSYS
, "SYS", "Bad system call");
159 #if defined (SIGPIPE)
160 init_sig (SIGPIPE
, "PIPE", "Broken pipe");
162 #if defined (SIGALRM)
163 init_sig (SIGALRM
, "ALRM", "Alarm clock");
165 #if defined (SIGTERM)
166 init_sig (SIGTERM
, "TERM", "Terminated");
168 #if defined (SIGUSR1)
169 init_sig (SIGUSR1
, "USR1", "User defined signal 1");
171 #if defined (SIGUSR2)
172 init_sig (SIGUSR2
, "USR2", "User defined signal 2");
174 /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
175 is what is in POSIX.1. */
176 #if defined (SIGCHLD)
177 init_sig (SIGCHLD
, "CHLD", "Child exited");
180 init_sig (SIGCLD
, "CLD", "Child exited");
183 init_sig (SIGPWR
, "PWR", "Power failure");
185 #if defined (SIGTSTP)
186 init_sig (SIGTSTP
, "TSTP", "Stopped");
188 #if defined (SIGTTIN)
189 init_sig (SIGTTIN
, "TTIN", "Stopped (tty input)");
191 #if defined (SIGTTOU)
192 init_sig (SIGTTOU
, "TTOU", "Stopped (tty output)");
194 #if defined (SIGSTOP)
195 init_sig (SIGSTOP
, "STOP", "Stopped (signal)");
197 #if defined (SIGXCPU)
198 init_sig (SIGXCPU
, "XCPU", "CPU time limit exceeded");
200 #if defined (SIGXFSZ)
201 init_sig (SIGXFSZ
, "XFSZ", "File size limit exceeded");
203 #if defined (SIGVTALRM)
204 init_sig (SIGVTALRM
, "VTALRM", "Virtual timer expired");
206 #if defined (SIGPROF)
207 init_sig (SIGPROF
, "PROF", "Profiling timer expired");
209 #if defined (SIGWINCH)
210 /* "Window size changed" might be more accurate, but even if that
211 is all that it means now, perhaps in the future it will be
212 extended to cover other kinds of window changes. */
213 init_sig (SIGWINCH
, "WINCH", "Window changed");
215 #if defined (SIGCONT)
216 init_sig (SIGCONT
, "CONT", "Continued");
219 init_sig (SIGURG
, "URG", "Urgent I/O condition");
222 /* "I/O pending" has also been suggested. A disadvantage is
223 that signal only happens when the process has
224 asked for it, not everytime I/O is pending. Another disadvantage
225 is the confusion from giving it a different name than under Unix. */
226 init_sig (SIGIO
, "IO", "I/O possible");
228 #if defined (SIGWIND)
229 init_sig (SIGWIND
, "WIND", "SIGWIND");
231 #if defined (SIGPHONE)
232 init_sig (SIGPHONE
, "PHONE", "SIGPHONE");
234 #if defined (SIGPOLL)
235 init_sig (SIGPOLL
, "POLL", "I/O possible");
237 #if defined (SIGLOST)
238 init_sig (SIGLOST
, "LOST", "Resource lost");
240 #if defined (SIGDANGER)
241 init_sig (SIGDANGER
, "DANGER", "Danger signal");
243 #if defined (SIGINFO)
244 init_sig (SIGINFO
, "INFO", "Information request");
246 #if defined (SIGNOFP)
247 init_sig (SIGNOFP
, "NOFP", "Floating point co-processor not available");
251 /* Return the abbreviation for signal NUMBER. */
259 if (sig_table_nelts
== 0)
262 for (i
= 0; i
< sig_table_nelts
; i
++)
263 if (sig_table
[i
].number
== number
)
264 return (char *)sig_table
[i
].abbrev
;
268 /* Return the signal number for an ABBREV, or -1 if there is no
269 signal by that name. */
277 if (sig_table_nelts
== 0)
280 /* Skip over "SIG" if present. */
281 if (abbrev
[0] == 'S' && abbrev
[1] == 'I' && abbrev
[2] == 'G')
284 for (i
= 0; i
< sig_table_nelts
; i
++)
285 if (abbrev
[0] == sig_table
[i
].abbrev
[0]
286 && strcmp (abbrev
, sig_table
[i
].abbrev
) == 0)
287 return sig_table
[i
].number
;
292 /* Print to standard error the name of SIGNAL, preceded by MESSAGE and
293 a colon, and followed by a newline. */
296 psignal (signal
, message
)
300 if (signal
<= 0 || signal
>= NSIG
)
301 fprintf (stderr
, "%s: unknown signal", message
);
303 fprintf (stderr
, "%s: %s\n", message
, sys_siglist
[signal
]);
307 #ifndef HAVE_STRSIGNAL
308 /* Return the string associated with the signal number. */
314 static char buf
[] = "Signal 12345678901234567890";
316 if (signal
> 0 || signal
< NSIG
)
317 return (char *) sys_siglist
[signal
];
319 sprintf (buf
, "Signal %d", signal
);