[c28a023] | 1 | /* signames.c -- Create and write `signames.c', which contains an array of
|
---|
| 2 | signal names. */
|
---|
| 3 |
|
---|
| 4 | /* Copyright (C) 1992 Free Software Foundation, Inc.
|
---|
| 5 |
|
---|
| 6 | This file is part of GNU Bash, the Bourne Again SHell.
|
---|
| 7 |
|
---|
| 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
|
---|
| 11 | version.
|
---|
| 12 |
|
---|
| 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
|
---|
| 16 | for more details.
|
---|
| 17 |
|
---|
| 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. */
|
---|
| 21 |
|
---|
| 22 | #include <stdio.h>
|
---|
| 23 | #include <sys/types.h>
|
---|
| 24 | #include <signal.h>
|
---|
| 25 | #include <stdlib.h>
|
---|
| 26 |
|
---|
| 27 | #if !defined (NSIG)
|
---|
| 28 | # define NSIG 64
|
---|
| 29 | #endif
|
---|
| 30 |
|
---|
| 31 | char *signal_names[2 * NSIG];
|
---|
| 32 |
|
---|
| 33 | char *progname;
|
---|
| 34 |
|
---|
| 35 | #if defined (SIGRTMAX) || defined (SIGRTMIN)
|
---|
| 36 | # define RTLEN 14
|
---|
| 37 | # define RTLIM 256
|
---|
| 38 | #endif
|
---|
| 39 |
|
---|
| 40 | void
|
---|
| 41 | initialize_signames ()
|
---|
| 42 | {
|
---|
| 43 | register int i;
|
---|
| 44 | #if defined (SIGRTMAX) || defined (SIGRTMIN)
|
---|
| 45 | int rtmin, rtmax, rtcnt;
|
---|
| 46 | #endif
|
---|
| 47 |
|
---|
| 48 | for (i = 1; i < sizeof(signal_names)/sizeof(signal_names[0]); i++)
|
---|
| 49 | signal_names[i] = (char *)NULL;
|
---|
| 50 |
|
---|
| 51 | /* `signal' 0 is what we do on exit. */
|
---|
| 52 | signal_names[0] = "EXIT";
|
---|
| 53 |
|
---|
| 54 | /* Place signal names which can be aliases for more common signal
|
---|
| 55 | names first. This allows (for example) SIGABRT to overwrite SIGLOST. */
|
---|
| 56 |
|
---|
| 57 | /* POSIX 1003.1b-1993 real time signals, but take care of incomplete
|
---|
| 58 | implementations. Acoording to the standard, both, SIGRTMIN and
|
---|
| 59 | SIGRTMAX must be defined, SIGRTMIN must be stricly less than
|
---|
| 60 | SIGRTMAX, and the difference must be at least 7, that is, there
|
---|
| 61 | must be at least eight distinct real time signals. */
|
---|
| 62 |
|
---|
| 63 | /* The generated signal names are SIGRTMIN, SIGRTMIN+1, ...,
|
---|
| 64 | SIGRTMIN+x, SIGRTMAX-x, ..., SIGRTMAX-1, SIGRTMAX. If the number
|
---|
| 65 | of RT signals is odd, there is an extra SIGRTMIN+(x+1).
|
---|
| 66 | These names are the ones used by ksh and /usr/xpg4/bin/sh on SunOS5. */
|
---|
| 67 |
|
---|
| 68 | #if defined (SIGRTMIN)
|
---|
| 69 | rtmin = SIGRTMIN;
|
---|
| 70 | signal_names[rtmin] = "SIGRTMIN";
|
---|
| 71 | #endif
|
---|
| 72 |
|
---|
| 73 | #if defined (SIGRTMAX)
|
---|
| 74 | rtmax = SIGRTMAX;
|
---|
| 75 | signal_names[rtmax] = "SIGRTMAX";
|
---|
| 76 | #endif
|
---|
| 77 |
|
---|
| 78 | #if defined (SIGRTMAX) && defined (SIGRTMIN)
|
---|
| 79 | if (rtmax > rtmin)
|
---|
| 80 | {
|
---|
| 81 | rtcnt = (rtmax - rtmin - 1) / 2;
|
---|
| 82 | /* croak if there are too many RT signals */
|
---|
| 83 | if (rtcnt >= RTLIM/2)
|
---|
| 84 | {
|
---|
| 85 | rtcnt = RTLIM/2-1;
|
---|
| 86 | fprintf(stderr, "%s: error: more than %i real time signals, fix `%s'\n",
|
---|
| 87 | progname, RTLIM, progname);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | for (i = 1; i <= rtcnt; i++)
|
---|
| 91 | {
|
---|
| 92 | signal_names[rtmin+i] = (char *)malloc(RTLEN);
|
---|
| 93 | sprintf (signal_names[rtmin+i], "SIGRTMIN+%d", i);
|
---|
| 94 | signal_names[rtmax-i] = (char *)malloc(RTLEN);
|
---|
| 95 | sprintf (signal_names[rtmax-i], "SIGRTMAX-%d", i);
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | if (rtcnt < RTLIM/2-1 && rtcnt != (rtmax-rtmin)/2)
|
---|
| 99 | {
|
---|
| 100 | /* Need an extra RTMIN signal */
|
---|
| 101 | signal_names[rtmin+rtcnt+1] = (char *)malloc(RTLEN);
|
---|
| 102 | sprintf (signal_names[rtmin+rtcnt+1], "SIGRTMIN+%d", rtcnt+1);
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 | #endif /* SIGRTMIN && SIGRTMAX */
|
---|
| 106 |
|
---|
| 107 | /* AIX */
|
---|
| 108 | #if defined (SIGLOST) /* resource lost (eg, record-lock lost) */
|
---|
| 109 | signal_names[SIGLOST] = "SIGLOST";
|
---|
| 110 | #endif
|
---|
| 111 |
|
---|
| 112 | #if defined (SIGMSG) /* HFT input data pending */
|
---|
| 113 | signal_names[SIGMSG] = "SIGMSG";
|
---|
| 114 | #endif
|
---|
| 115 |
|
---|
| 116 | #if defined (SIGDANGER) /* system crash imminent */
|
---|
| 117 | signal_names[SIGDANGER] = "SIGDANGER";
|
---|
| 118 | #endif
|
---|
| 119 |
|
---|
| 120 | #if defined (SIGMIGRATE) /* migrate process to another CPU */
|
---|
| 121 | signal_names[SIGMIGRATE] = "SIGMIGRATE";
|
---|
| 122 | #endif
|
---|
| 123 |
|
---|
| 124 | #if defined (SIGPRE) /* programming error */
|
---|
| 125 | signal_names[SIGPRE] = "SIGPRE";
|
---|
| 126 | #endif
|
---|
| 127 |
|
---|
| 128 | #if defined (SIGVIRT) /* AIX virtual time alarm */
|
---|
| 129 | signal_names[SIGVIRT] = "SIGVIRT";
|
---|
| 130 | #endif
|
---|
| 131 |
|
---|
| 132 | #if defined (SIGALRM1) /* m:n condition variables */
|
---|
| 133 | signal_names[SIGALRM1] = "SIGALRM1";
|
---|
| 134 | #endif
|
---|
| 135 |
|
---|
| 136 | #if defined (SIGWAITING) /* m:n scheduling */
|
---|
| 137 | signal_names[SIGWAITING] = "SIGWAITING";
|
---|
| 138 | #endif
|
---|
| 139 |
|
---|
| 140 | #if defined (SIGGRANT) /* HFT monitor mode granted */
|
---|
| 141 | signal_names[SIGGRANT] = "SIGGRANT";
|
---|
| 142 | #endif
|
---|
| 143 |
|
---|
| 144 | #if defined (SIGKAP) /* keep alive poll from native keyboard */
|
---|
| 145 | signal_names[SIGKAP] = "SIGKAP";
|
---|
| 146 | #endif
|
---|
| 147 |
|
---|
| 148 | #if defined (SIGRETRACT) /* HFT monitor mode retracted */
|
---|
| 149 | signal_names[SIGRETRACT] = "SIGRETRACT";
|
---|
| 150 | #endif
|
---|
| 151 |
|
---|
| 152 | #if defined (SIGSOUND) /* HFT sound sequence has completed */
|
---|
| 153 | signal_names[SIGSOUND] = "SIGSOUND";
|
---|
| 154 | #endif
|
---|
| 155 |
|
---|
| 156 | #if defined (SIGSAK) /* Secure Attention Key */
|
---|
| 157 | signal_names[SIGSAK] = "SIGSAK";
|
---|
| 158 | #endif
|
---|
| 159 |
|
---|
| 160 | /* SunOS5 */
|
---|
| 161 | #if defined (SIGLWP) /* special signal used by thread library */
|
---|
| 162 | signal_names[SIGLWP] = "SIGLWP";
|
---|
| 163 | #endif
|
---|
| 164 |
|
---|
| 165 | #if defined (SIGFREEZE) /* special signal used by CPR */
|
---|
| 166 | signal_names[SIGFREEZE] = "SIGFREEZE";
|
---|
| 167 | #endif
|
---|
| 168 |
|
---|
| 169 | #if defined (SIGTHAW) /* special signal used by CPR */
|
---|
| 170 | signal_names[SIGTHAW] = "SIGTHAW";
|
---|
| 171 | #endif
|
---|
| 172 |
|
---|
| 173 | #if defined (SIGCANCEL) /* thread cancellation signal used by libthread */
|
---|
| 174 | signal_names[SIGCANCEL] = "SIGCANCEL";
|
---|
| 175 | #endif
|
---|
| 176 |
|
---|
| 177 | /* HP-UX */
|
---|
| 178 | #if defined (SIGDIL) /* DIL signal (?) */
|
---|
| 179 | signal_names[SIGDIL] = "SIGDIL";
|
---|
| 180 | #endif
|
---|
| 181 |
|
---|
| 182 | /* System V */
|
---|
| 183 | #if defined (SIGCLD) /* Like SIGCHLD. */
|
---|
| 184 | signal_names[SIGCLD] = "SIGCLD";
|
---|
| 185 | #endif
|
---|
| 186 |
|
---|
| 187 | #if defined (SIGPWR) /* power state indication */
|
---|
| 188 | signal_names[SIGPWR] = "SIGPWR";
|
---|
| 189 | #endif
|
---|
| 190 |
|
---|
| 191 | #if defined (SIGPOLL) /* Pollable event (for streams) */
|
---|
| 192 | signal_names[SIGPOLL] = "SIGPOLL";
|
---|
| 193 | #endif
|
---|
| 194 |
|
---|
| 195 | /* Unknown */
|
---|
| 196 | #if defined (SIGWINDOW)
|
---|
| 197 | signal_names[SIGWINDOW] = "SIGWINDOW";
|
---|
| 198 | #endif
|
---|
| 199 |
|
---|
| 200 | /* Common */
|
---|
| 201 | #if defined (SIGHUP) /* hangup */
|
---|
| 202 | signal_names[SIGHUP] = "SIGHUP";
|
---|
| 203 | #endif
|
---|
| 204 |
|
---|
| 205 | #if defined (SIGINT) /* interrupt */
|
---|
| 206 | signal_names[SIGINT] = "SIGINT";
|
---|
| 207 | #endif
|
---|
| 208 |
|
---|
| 209 | #if defined (SIGQUIT) /* quit */
|
---|
| 210 | signal_names[SIGQUIT] = "SIGQUIT";
|
---|
| 211 | #endif
|
---|
| 212 |
|
---|
| 213 | #if defined (SIGILL) /* illegal instruction (not reset when caught) */
|
---|
| 214 | signal_names[SIGILL] = "SIGILL";
|
---|
| 215 | #endif
|
---|
| 216 |
|
---|
| 217 | #if defined (SIGTRAP) /* trace trap (not reset when caught) */
|
---|
| 218 | signal_names[SIGTRAP] = "SIGTRAP";
|
---|
| 219 | #endif
|
---|
| 220 |
|
---|
| 221 | #if defined (SIGIOT) /* IOT instruction */
|
---|
| 222 | signal_names[SIGIOT] = "SIGIOT";
|
---|
| 223 | #endif
|
---|
| 224 |
|
---|
| 225 | #if defined (SIGABRT) /* Cause current process to dump core. */
|
---|
| 226 | signal_names[SIGABRT] = "SIGABRT";
|
---|
| 227 | #endif
|
---|
| 228 |
|
---|
| 229 | #if defined (SIGEMT) /* EMT instruction */
|
---|
| 230 | signal_names[SIGEMT] = "SIGEMT";
|
---|
| 231 | #endif
|
---|
| 232 |
|
---|
| 233 | #if defined (SIGFPE) /* floating point exception */
|
---|
| 234 | signal_names[SIGFPE] = "SIGFPE";
|
---|
| 235 | #endif
|
---|
| 236 |
|
---|
| 237 | #if defined (SIGKILL) /* kill (cannot be caught or ignored) */
|
---|
| 238 | signal_names[SIGKILL] = "SIGKILL";
|
---|
| 239 | #endif
|
---|
| 240 |
|
---|
| 241 | #if defined (SIGBUS) /* bus error */
|
---|
| 242 | signal_names[SIGBUS] = "SIGBUS";
|
---|
| 243 | #endif
|
---|
| 244 |
|
---|
| 245 | #if defined (SIGSEGV) /* segmentation violation */
|
---|
| 246 | signal_names[SIGSEGV] = "SIGSEGV";
|
---|
| 247 | #endif
|
---|
| 248 |
|
---|
| 249 | #if defined (SIGSYS) /* bad argument to system call */
|
---|
| 250 | signal_names[SIGSYS] = "SIGSYS";
|
---|
| 251 | #endif
|
---|
| 252 |
|
---|
| 253 | #if defined (SIGPIPE) /* write on a pipe with no one to read it */
|
---|
| 254 | signal_names[SIGPIPE] = "SIGPIPE";
|
---|
| 255 | #endif
|
---|
| 256 |
|
---|
| 257 | #if defined (SIGALRM) /* alarm clock */
|
---|
| 258 | signal_names[SIGALRM] = "SIGALRM";
|
---|
| 259 | #endif
|
---|
| 260 |
|
---|
| 261 | #if defined (SIGTERM) /* software termination signal from kill */
|
---|
| 262 | signal_names[SIGTERM] = "SIGTERM";
|
---|
| 263 | #endif
|
---|
| 264 |
|
---|
| 265 | #if defined (SIGURG) /* urgent condition on IO channel */
|
---|
| 266 | signal_names[SIGURG] = "SIGURG";
|
---|
| 267 | #endif
|
---|
| 268 |
|
---|
| 269 | #if defined (SIGSTOP) /* sendable stop signal not from tty */
|
---|
| 270 | signal_names[SIGSTOP] = "SIGSTOP";
|
---|
| 271 | #endif
|
---|
| 272 |
|
---|
| 273 | #if defined (SIGTSTP) /* stop signal from tty */
|
---|
| 274 | signal_names[SIGTSTP] = "SIGTSTP";
|
---|
| 275 | #endif
|
---|
| 276 |
|
---|
| 277 | #if defined (SIGCONT) /* continue a stopped process */
|
---|
| 278 | signal_names[SIGCONT] = "SIGCONT";
|
---|
| 279 | #endif
|
---|
| 280 |
|
---|
| 281 | #if defined (SIGCHLD) /* to parent on child stop or exit */
|
---|
| 282 | signal_names[SIGCHLD] = "SIGCHLD";
|
---|
| 283 | #endif
|
---|
| 284 |
|
---|
| 285 | #if defined (SIGTTIN) /* to readers pgrp upon background tty read */
|
---|
| 286 | signal_names[SIGTTIN] = "SIGTTIN";
|
---|
| 287 | #endif
|
---|
| 288 |
|
---|
| 289 | #if defined (SIGTTOU) /* like TTIN for output if (tp->t_local<OSTOP) */
|
---|
| 290 | signal_names[SIGTTOU] = "SIGTTOU";
|
---|
| 291 | #endif
|
---|
| 292 |
|
---|
| 293 | #if defined (SIGIO) /* input/output possible signal */
|
---|
| 294 | signal_names[SIGIO] = "SIGIO";
|
---|
| 295 | #endif
|
---|
| 296 |
|
---|
| 297 | #if defined (SIGXCPU) /* exceeded CPU time limit */
|
---|
| 298 | signal_names[SIGXCPU] = "SIGXCPU";
|
---|
| 299 | #endif
|
---|
| 300 |
|
---|
| 301 | #if defined (SIGXFSZ) /* exceeded file size limit */
|
---|
| 302 | signal_names[SIGXFSZ] = "SIGXFSZ";
|
---|
| 303 | #endif
|
---|
| 304 |
|
---|
| 305 | #if defined (SIGVTALRM) /* virtual time alarm */
|
---|
| 306 | signal_names[SIGVTALRM] = "SIGVTALRM";
|
---|
| 307 | #endif
|
---|
| 308 |
|
---|
| 309 | #if defined (SIGPROF) /* profiling time alarm */
|
---|
| 310 | signal_names[SIGPROF] = "SIGPROF";
|
---|
| 311 | #endif
|
---|
| 312 |
|
---|
| 313 | #if defined (SIGWINCH) /* window changed */
|
---|
| 314 | signal_names[SIGWINCH] = "SIGWINCH";
|
---|
| 315 | #endif
|
---|
| 316 |
|
---|
| 317 | /* 4.4 BSD */
|
---|
| 318 | #if defined (SIGINFO) && !defined (_SEQUENT_) /* information request */
|
---|
| 319 | signal_names[SIGINFO] = "SIGINFO";
|
---|
| 320 | #endif
|
---|
| 321 |
|
---|
| 322 | #if defined (SIGUSR1) /* user defined signal 1 */
|
---|
| 323 | signal_names[SIGUSR1] = "SIGUSR1";
|
---|
| 324 | #endif
|
---|
| 325 |
|
---|
| 326 | #if defined (SIGUSR2) /* user defined signal 2 */
|
---|
| 327 | signal_names[SIGUSR2] = "SIGUSR2";
|
---|
| 328 | #endif
|
---|
| 329 |
|
---|
| 330 | #if defined (SIGKILLTHR) /* BeOS: Kill Thread */
|
---|
| 331 | signal_names[SIGKILLTHR] = "SIGKILLTHR";
|
---|
| 332 | #endif
|
---|
| 333 |
|
---|
| 334 | for (i = 0; i < NSIG; i++)
|
---|
| 335 | if (signal_names[i] == (char *)NULL)
|
---|
| 336 | {
|
---|
| 337 | signal_names[i] = (char *)malloc (18);
|
---|
| 338 | sprintf (signal_names[i], "SIGJUNK(%d)", i);
|
---|
| 339 | }
|
---|
| 340 |
|
---|
| 341 | signal_names[NSIG] = "DEBUG";
|
---|
| 342 | }
|
---|
| 343 |
|
---|
| 344 | void
|
---|
| 345 | write_signames (stream)
|
---|
| 346 | FILE *stream;
|
---|
| 347 | {
|
---|
| 348 | register int i;
|
---|
| 349 |
|
---|
| 350 | fprintf (stream, "/* This file was automatically created by %s.\n",
|
---|
| 351 | progname);
|
---|
| 352 | fprintf (stream, " Do not edit. Edit support/mksignames.c instead. */\n\n");
|
---|
| 353 | fprintf (stream, "#include <signal.h>\n\n");
|
---|
| 354 | fprintf (stream,
|
---|
| 355 | "/* A translation list so we can be polite to our users. */\n");
|
---|
| 356 | fprintf (stream, "char *signal_names[NSIG + 2] = {\n");
|
---|
| 357 |
|
---|
| 358 | for (i = 0; i <= NSIG; i++)
|
---|
| 359 | fprintf (stream, " \"%s\",\n", signal_names[i]);
|
---|
| 360 |
|
---|
| 361 | fprintf (stream, " (char *)0x0,\n");
|
---|
| 362 | fprintf (stream, "};\n");
|
---|
| 363 | }
|
---|
| 364 |
|
---|
| 365 | int
|
---|
| 366 | main (argc, argv)
|
---|
| 367 | int argc;
|
---|
| 368 | char **argv;
|
---|
| 369 | {
|
---|
| 370 | char *stream_name;
|
---|
| 371 | FILE *stream;
|
---|
| 372 |
|
---|
| 373 | progname = argv[0];
|
---|
| 374 |
|
---|
| 375 | if (argc == 1)
|
---|
| 376 | {
|
---|
| 377 | stream_name = "signames.c";
|
---|
| 378 | }
|
---|
| 379 | else if (argc == 2)
|
---|
| 380 | {
|
---|
| 381 | stream_name = argv[1];
|
---|
| 382 | }
|
---|
| 383 | else
|
---|
| 384 | {
|
---|
| 385 | fprintf (stderr, "Usage: %s [output-file]\n", progname);
|
---|
| 386 | exit (1);
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 | stream = fopen (stream_name, "w");
|
---|
| 390 | if (!stream)
|
---|
| 391 | {
|
---|
| 392 | fprintf (stderr, "%s: %s: cannot open for writing\n",
|
---|
| 393 | progname, stream_name);
|
---|
| 394 | exit (2);
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 | initialize_signames ();
|
---|
| 398 | write_signames (stream);
|
---|
| 399 | exit (0);
|
---|
| 400 | }
|
---|