00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "config.h"
00010 #include "ansidecl.h"
00011 #include "libiberty.h"
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #define sys_siglist no_such_symbol
00023 #define sys_nsig sys_nsig__no_such_symbol
00024
00025 #include <stdio.h>
00026 #include <signal.h>
00027
00028
00029
00030 #ifdef HAVE_STDLIB_H
00031 #include <stdlib.h>
00032 #else
00033 extern PTR malloc ();
00034 #endif
00035
00036 #ifdef HAVE_STRING_H
00037 #include <string.h>
00038 #else
00039 extern PTR memset ();
00040 #endif
00041
00042
00043
00044 #undef sys_siglist
00045 #undef sys_nsig
00046
00047 #ifndef NULL
00048 # ifdef ANSI_PROTOTYPES
00049 # define NULL (void *) 0
00050 # else
00051 # define NULL 0
00052 # endif
00053 #endif
00054
00055 #ifndef MAX
00056 # define MAX(a,b) ((a) > (b) ? (a) : (b))
00057 #endif
00058
00059 static void init_signal_tables PARAMS ((void));
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 struct signal_info
00072 {
00073 const int value;
00074 const char *const name;
00075 #ifndef HAVE_SYS_SIGLIST
00076 const char *const msg;
00077 #endif
00078 };
00079
00080 #ifndef HAVE_SYS_SIGLIST
00081 # define ENTRY(value, name, msg) {value, name, msg}
00082 #else
00083 # define ENTRY(value, name, msg) {value, name}
00084 #endif
00085
00086 static const struct signal_info signal_table[] =
00087 {
00088 #if defined (SIGHUP)
00089 ENTRY(SIGHUP, "SIGHUP", "Hangup"),
00090 #endif
00091 #if defined (SIGINT)
00092 ENTRY(SIGINT, "SIGINT", "Interrupt"),
00093 #endif
00094 #if defined (SIGQUIT)
00095 ENTRY(SIGQUIT, "SIGQUIT", "Quit"),
00096 #endif
00097 #if defined (SIGILL)
00098 ENTRY(SIGILL, "SIGILL", "Illegal instruction"),
00099 #endif
00100 #if defined (SIGTRAP)
00101 ENTRY(SIGTRAP, "SIGTRAP", "Trace/breakpoint trap"),
00102 #endif
00103
00104
00105 #if defined (SIGIOT)
00106 ENTRY(SIGIOT, "SIGIOT", "IOT trap"),
00107 #endif
00108 #if defined (SIGABRT)
00109 ENTRY(SIGABRT, "SIGABRT", "Aborted"),
00110 #endif
00111 #if defined (SIGEMT)
00112 ENTRY(SIGEMT, "SIGEMT", "Emulation trap"),
00113 #endif
00114 #if defined (SIGFPE)
00115 ENTRY(SIGFPE, "SIGFPE", "Arithmetic exception"),
00116 #endif
00117 #if defined (SIGKILL)
00118 ENTRY(SIGKILL, "SIGKILL", "Killed"),
00119 #endif
00120 #if defined (SIGBUS)
00121 ENTRY(SIGBUS, "SIGBUS", "Bus error"),
00122 #endif
00123 #if defined (SIGSEGV)
00124 ENTRY(SIGSEGV, "SIGSEGV", "Segmentation fault"),
00125 #endif
00126 #if defined (SIGSYS)
00127 ENTRY(SIGSYS, "SIGSYS", "Bad system call"),
00128 #endif
00129 #if defined (SIGPIPE)
00130 ENTRY(SIGPIPE, "SIGPIPE", "Broken pipe"),
00131 #endif
00132 #if defined (SIGALRM)
00133 ENTRY(SIGALRM, "SIGALRM", "Alarm clock"),
00134 #endif
00135 #if defined (SIGTERM)
00136 ENTRY(SIGTERM, "SIGTERM", "Terminated"),
00137 #endif
00138 #if defined (SIGUSR1)
00139 ENTRY(SIGUSR1, "SIGUSR1", "User defined signal 1"),
00140 #endif
00141 #if defined (SIGUSR2)
00142 ENTRY(SIGUSR2, "SIGUSR2", "User defined signal 2"),
00143 #endif
00144
00145
00146 #if defined (SIGCLD)
00147 ENTRY(SIGCLD, "SIGCLD", "Child status changed"),
00148 #endif
00149 #if defined (SIGCHLD)
00150 ENTRY(SIGCHLD, "SIGCHLD", "Child status changed"),
00151 #endif
00152 #if defined (SIGPWR)
00153 ENTRY(SIGPWR, "SIGPWR", "Power fail/restart"),
00154 #endif
00155 #if defined (SIGWINCH)
00156 ENTRY(SIGWINCH, "SIGWINCH", "Window size changed"),
00157 #endif
00158 #if defined (SIGURG)
00159 ENTRY(SIGURG, "SIGURG", "Urgent I/O condition"),
00160 #endif
00161 #if defined (SIGIO)
00162
00163
00164
00165 ENTRY(SIGIO, "SIGIO", "I/O possible"),
00166 #endif
00167 #if defined (SIGPOLL)
00168 ENTRY(SIGPOLL, "SIGPOLL", "Pollable event occurred"),
00169 #endif
00170 #if defined (SIGSTOP)
00171 ENTRY(SIGSTOP, "SIGSTOP", "Stopped (signal)"),
00172 #endif
00173 #if defined (SIGTSTP)
00174 ENTRY(SIGTSTP, "SIGTSTP", "Stopped (user)"),
00175 #endif
00176 #if defined (SIGCONT)
00177 ENTRY(SIGCONT, "SIGCONT", "Continued"),
00178 #endif
00179 #if defined (SIGTTIN)
00180 ENTRY(SIGTTIN, "SIGTTIN", "Stopped (tty input)"),
00181 #endif
00182 #if defined (SIGTTOU)
00183 ENTRY(SIGTTOU, "SIGTTOU", "Stopped (tty output)"),
00184 #endif
00185 #if defined (SIGVTALRM)
00186 ENTRY(SIGVTALRM, "SIGVTALRM", "Virtual timer expired"),
00187 #endif
00188 #if defined (SIGPROF)
00189 ENTRY(SIGPROF, "SIGPROF", "Profiling timer expired"),
00190 #endif
00191 #if defined (SIGXCPU)
00192 ENTRY(SIGXCPU, "SIGXCPU", "CPU time limit exceeded"),
00193 #endif
00194 #if defined (SIGXFSZ)
00195 ENTRY(SIGXFSZ, "SIGXFSZ", "File size limit exceeded"),
00196 #endif
00197 #if defined (SIGWIND)
00198 ENTRY(SIGWIND, "SIGWIND", "SIGWIND"),
00199 #endif
00200 #if defined (SIGPHONE)
00201 ENTRY(SIGPHONE, "SIGPHONE", "SIGPHONE"),
00202 #endif
00203 #if defined (SIGLOST)
00204 ENTRY(SIGLOST, "SIGLOST", "Resource lost"),
00205 #endif
00206 #if defined (SIGWAITING)
00207 ENTRY(SIGWAITING, "SIGWAITING", "Process's LWPs are blocked"),
00208 #endif
00209 #if defined (SIGLWP)
00210 ENTRY(SIGLWP, "SIGLWP", "Signal LWP"),
00211 #endif
00212 #if defined (SIGDANGER)
00213 ENTRY(SIGDANGER, "SIGDANGER", "Swap space dangerously low"),
00214 #endif
00215 #if defined (SIGGRANT)
00216 ENTRY(SIGGRANT, "SIGGRANT", "Monitor mode granted"),
00217 #endif
00218 #if defined (SIGRETRACT)
00219 ENTRY(SIGRETRACT, "SIGRETRACT", "Need to relinguish monitor mode"),
00220 #endif
00221 #if defined (SIGMSG)
00222 ENTRY(SIGMSG, "SIGMSG", "Monitor mode data available"),
00223 #endif
00224 #if defined (SIGSOUND)
00225 ENTRY(SIGSOUND, "SIGSOUND", "Sound completed"),
00226 #endif
00227 #if defined (SIGSAK)
00228 ENTRY(SIGSAK, "SIGSAK", "Secure attention"),
00229 #endif
00230 ENTRY(0, NULL, NULL)
00231 };
00232
00233
00234
00235
00236 static const char **signal_names;
00237 static int num_signal_names = 0;
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 #ifndef HAVE_SYS_SIGLIST
00248
00249 static int sys_nsig;
00250 static const char **sys_siglist;
00251
00252 #else
00253
00254 #ifdef NSIG
00255 static int sys_nsig = NSIG;
00256 #else
00257 #ifdef _NSIG
00258 static int sys_nsig = _NSIG;
00259 #endif
00260 #endif
00261 extern const char * const sys_siglist[];
00262
00263 #endif
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294 static void
00295 init_signal_tables ()
00296 {
00297 const struct signal_info *eip;
00298 int nbytes;
00299
00300
00301
00302
00303 if (num_signal_names == 0)
00304 {
00305 for (eip = signal_table; eip -> name != NULL; eip++)
00306 {
00307 if (eip -> value >= num_signal_names)
00308 {
00309 num_signal_names = eip -> value + 1;
00310 }
00311 }
00312 }
00313
00314
00315
00316
00317 if (signal_names == NULL)
00318 {
00319 nbytes = num_signal_names * sizeof (char *);
00320 if ((signal_names = (const char **) malloc (nbytes)) != NULL)
00321 {
00322 memset (signal_names, 0, nbytes);
00323 for (eip = signal_table; eip -> name != NULL; eip++)
00324 {
00325 signal_names[eip -> value] = eip -> name;
00326 }
00327 }
00328 }
00329
00330 #ifndef HAVE_SYS_SIGLIST
00331
00332
00333
00334
00335 if (sys_siglist == NULL)
00336 {
00337 nbytes = num_signal_names * sizeof (char *);
00338 if ((sys_siglist = (const char **) malloc (nbytes)) != NULL)
00339 {
00340 memset (sys_siglist, 0, nbytes);
00341 sys_nsig = num_signal_names;
00342 for (eip = signal_table; eip -> name != NULL; eip++)
00343 {
00344 sys_siglist[eip -> value] = eip -> msg;
00345 }
00346 }
00347 }
00348
00349 #endif
00350
00351 }
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375 int
00376 signo_max ()
00377 {
00378 int maxsize;
00379
00380 if (signal_names == NULL)
00381 {
00382 init_signal_tables ();
00383 }
00384 maxsize = MAX (sys_nsig, num_signal_names);
00385 return (maxsize - 1);
00386 }
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 #ifndef HAVE_STRSIGNAL
00414
00415 const char *
00416 strsignal (signo)
00417 int signo;
00418 {
00419 const char *msg;
00420 static char buf[32];
00421
00422 #ifndef HAVE_SYS_SIGLIST
00423
00424 if (signal_names == NULL)
00425 {
00426 init_signal_tables ();
00427 }
00428
00429 #endif
00430
00431 if ((signo < 0) || (signo >= sys_nsig))
00432 {
00433
00434 msg = NULL;
00435 }
00436 else if ((sys_siglist == NULL) || (sys_siglist[signo] == NULL))
00437 {
00438
00439 sprintf (buf, "Signal %d", signo);
00440 msg = (const char *) buf;
00441 }
00442 else
00443 {
00444
00445 msg = (const char *) sys_siglist[signo];
00446 }
00447
00448 return (msg);
00449 }
00450
00451 #endif
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475 const char *
00476 strsigno (signo)
00477 int signo;
00478 {
00479 const char *name;
00480 static char buf[32];
00481
00482 if (signal_names == NULL)
00483 {
00484 init_signal_tables ();
00485 }
00486
00487 if ((signo < 0) || (signo >= num_signal_names))
00488 {
00489
00490 name = NULL;
00491 }
00492 else if ((signal_names == NULL) || (signal_names[signo] == NULL))
00493 {
00494
00495 sprintf (buf, "Signal %d", signo);
00496 name = (const char *) buf;
00497 }
00498 else
00499 {
00500
00501 name = signal_names[signo];
00502 }
00503
00504 return (name);
00505 }
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519 int
00520 strtosigno (name)
00521 const char *name;
00522 {
00523 int signo = 0;
00524
00525 if (name != NULL)
00526 {
00527 if (signal_names == NULL)
00528 {
00529 init_signal_tables ();
00530 }
00531 for (signo = 0; signo < num_signal_names; signo++)
00532 {
00533 if ((signal_names[signo] != NULL) &&
00534 (strcmp (name, signal_names[signo]) == 0))
00535 {
00536 break;
00537 }
00538 }
00539 if (signo == num_signal_names)
00540 {
00541 signo = 0;
00542 }
00543 }
00544 return (signo);
00545 }
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560 #ifndef HAVE_PSIGNAL
00561
00562 void
00563 psignal (signo, message)
00564 unsigned signo;
00565 char *message;
00566 {
00567 if (signal_names == NULL)
00568 {
00569 init_signal_tables ();
00570 }
00571 if ((signo <= 0) || (signo >= sys_nsig))
00572 {
00573 fprintf (stderr, "%s: unknown signal\n", message);
00574 }
00575 else
00576 {
00577 fprintf (stderr, "%s: %s\n", message, sys_siglist[signo]);
00578 }
00579 }
00580
00581 #endif
00582
00583
00584
00585
00586
00587 #ifdef MAIN
00588
00589 #include <stdio.h>
00590
00591 int
00592 main ()
00593 {
00594 int signo;
00595 int maxsigno;
00596 const char *name;
00597 const char *msg;
00598
00599 maxsigno = signo_max ();
00600 printf ("%d entries in names table.\n", num_signal_names);
00601 printf ("%d entries in messages table.\n", sys_nsig);
00602 printf ("%d is max useful index.\n", maxsigno);
00603
00604
00605
00606
00607
00608
00609 for (signo = 0; signo <= maxsigno; signo++)
00610 {
00611 name = strsigno (signo);
00612 name = (name == NULL) ? "<NULL>" : name;
00613 msg = strsignal (signo);
00614 msg = (msg == NULL) ? "<NULL>" : msg;
00615 printf ("%-4d%-18s%s\n", signo, name, msg);
00616 }
00617
00618 return 0;
00619 }
00620
00621 #endif