1 /* signames.c -- Create and write `signames.h', which contains an array of
4 /* Copyright (C) 1992-2003 Free Software Foundation, Inc.
6 This file is part of GNU Bash, the Bourne Again SHell.
8 Bash is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License along
19 with Bash; see the file COPYING. If not, write to the Free Software
20 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
25 #include <sys/types.h>
27 #if defined (HAVE_STDLIB_H)
30 # include "ansi_stdlib.h"
31 #endif /* HAVE_STDLIB_H */
44 #define LASTSIG NSIG+2
46 char *signal_names[2 * (LASTSIG)];
48 #define signal_names_size (sizeof(signal_names)/sizeof(signal_names[0]))
52 /* AIX 4.3 defines SIGRTMIN and SIGRTMAX as 888 and 999 respectively.
53 I don't want to allocate so much unused space for the intervening signal
54 numbers, so we just punt if SIGRTMAX is past the bounds of the
55 signal_names array (handled in configure). */
56 #if defined (SIGRTMAX) && defined (UNUSABLE_RT_SIGNALS)
61 #if defined (SIGRTMAX) || defined (SIGRTMIN)
67 initialize_signames ()
70 #if defined (SIGRTMAX) || defined (SIGRTMIN)
71 int rtmin, rtmax, rtcnt;
74 for (i = 1; i < signal_names_size; i++)
75 signal_names[i] = (char *)NULL;
77 /* `signal' 0 is what we do on exit. */
78 signal_names[0] = "EXIT";
80 /* Place signal names which can be aliases for more common signal
81 names first. This allows (for example) SIGABRT to overwrite SIGLOST. */
83 /* POSIX 1003.1b-1993 real time signals, but take care of incomplete
84 implementations. Acoording to the standard, both, SIGRTMIN and
85 SIGRTMAX must be defined, SIGRTMIN must be stricly less than
86 SIGRTMAX, and the difference must be at least 7, that is, there
87 must be at least eight distinct real time signals. */
89 /* The generated signal names are SIGRTMIN, SIGRTMIN+1, ...,
90 SIGRTMIN+x, SIGRTMAX-x, ..., SIGRTMAX-1, SIGRTMAX. If the number
91 of RT signals is odd, there is an extra SIGRTMIN+(x+1).
92 These names are the ones used by ksh and /usr/xpg4/bin/sh on SunOS5. */
94 #if defined (SIGRTMIN)
96 signal_names[rtmin] = "SIGRTMIN";
99 #if defined (SIGRTMAX)
101 signal_names[rtmax] = "SIGRTMAX";
104 #if defined (SIGRTMAX) && defined (SIGRTMIN)
107 rtcnt = (rtmax - rtmin - 1) / 2;
108 /* croak if there are too many RT signals */
109 if (rtcnt >= RTLIM/2)
112 fprintf(stderr, "%s: error: more than %i real time signals, fix `%s'\n",
113 progname, RTLIM, progname);
116 for (i = 1; i <= rtcnt; i++)
118 signal_names[rtmin+i] = (char *)malloc(RTLEN);
119 if (signal_names[rtmin+i])
120 sprintf (signal_names[rtmin+i], "SIGRTMIN+%d", i);
121 signal_names[rtmax-i] = (char *)malloc(RTLEN);
122 if (signal_names[rtmax-i])
123 sprintf (signal_names[rtmax-i], "SIGRTMAX-%d", i);
126 if (rtcnt < RTLIM/2-1 && rtcnt != (rtmax-rtmin)/2)
128 /* Need an extra RTMIN signal */
129 signal_names[rtmin+rtcnt+1] = (char *)malloc(RTLEN);
130 if (signal_names[rtmin+rtcnt+1])
131 sprintf (signal_names[rtmin+rtcnt+1], "SIGRTMIN+%d", rtcnt+1);
134 #endif /* SIGRTMIN && SIGRTMAX */
137 #if defined (SIGLOST) /* resource lost (eg, record-lock lost) */
138 signal_names[SIGLOST] = "SIGLOST";
141 #if defined (SIGMSG) /* HFT input data pending */
142 signal_names[SIGMSG] = "SIGMSG";
145 #if defined (SIGDANGER) /* system crash imminent */
146 signal_names[SIGDANGER] = "SIGDANGER";
149 #if defined (SIGMIGRATE) /* migrate process to another CPU */
150 signal_names[SIGMIGRATE] = "SIGMIGRATE";
153 #if defined (SIGPRE) /* programming error */
154 signal_names[SIGPRE] = "SIGPRE";
157 #if defined (SIGVIRT) /* AIX virtual time alarm */
158 signal_names[SIGVIRT] = "SIGVIRT";
161 #if defined (SIGALRM1) /* m:n condition variables */
162 signal_names[SIGALRM1] = "SIGALRM1";
165 #if defined (SIGWAITING) /* m:n scheduling */
166 signal_names[SIGWAITING] = "SIGWAITING";
169 #if defined (SIGGRANT) /* HFT monitor mode granted */
170 signal_names[SIGGRANT] = "SIGGRANT";
173 #if defined (SIGKAP) /* keep alive poll from native keyboard */
174 signal_names[SIGKAP] = "SIGKAP";
177 #if defined (SIGRETRACT) /* HFT monitor mode retracted */
178 signal_names[SIGRETRACT] = "SIGRETRACT";
181 #if defined (SIGSOUND) /* HFT sound sequence has completed */
182 signal_names[SIGSOUND] = "SIGSOUND";
185 #if defined (SIGSAK) /* Secure Attention Key */
186 signal_names[SIGSAK] = "SIGSAK";
190 #if defined (SIGLWP) /* special signal used by thread library */
191 signal_names[SIGLWP] = "SIGLWP";
194 #if defined (SIGFREEZE) /* special signal used by CPR */
195 signal_names[SIGFREEZE] = "SIGFREEZE";
198 #if defined (SIGTHAW) /* special signal used by CPR */
199 signal_names[SIGTHAW] = "SIGTHAW";
202 #if defined (SIGCANCEL) /* thread cancellation signal used by libthread */
203 signal_names[SIGCANCEL] = "SIGCANCEL";
207 #if defined (SIGDIL) /* DIL signal (?) */
208 signal_names[SIGDIL] = "SIGDIL";
212 #if defined (SIGCLD) /* Like SIGCHLD. */
213 signal_names[SIGCLD] = "SIGCLD";
216 #if defined (SIGPWR) /* power state indication */
217 signal_names[SIGPWR] = "SIGPWR";
220 #if defined (SIGPOLL) /* Pollable event (for streams) */
221 signal_names[SIGPOLL] = "SIGPOLL";
225 #if defined (SIGWINDOW)
226 signal_names[SIGWINDOW] = "SIGWINDOW";
230 #if defined (SIGHUP) /* hangup */
231 signal_names[SIGHUP] = "SIGHUP";
234 #if defined (SIGINT) /* interrupt */
235 signal_names[SIGINT] = "SIGINT";
238 #if defined (SIGQUIT) /* quit */
239 signal_names[SIGQUIT] = "SIGQUIT";
242 #if defined (SIGILL) /* illegal instruction (not reset when caught) */
243 signal_names[SIGILL] = "SIGILL";
246 #if defined (SIGTRAP) /* trace trap (not reset when caught) */
247 signal_names[SIGTRAP] = "SIGTRAP";
250 #if defined (SIGIOT) /* IOT instruction */
251 signal_names[SIGIOT] = "SIGIOT";
254 #if defined (SIGABRT) /* Cause current process to dump core. */
255 signal_names[SIGABRT] = "SIGABRT";
258 #if defined (SIGEMT) /* EMT instruction */
259 signal_names[SIGEMT] = "SIGEMT";
262 #if defined (SIGFPE) /* floating point exception */
263 signal_names[SIGFPE] = "SIGFPE";
266 #if defined (SIGKILL) /* kill (cannot be caught or ignored) */
267 signal_names[SIGKILL] = "SIGKILL";
270 #if defined (SIGBUS) /* bus error */
271 signal_names[SIGBUS] = "SIGBUS";
274 #if defined (SIGSEGV) /* segmentation violation */
275 signal_names[SIGSEGV] = "SIGSEGV";
278 #if defined (SIGSYS) /* bad argument to system call */
279 signal_names[SIGSYS] = "SIGSYS";
282 #if defined (SIGPIPE) /* write on a pipe with no one to read it */
283 signal_names[SIGPIPE] = "SIGPIPE";
286 #if defined (SIGALRM) /* alarm clock */
287 signal_names[SIGALRM] = "SIGALRM";
290 #if defined (SIGTERM) /* software termination signal from kill */
291 signal_names[SIGTERM] = "SIGTERM";
294 #if defined (SIGURG) /* urgent condition on IO channel */
295 signal_names[SIGURG] = "SIGURG";
298 #if defined (SIGSTOP) /* sendable stop signal not from tty */
299 signal_names[SIGSTOP] = "SIGSTOP";
302 #if defined (SIGTSTP) /* stop signal from tty */
303 signal_names[SIGTSTP] = "SIGTSTP";
306 #if defined (SIGCONT) /* continue a stopped process */
307 signal_names[SIGCONT] = "SIGCONT";
310 #if defined (SIGCHLD) /* to parent on child stop or exit */
311 signal_names[SIGCHLD] = "SIGCHLD";
314 #if defined (SIGTTIN) /* to readers pgrp upon background tty read */
315 signal_names[SIGTTIN] = "SIGTTIN";
318 #if defined (SIGTTOU) /* like TTIN for output if (tp->t_local<OSTOP) */
319 signal_names[SIGTTOU] = "SIGTTOU";
322 #if defined (SIGIO) /* input/output possible signal */
323 signal_names[SIGIO] = "SIGIO";
326 #if defined (SIGXCPU) /* exceeded CPU time limit */
327 signal_names[SIGXCPU] = "SIGXCPU";
330 #if defined (SIGXFSZ) /* exceeded file size limit */
331 signal_names[SIGXFSZ] = "SIGXFSZ";
334 #if defined (SIGVTALRM) /* virtual time alarm */
335 signal_names[SIGVTALRM] = "SIGVTALRM";
338 #if defined (SIGPROF) /* profiling time alarm */
339 signal_names[SIGPROF] = "SIGPROF";
342 #if defined (SIGWINCH) /* window changed */
343 signal_names[SIGWINCH] = "SIGWINCH";
347 #if defined (SIGINFO) && !defined (_SEQUENT_) /* information request */
348 signal_names[SIGINFO] = "SIGINFO";
351 #if defined (SIGUSR1) /* user defined signal 1 */
352 signal_names[SIGUSR1] = "SIGUSR1";
355 #if defined (SIGUSR2) /* user defined signal 2 */
356 signal_names[SIGUSR2] = "SIGUSR2";
359 #if defined (SIGKILLTHR) /* BeOS: Kill Thread */
360 signal_names[SIGKILLTHR] = "SIGKILLTHR";
363 for (i = 0; i < NSIG; i++)
364 if (signal_names[i] == (char *)NULL)
366 signal_names[i] = (char *)malloc (18);
368 sprintf (signal_names[i], "SIGJUNK(%d)", i);
371 signal_names[NSIG] = "DEBUG";
372 signal_names[NSIG+1] = "ERR";
373 signal_names[NSIG+2] = "RETURN";
377 write_signames (stream)
382 fprintf (stream, "/* This file was automatically created by %s.\n",
384 fprintf (stream, " Do not edit. Edit support/mksignames.c instead. */\n\n");
386 "/* A translation list so we can be polite to our users. */\n");
387 fprintf (stream, "char *signal_names[NSIG + 4] = {\n");
389 for (i = 0; i <= LASTSIG; i++)
390 fprintf (stream, " \"%s\",\n", signal_names[i]);
392 fprintf (stream, " (char *)0x0\n");
393 fprintf (stream, "};\n");
408 stream_name = "stdout";
413 stream_name = argv[1];
414 stream = fopen (stream_name, "w");
418 fprintf (stderr, "Usage: %s [output-file]\n", progname);
424 fprintf (stderr, "%s: %s: cannot open for writing\n",
425 progname, stream_name);
429 initialize_signames ();
430 write_signames (stream);