VirtualBox

source: kBuild/trunk/src/gmakenew/signame.c@ 944

Last change on this file since 944 was 503, checked in by bird, 18 years ago

Untested merge with GNU Make v3.81 (vendor/gnumake/2005-05-16 -> vendor/gnumake/current).

  • Property svn:eol-style set to native
File size: 6.9 KB
Line 
1/* Convert between signal names and numbers.
2Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
32000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
4This file is part of GNU Make.
5
6GNU Make is free software; you can redistribute it and/or modify it under the
7terms of the GNU General Public License as published by the Free Software
8Foundation; either version 2, or (at your option) any later version.
9
10GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
11WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License along with
15GNU Make; see the file COPYING. If not, write to the Free Software
16Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */
17
18#include "make.h"
19
20/* If the system provides strsignal, we don't need it. */
21
22#if !HAVE_STRSIGNAL
23
24/* If the system provides sys_siglist, we'll use that.
25 Otherwise create our own.
26 */
27
28#if !HAVE_DECL_SYS_SIGLIST
29
30/* Some systems do not define NSIG in <signal.h>. */
31#ifndef NSIG
32#ifdef _NSIG
33#define NSIG _NSIG
34#else
35#define NSIG 32
36#endif
37#endif
38
39/* There is too much variation in Sys V signal numbers and names, so
40 we must initialize them at runtime. */
41
42static const char *undoc;
43
44static const char *sys_siglist[NSIG];
45
46/* Table of abbreviations for signals. Note: A given number can
47 appear more than once with different abbreviations. */
48#define SIG_TABLE_SIZE (NSIG*2)
49
50typedef struct
51 {
52 int number;
53 const char *abbrev;
54 } num_abbrev;
55
56static num_abbrev sig_table[SIG_TABLE_SIZE];
57
58/* Number of elements of sig_table used. */
59static int sig_table_nelts = 0;
60
61/* Enter signal number NUMBER into the tables with ABBREV and NAME. */
62
63static void
64init_sig (int number, const char *abbrev, const char *name)
65{
66 /* If this value is ever greater than NSIG it seems like it'd be a bug in
67 the system headers, but... better safe than sorry. We know, for
68 example, that this isn't always true on VMS. */
69
70 if (number >= 0 && number < NSIG)
71 sys_siglist[number] = name;
72
73 if (sig_table_nelts < SIG_TABLE_SIZE)
74 {
75 sig_table[sig_table_nelts].number = number;
76 sig_table[sig_table_nelts++].abbrev = abbrev;
77 }
78}
79
80static int
81signame_init (void)
82{
83 int i;
84
85 undoc = xstrdup (_("unknown signal"));
86
87 /* Initialize signal names. */
88 for (i = 0; i < NSIG; i++)
89 sys_siglist[i] = undoc;
90
91 /* Initialize signal names. */
92#if defined (SIGHUP)
93 init_sig (SIGHUP, "HUP", _("Hangup"));
94#endif
95#if defined (SIGINT)
96 init_sig (SIGINT, "INT", _("Interrupt"));
97#endif
98#if defined (SIGQUIT)
99 init_sig (SIGQUIT, "QUIT", _("Quit"));
100#endif
101#if defined (SIGILL)
102 init_sig (SIGILL, "ILL", _("Illegal Instruction"));
103#endif
104#if defined (SIGTRAP)
105 init_sig (SIGTRAP, "TRAP", _("Trace/breakpoint trap"));
106#endif
107 /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
108 SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
109#if defined (SIGABRT)
110 init_sig (SIGABRT, "ABRT", _("Aborted"));
111#endif
112#if defined (SIGIOT)
113 init_sig (SIGIOT, "IOT", _("IOT trap"));
114#endif
115#if defined (SIGEMT)
116 init_sig (SIGEMT, "EMT", _("EMT trap"));
117#endif
118#if defined (SIGFPE)
119 init_sig (SIGFPE, "FPE", _("Floating point exception"));
120#endif
121#if defined (SIGKILL)
122 init_sig (SIGKILL, "KILL", _("Killed"));
123#endif
124#if defined (SIGBUS)
125 init_sig (SIGBUS, "BUS", _("Bus error"));
126#endif
127#if defined (SIGSEGV)
128 init_sig (SIGSEGV, "SEGV", _("Segmentation fault"));
129#endif
130#if defined (SIGSYS)
131 init_sig (SIGSYS, "SYS", _("Bad system call"));
132#endif
133#if defined (SIGPIPE)
134 init_sig (SIGPIPE, "PIPE", _("Broken pipe"));
135#endif
136#if defined (SIGALRM)
137 init_sig (SIGALRM, "ALRM", _("Alarm clock"));
138#endif
139#if defined (SIGTERM)
140 init_sig (SIGTERM, "TERM", _("Terminated"));
141#endif
142#if defined (SIGUSR1)
143 init_sig (SIGUSR1, "USR1", _("User defined signal 1"));
144#endif
145#if defined (SIGUSR2)
146 init_sig (SIGUSR2, "USR2", _("User defined signal 2"));
147#endif
148 /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
149 is what is in POSIX.1. */
150#if defined (SIGCHLD)
151 init_sig (SIGCHLD, "CHLD", _("Child exited"));
152#endif
153#if defined (SIGCLD)
154 init_sig (SIGCLD, "CLD", _("Child exited"));
155#endif
156#if defined (SIGPWR)
157 init_sig (SIGPWR, "PWR", _("Power failure"));
158#endif
159#if defined (SIGTSTP)
160 init_sig (SIGTSTP, "TSTP", _("Stopped"));
161#endif
162#if defined (SIGTTIN)
163 init_sig (SIGTTIN, "TTIN", _("Stopped (tty input)"));
164#endif
165#if defined (SIGTTOU)
166 init_sig (SIGTTOU, "TTOU", _("Stopped (tty output)"));
167#endif
168#if defined (SIGSTOP)
169 init_sig (SIGSTOP, "STOP", _("Stopped (signal)"));
170#endif
171#if defined (SIGXCPU)
172 init_sig (SIGXCPU, "XCPU", _("CPU time limit exceeded"));
173#endif
174#if defined (SIGXFSZ)
175 init_sig (SIGXFSZ, "XFSZ", _("File size limit exceeded"));
176#endif
177#if defined (SIGVTALRM)
178 init_sig (SIGVTALRM, "VTALRM", _("Virtual timer expired"));
179#endif
180#if defined (SIGPROF)
181 init_sig (SIGPROF, "PROF", _("Profiling timer expired"));
182#endif
183#if defined (SIGWINCH)
184 /* "Window size changed" might be more accurate, but even if that
185 is all that it means now, perhaps in the future it will be
186 extended to cover other kinds of window changes. */
187 init_sig (SIGWINCH, "WINCH", _("Window changed"));
188#endif
189#if defined (SIGCONT)
190 init_sig (SIGCONT, "CONT", _("Continued"));
191#endif
192#if defined (SIGURG)
193 init_sig (SIGURG, "URG", _("Urgent I/O condition"));
194#endif
195#if defined (SIGIO)
196 /* "I/O pending" has also been suggested. A disadvantage is
197 that signal only happens when the process has
198 asked for it, not everytime I/O is pending. Another disadvantage
199 is the confusion from giving it a different name than under Unix. */
200 init_sig (SIGIO, "IO", _("I/O possible"));
201#endif
202#if defined (SIGWIND)
203 init_sig (SIGWIND, "WIND", _("SIGWIND"));
204#endif
205#if defined (SIGPHONE)
206 init_sig (SIGPHONE, "PHONE", _("SIGPHONE"));
207#endif
208#if defined (SIGPOLL)
209 init_sig (SIGPOLL, "POLL", _("I/O possible"));
210#endif
211#if defined (SIGLOST)
212 init_sig (SIGLOST, "LOST", _("Resource lost"));
213#endif
214#if defined (SIGDANGER)
215 init_sig (SIGDANGER, "DANGER", _("Danger signal"));
216#endif
217#if defined (SIGINFO)
218 init_sig (SIGINFO, "INFO", _("Information request"));
219#endif
220#if defined (SIGNOFP)
221 init_sig (SIGNOFP, "NOFP", _("Floating point co-processor not available"));
222#endif
223
224 return 1;
225}
226
227#endif /* HAVE_DECL_SYS_SIGLIST */
228
229
230char *
231strsignal (int signal)
232{
233 static char buf[] = "Signal 12345678901234567890";
234
235#if ! HAVE_DECL_SYS_SIGLIST
236# if HAVE_DECL__SYS_SIGLIST
237# define sys_siglist _sys_siglist
238# elif HAVE_DECL___SYS_SIGLIST
239# define sys_siglist __sys_siglist
240# else
241 static char sig_initted = 0;
242
243 if (!sig_initted)
244 sig_initted = signame_init ();
245# endif
246#endif
247
248 if (signal > 0 || signal < NSIG)
249 return (char *) sys_siglist[signal];
250
251 sprintf (buf, "Signal %d", signal);
252 return buf;
253}
254
255#endif /* HAVE_STRSIGNAL */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette