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