1 /* signames.c -- Create and write `signames.h', which contains an array of
4 /* Copyright (C) 1992 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 */
43 #define LASTSIG NSIG+1
45 char *signal_names[2 * NSIG + 3];
47 #define signal_names_size (sizeof(signal_names)/sizeof(signal_names[0]))
51 /* AIX 4.3 defines SIGRTMIN and SIGRTMAX as 888 and 999 respectively.
52 I don't want to allocate so much unused space for the intervening signal
53 numbers, so we just punt if SIGRTMAX is past the bounds of the
54 signal_names array (handled in configure). */
55 #if defined (SIGRTMAX) && defined (UNUSABLE_RT_SIGNALS)
60 #if defined (SIGRTMAX) || defined (SIGRTMIN)
66 initialize_signames ()
69 #if defined (SIGRTMAX) || defined (SIGRTMIN)
70 int rtmin, rtmax, rtcnt;
73 for (i = 1; i < signal_names_size; i++)
74 signal_names[i] = (char *)NULL;
76 /* `signal' 0 is what we do on exit. */
77 signal_names[0] = "EXIT";
79 /* Place signal names which can be aliases for more common signal
80 names first. This allows (for example) SIGABRT to overwrite SIGLOST. */
82 /* POSIX 1003.1b-1993 real time signals, but take care of incomplete
83 implementations. Acoording to the standard, both, SIGRTMIN and
84 SIGRTMAX must be defined, SIGRTMIN must be stricly less than
85 SIGRTMAX, and the difference must be at least 7, that is, there
86 must be at least eight distinct real time signals. */
88 /* The generated signal names are SIGRTMIN, SIGRTMIN+1, ...,
89 SIGRTMIN+x, SIGRTMAX-x, ..., SIGRTMAX-1, SIGRTMAX. If the number
90 of RT signals is odd, there is an extra SIGRTMIN+(x+1).
91 These names are the ones used by ksh and /usr/xpg4/bin/sh on SunOS5. */
93 #if defined (SIGRTMIN)
95 signal_names[rtmin] = "SIGRTMIN";
98 #if defined (SIGRTMAX)
100 signal_names[rtmax] = "SIGRTMAX";
103 #if defined (SIGRTMAX) && defined (SIGRTMIN)
106 rtcnt = (rtmax - rtmin - 1) / 2;
107 /* croak if there are too many RT signals */
108 if (rtcnt >= RTLIM/2)
111 fprintf(stderr, "%s: error: more than %i real time signals, fix `%s'\n",
112 progname, RTLIM, progname);
115 for (i = 1; i <= rtcnt; i++)
117 signal_names[rtmin+i] = (char *)malloc(RTLEN);
118 if (signal_names[rtmin+i])
119 sprintf (signal_names[rtmin+i], "SIGRTMIN+%d", i);
120 signal_names[rtmax-i] = (char *)malloc(RTLEN);
121 if (signal_names[rtmax-i])
122 sprintf (signal_names[rtmax-i], "SIGRTMAX-%d", i);
125 if (rtcnt < RTLIM/2-1 && rtcnt != (rtmax-rtmin)/2)
127 /* Need an extra RTMIN signal */
128 signal_names[rtmin+rtcnt+1] = (char *)malloc(RTLEN);
129 if (signal_names[rtmin+rtcnt+1])
130 sprintf (signal_names[rtmin+rtcnt+1], "SIGRTMIN+%d", rtcnt+1);
133 #endif /* SIGRTMIN && SIGRTMAX */
136 #if defined (SIGLOST) /* resource lost (eg, record-lock lost) */
137 signal_names[SIGLOST] = "SIGLOST";
140 #if defined (SIGMSG) /* HFT input data pending */
141 signal_names[SIGMSG] = "SIGMSG";
144 #if defined (SIGDANGER) /* system crash imminent */
145 signal_names[SIGDANGER] = "SIGDANGER";
148 #if defined (SIGMIGRATE) /* migrate process to another CPU */
149 signal_names[SIGMIGRATE] = "SIGMIGRATE";
152 #if defined (SIGPRE) /* programming error */
153 signal_names[SIGPRE] = "SIGPRE";
156 #if defined (SIGVIRT) /* AIX virtual time alarm */
157 signal_names[SIGVIRT] = "SIGVIRT";
160 #if defined (SIGALRM1) /* m:n condition variables */
161 signal_names[SIGALRM1] = "SIGALRM1";
164 #if defined (SIGWAITING) /* m:n scheduling */
165 signal_names[SIGWAITING] = "SIGWAITING";
168 #if defined (SIGGRANT) /* HFT monitor mode granted */
169 signal_names[SIGGRANT] = "SIGGRANT";
172 #if defined (SIGKAP) /* keep alive poll from native keyboard */
173 signal_names[SIGKAP] = "SIGKAP";
176 #if defined (SIGRETRACT) /* HFT monitor mode retracted */
177 signal_names[SIGRETRACT] = "SIGRETRACT";
180 #if defined (SIGSOUND) /* HFT sound sequence has completed */
181 signal_names[SIGSOUND] = "SIGSOUND";
184 #if defined (SIGSAK) /* Secure Attention Key */
185 signal_names[SIGSAK] = "SIGSAK";
189 #if defined (SIGLWP) /* special signal used by thread library */
190 signal_names[SIGLWP] = "SIGLWP";
193 #if defined (SIGFREEZE) /* special signal used by CPR */
194 signal_names[SIGFREEZE] = "SIGFREEZE";
197 #if defined (SIGTHAW) /* special signal used by CPR */
198 signal_names[SIGTHAW] = "SIGTHAW";
201 #if defined (SIGCANCEL) /* thread cancellation signal used by libthread */
202 signal_names[SIGCANCEL] = "SIGCANCEL";
206 #if defined (SIGDIL) /* DIL signal (?) */
207 signal_names[SIGDIL] = "SIGDIL";
211 #if defined (SIGCLD) /* Like SIGCHLD. */
212 signal_names[SIGCLD] = "SIGCLD";
215 #if defined (SIGPWR) /* power state indication */
216 signal_names[SIGPWR] = "SIGPWR";
219 #if defined (SIGPOLL) /* Pollable event (for streams) */
220 signal_names[SIGPOLL] = "SIGPOLL";
224 #if defined (SIGWINDOW)
225 signal_names[SIGWINDOW] = "SIGWINDOW";
229 #if defined (SIGHUP) /* hangup */
230 signal_names[SIGHUP] = "SIGHUP";
233 #if defined (SIGINT) /* interrupt */
234 signal_names[SIGINT] = "SIGINT";
237 #if defined (SIGQUIT) /* quit */
238 signal_names[SIGQUIT] = "SIGQUIT";
241 #if defined (SIGILL) /* illegal instruction (not reset when caught) */
242 signal_names[SIGILL] = "SIGILL";
245 #if defined (SIGTRAP) /* trace trap (not reset when caught) */
246 signal_names[SIGTRAP] = "SIGTRAP";
249 #if defined (SIGIOT) /* IOT instruction */
250 signal_names[SIGIOT] = "SIGIOT";
253 #if defined (SIGABRT) /* Cause current process to dump core. */
254 signal_names[SIGABRT] = "SIGABRT";
257 #if defined (SIGEMT) /* EMT instruction */
258 signal_names[SIGEMT] = "SIGEMT";
261 #if defined (SIGFPE) /* floating point exception */
262 signal_names[SIGFPE] = "SIGFPE";
265 #if defined (SIGKILL) /* kill (cannot be caught or ignored) */
266 signal_names[SIGKILL] = "SIGKILL";
269 #if defined (SIGBUS) /* bus error */
270 signal_names[SIGBUS] = "SIGBUS";
273 #if defined (SIGSEGV) /* segmentation violation */
274 signal_names[SIGSEGV] = "SIGSEGV";
277 #if defined (SIGSYS) /* bad argument to system call */
278 signal_names[SIGSYS] = "SIGSYS";
281 #if defined (SIGPIPE) /* write on a pipe with no one to read it */
282 signal_names[SIGPIPE] = "SIGPIPE";
285 #if defined (SIGALRM) /* alarm clock */
286 signal_names[SIGALRM] = "SIGALRM";
289 #if defined (SIGTERM) /* software termination signal from kill */
290 signal_names[SIGTERM] = "SIGTERM";
293 #if defined (SIGURG) /* urgent condition on IO channel */
294 signal_names[SIGURG] = "SIGURG";
297 #if defined (SIGSTOP) /* sendable stop signal not from tty */
298 signal_names[SIGSTOP] = "SIGSTOP";
301 #if defined (SIGTSTP) /* stop signal from tty */
302 signal_names[SIGTSTP] = "SIGTSTP";
305 #if defined (SIGCONT) /* continue a stopped process */
306 signal_names[SIGCONT] = "SIGCONT";
309 #if defined (SIGCHLD) /* to parent on child stop or exit */
310 signal_names[SIGCHLD] = "SIGCHLD";
313 #if defined (SIGTTIN) /* to readers pgrp upon background tty read */
314 signal_names[SIGTTIN] = "SIGTTIN";
317 #if defined (SIGTTOU) /* like TTIN for output if (tp->t_local<OSTOP) */
318 signal_names[SIGTTOU] = "SIGTTOU";
321 #if defined (SIGIO) /* input/output possible signal */
322 signal_names[SIGIO] = "SIGIO";
325 #if defined (SIGXCPU) /* exceeded CPU time limit */
326 signal_names[SIGXCPU] = "SIGXCPU";
329 #if defined (SIGXFSZ) /* exceeded file size limit */
330 signal_names[SIGXFSZ] = "SIGXFSZ";
333 #if defined (SIGVTALRM) /* virtual time alarm */
334 signal_names[SIGVTALRM] = "SIGVTALRM";
337 #if defined (SIGPROF) /* profiling time alarm */
338 signal_names[SIGPROF] = "SIGPROF";
341 #if defined (SIGWINCH) /* window changed */
342 signal_names[SIGWINCH] = "SIGWINCH";
346 #if defined (SIGINFO) && !defined (_SEQUENT_) /* information request */
347 signal_names[SIGINFO] = "SIGINFO";
350 #if defined (SIGUSR1) /* user defined signal 1 */
351 signal_names[SIGUSR1] = "SIGUSR1";
354 #if defined (SIGUSR2) /* user defined signal 2 */
355 signal_names[SIGUSR2] = "SIGUSR2";
358 #if defined (SIGKILLTHR) /* BeOS: Kill Thread */
359 signal_names[SIGKILLTHR] = "SIGKILLTHR";
362 for (i = 0; i < NSIG; i++)
363 if (signal_names[i] == (char *)NULL)
365 signal_names[i] = (char *)malloc (18);
367 sprintf (signal_names[i], "SIGJUNK(%d)", i);
370 signal_names[NSIG] = "DEBUG";
371 signal_names[NSIG+1] = "ERR";
375 write_signames (stream)
380 fprintf (stream, "/* This file was automatically created by %s.\n",
382 fprintf (stream, " Do not edit. Edit support/mksignames.c instead. */\n\n");
384 "/* A translation list so we can be polite to our users. */\n");
385 fprintf (stream, "char *signal_names[NSIG + 3] = {\n");
387 for (i = 0; i <= LASTSIG; i++)
388 fprintf (stream, " \"%s\",\n", signal_names[i]);
390 fprintf (stream, " (char *)0x0\n");
391 fprintf (stream, "};\n");
406 stream_name = "stdout";
411 stream_name = argv[1];
412 stream = fopen (stream_name, "w");
416 fprintf (stderr, "Usage: %s [output-file]\n", progname);
422 fprintf (stderr, "%s: %s: cannot open for writing\n",
423 progname, stream_name);
427 initialize_signames ();
428 write_signames (stream);