home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / libg++-2.6-fsf.lha / libg++-2.6 / libiberty / strsignal.c < prev    next >
C/C++ Source or Header  |  1994-02-20  |  15KB  |  644 lines

  1. /* Extended support for using signal values.
  2.    Copyright (C) 1992 Free Software Foundation, Inc.
  3.    Written by Fred Fish.  fnf@cygnus.com
  4.  
  5. This file is part of the libiberty library.
  6. Libiberty is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Library General Public
  8. License as published by the Free Software Foundation; either
  9. version 2 of the License, or (at your option) any later version.
  10.  
  11. Libiberty is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14. Library General Public License for more details.
  15.  
  16. You should have received a copy of the GNU Library General Public
  17. License along with libiberty; see the file COPYING.LIB.  If
  18. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  19. Cambridge, MA 02139, USA.  */
  20.  
  21. #include "ansidecl.h"
  22. #include "libiberty.h"
  23.  
  24. #include "config.h"
  25.  
  26. #ifdef LOSING_SYS_SIGLIST
  27. #define sys_siglist no_such_symbol
  28. #endif
  29.  
  30. #include <stdio.h>
  31. #include <signal.h>
  32.  
  33. /*  Routines imported from standard C runtime libraries. */
  34.  
  35. #ifdef __STDC__
  36. #include <stddef.h>
  37. extern void *malloc (size_t size);                /* 4.10.3.3 */
  38. extern void *memset (void *s, int c, size_t n);            /* 4.11.6.1 */
  39. #else    /* !__STDC__ */
  40. extern char *malloc ();        /* Standard memory allocater */
  41. extern char *memset ();
  42. #endif    /* __STDC__ */
  43.  
  44. #ifdef LOSING_SYS_SIGLIST
  45. #undef sys_siglist
  46. #endif
  47.  
  48.  
  49. #ifndef NULL
  50. #  ifdef __STDC__
  51. #    define NULL (void *) 0
  52. #  else
  53. #    define NULL 0
  54. #  endif
  55. #endif
  56.  
  57. #ifndef MAX
  58. #  define MAX(a,b) ((a) > (b) ? (a) : (b))
  59. #endif
  60.  
  61. /* Translation table for signal values.
  62.  
  63.    Note that this table is generally only accessed when it is used at runtime
  64.    to initialize signal name and message tables that are indexed by signal
  65.    value.
  66.  
  67.    Not all of these signals will exist on all systems.  This table is the only
  68.    thing that should have to be updated as new signal numbers are introduced.
  69.    It's sort of ugly, but at least its portable. */
  70.  
  71. struct signal_info
  72. {
  73.   int value;        /* The numeric value from <signal.h> */
  74.   const char *name;    /* The equivalent symbolic value */
  75. #ifdef NEED_sys_siglist
  76.   const char *msg;    /* Short message about this value */
  77. #endif
  78. };
  79.  
  80. #ifdef NEED_sys_siglist
  81. #   define ENTRY(value, name, msg)    {value, name, msg}
  82. #else
  83. #   define ENTRY(value, name, msg)    {value, name}
  84. #endif
  85.  
  86. static const struct signal_info signal_table[] =
  87. {
  88. #if defined (SIGHUP)
  89.   ENTRY(SIGHUP, "SIGHUP", "Hangup"),
  90. #endif
  91. #if defined (SIGINT)
  92.   ENTRY(SIGINT, "SIGINT", "Interrupt"),
  93. #endif
  94. #if defined (SIGQUIT)
  95.   ENTRY(SIGQUIT, "SIGQUIT", "Quit"),
  96. #endif
  97. #if defined (SIGILL)
  98.   ENTRY(SIGILL, "SIGILL", "Illegal instruction"),
  99. #endif
  100. #if defined (SIGTRAP)
  101.   ENTRY(SIGTRAP, "SIGTRAP", "Trace/breakpoint trap"),
  102. #endif
  103. /* Put SIGIOT before SIGABRT, so that if SIGIOT==SIGABRT then SIGABRT
  104.    overrides SIGIOT.  SIGABRT is in ANSI and POSIX.1, and SIGIOT isn't. */
  105. #if defined (SIGIOT)
  106.   ENTRY(SIGIOT, "SIGIOT", "IOT trap"),
  107. #endif
  108. #if defined (SIGABRT)
  109.   ENTRY(SIGABRT, "SIGABRT", "Aborted"),
  110. #endif
  111. #if defined (SIGEMT)
  112.   ENTRY(SIGEMT, "SIGEMT", "Emulation trap"),
  113. #endif
  114. #if defined (SIGFPE)
  115.   ENTRY(SIGFPE, "SIGFPE", "Arithmetic exception"),
  116. #endif
  117. #if defined (SIGKILL)
  118.   ENTRY(SIGKILL, "SIGKILL", "Killed"),
  119. #endif
  120. #if defined (SIGBUS)
  121.   ENTRY(SIGBUS, "SIGBUS", "Bus error"),
  122. #endif
  123. #if defined (SIGSEGV)
  124.   ENTRY(SIGSEGV, "SIGSEGV", "Segmentation fault"),
  125. #endif
  126. #if defined (SIGSYS)
  127.   ENTRY(SIGSYS, "SIGSYS", "Bad system call"),
  128. #endif
  129. #if defined (SIGPIPE)
  130.   ENTRY(SIGPIPE, "SIGPIPE", "Broken pipe"),
  131. #endif
  132. #if defined (SIGALRM)
  133.   ENTRY(SIGALRM, "SIGALRM", "Alarm clock"),
  134. #endif
  135. #if defined (SIGTERM)
  136.   ENTRY(SIGTERM, "SIGTERM", "Terminated"),
  137. #endif
  138. #if defined (SIGUSR1)
  139.   ENTRY(SIGUSR1, "SIGUSR1", "User defined signal 1"),
  140. #endif
  141. #if defined (SIGUSR2)
  142.   ENTRY(SIGUSR2, "SIGUSR2", "User defined signal 2"),
  143. #endif
  144. /* Put SIGCLD before SIGCHLD, so that if SIGCLD==SIGCHLD then SIGCHLD
  145.    overrides SIGCLD.  SIGCHLD is in POXIX.1 */
  146. #if defined (SIGCLD)
  147.   ENTRY(SIGCLD, "SIGCLD", "Child status changed"),
  148. #endif
  149. #if defined (SIGCHLD)
  150.   ENTRY(SIGCHLD, "SIGCHLD", "Child status changed"),
  151. #endif
  152. #if defined (SIGPWR)
  153.   ENTRY(SIGPWR, "SIGPWR", "Power fail/restart"),
  154. #endif
  155. #if defined (SIGWINCH)
  156.   ENTRY(SIGWINCH, "SIGWINCH", "Window size changed"),
  157. #endif
  158. #if defined (SIGURG)
  159.   ENTRY(SIGURG, "SIGURG", "Urgent I/O condition"),
  160. #endif
  161. #if defined (SIGIO)
  162.   /* "I/O pending" has also been suggested, but is misleading since the
  163.      signal only happens when the process has asked for it, not everytime
  164.      I/O is pending. */
  165.   ENTRY(SIGIO, "SIGIO", "I/O possible"),
  166. #endif
  167. #if defined (SIGPOLL)
  168.   ENTRY(SIGPOLL, "SIGPOLL", "Pollable event occurred"),
  169. #endif
  170. #if defined (SIGSTOP)
  171.   ENTRY(SIGSTOP, "SIGSTOP", "Stopped (signal)"),
  172. #endif
  173. #if defined (SIGTSTP)
  174.   ENTRY(SIGTSTP, "SIGTSTP", "Stopped (user)"),
  175. #endif
  176. #if defined (SIGCONT)
  177.   ENTRY(SIGCONT, "SIGCONT", "Continued"),
  178. #endif
  179. #if defined (SIGTTIN)
  180.   ENTRY(SIGTTIN, "SIGTTIN", "Stopped (tty input)"),
  181. #endif
  182. #if defined (SIGTTOU)
  183.   ENTRY(SIGTTOU, "SIGTTOU", "Stopped (tty output)"),
  184. #endif
  185. #if defined (SIGVTALRM)
  186.   ENTRY(SIGVTALRM, "SIGVTALRM", "Virtual timer expired"),
  187. #endif
  188. #if defined (SIGPROF)
  189.   ENTRY(SIGPROF, "SIGPROF", "Profiling timer expired"),
  190. #endif
  191. #if defined (SIGXCPU)
  192.   ENTRY(SIGXCPU, "SIGXCPU", "CPU time limit exceeded"),
  193. #endif
  194. #if defined (SIGXFSZ)
  195.   ENTRY(SIGXFSZ, "SIGXFSZ", "File size limit exceeded"),
  196. #endif
  197. #if defined (SIGWIND)
  198.   ENTRY(SIGWIND, "SIGWIND", "SIGWIND"),
  199. #endif
  200. #if defined (SIGPHONE)
  201.   ENTRY(SIGPHONE, "SIGPHONE", "SIGPHONE"),
  202. #endif
  203. #if defined (SIGLOST)
  204.   ENTRY(SIGLOST, "SIGLOST", "Resource lost"),
  205. #endif
  206. #if defined (SIGWAITING)
  207.   ENTRY(SIGWAITING, "SIGWAITING", "Process's LWPs are blocked"),
  208. #endif
  209. #if defined (SIGLWP)
  210.   ENTRY(SIGLWP, "SIGLWP", "Signal LWP"),
  211. #endif
  212. #if defined (SIGDANGER)
  213.   ENTRY(SIGDANGER, "SIGDANGER", "Swap space dangerously low"),
  214. #endif
  215. #if defined (SIGGRANT)
  216.   ENTRY(SIGGRANT, "SIGGRANT", "Monitor mode granted"),
  217. #endif
  218. #if defined (SIGRETRACT)
  219.   ENTRY(SIGRETRACT, "SIGRETRACT", "Need to relinguish monitor mode"),
  220. #endif
  221. #if defined (SIGMSG)
  222.   ENTRY(SIGMSG, "SIGMSG", "Monitor mode data available"),
  223. #endif
  224. #if defined (SIGSOUND)
  225.   ENTRY(SIGSOUND, "SIGSOUND", "Sound completed"),
  226. #endif
  227. #if defined (SIGSAK)
  228.   ENTRY(SIGSAK, "SIGSAK", "Secure attention"),
  229. #endif
  230.   ENTRY(0, NULL, NULL)
  231. };
  232.  
  233. /* Translation table allocated and initialized at runtime.  Indexed by the
  234.    signal value to find the equivalent symbolic value. */
  235.  
  236. static const char **signal_names;
  237. static int num_signal_names = 0;
  238.  
  239. /* Translation table allocated and initialized at runtime, if it does not
  240.    already exist in the host environment.  Indexed by the signal value to find
  241.    the descriptive string.
  242.  
  243.    We don't export it for use in other modules because even though it has the
  244.    same name, it differs from other implementations in that it is dynamically
  245.    initialized rather than statically initialized. */
  246.  
  247. #ifdef NEED_sys_siglist
  248.  
  249. static int sys_nsig;
  250. static const char **sys_siglist;
  251.  
  252. #else
  253.  
  254. static int sys_nsig = NSIG;
  255. extern const char * const sys_siglist[];
  256.  
  257. #endif
  258.  
  259.  
  260. /*
  261.  
  262. NAME
  263.  
  264.     init_signal_tables -- initialize the name and message tables
  265.  
  266. SYNOPSIS
  267.  
  268.     static void init_signal_tables ();
  269.  
  270. DESCRIPTION
  271.  
  272.     Using the signal_table, which is initialized at compile time, generate
  273.     the signal_names and the sys_siglist (if needed) tables, which are
  274.     indexed at runtime by a specific signal value.
  275.  
  276. BUGS
  277.  
  278.     The initialization of the tables may fail under low memory conditions,
  279.     in which case we don't do anything particularly useful, but we don't
  280.     bomb either.  Who knows, it might succeed at a later point if we free
  281.     some memory in the meantime.  In any case, the other routines know
  282.     how to deal with lack of a table after trying to initialize it.  This
  283.     may or may not be considered to be a bug, that we don't specifically
  284.     warn about this particular failure mode.
  285.  
  286. */
  287.  
  288. static void
  289. init_signal_tables ()
  290. {
  291.   const struct signal_info *eip;
  292.   int nbytes;
  293.  
  294.   /* If we haven't already scanned the signal_table once to find the maximum
  295.      signal value, then go find it now. */
  296.  
  297.