make_siglist.c

Tor Lillqvist tml at hemuli.atk.vtt.fi
Wed Jun 7 21:10:25 AEST 1989


With all the SysV/BSD hybrids out there, one cannot assume anything
about the values of the SIG* macros.  Another problem is that
sys_siglist isn't available on many systems.

This program generates a file that defines the BSD-style sys_siglist
array and a signal_names array.

It is easy to add more exotic signals.

/*
 * make_siglist -- create a file defining sys_siglist and signal_names
 *
 */

#include <stdio.h>
#include <sys/signal.h>

char *sys_siglist[NSIG];
char *signal_names[NSIG];

void
setup_siglist()
{
  int i;
  for (i = 0; i < NSIG; i++)
    sys_siglist[i] = NULL, signal_names[i] = NULL;

  sys_siglist[0] = "No signal";
  signal_names[0] = "ON_EXIT";
  sys_siglist[SIGHUP] = "Hangup";
  signal_names[SIGHUP] = "SIGHUP";
  sys_siglist[SIGINT] = "Interrupt";
  signal_names[SIGINT] = "SIGINT";
  sys_siglist[SIGQUIT] = "Quit";
  signal_names[SIGQUIT] = "SIGQUIT";
  sys_siglist[SIGILL] = "Illegal instruction";
  signal_names[SIGILL] = "SIGILL";
  sys_siglist[SIGTRAP] = "Trace trap";
  signal_names[SIGTRAP] = "SIGTRAP";
#ifdef SIGABRT
  sys_siglist[SIGABRT] = "Abnormal termination";
  signal_names[SIGABRT] = "SIGABRT";
#endif
#if defined(SIGIOT) && (!defined(SIGABRT) || SIGIOT != SIGABRT)
  sys_siglist[SIGIOT] = "IOT instruction";
  signal_names[SIGIOT] = "SIGIOT";
#endif
#ifdef SIGEMT
  sys_siglist[SIGEMT] = "EMT instruction";
  signal_names[SIGEMT] = "SIGEMT";
#endif
#ifdef SIGFPE
  sys_siglist[SIGFPE] = "Floating point exception";
  signal_names[SIGFPE] = "SIGFPE";
#endif
  sys_siglist[SIGKILL] = "Killed";
  signal_names[SIGKILL] = "SIGKILL";
  sys_siglist[SIGBUS] = "Bus error";
  signal_names[SIGBUS] = "SIGBUS";
  sys_siglist[SIGSEGV] = "Segmentation violation";
  signal_names[SIGSEGV] = "SIGSEG";
#ifdef SIGSYS
  sys_siglist[SIGSYS] = "Bad argument to system call";
  signal_names[SIGSYS] = "SIGSYS";
#endif
  sys_siglist[SIGPIPE] = "Write on pipe with no one reading";
  signal_names[SIGPIPE] = "SIGPIPE";
  sys_siglist[SIGALRM] = "Alarm clock";
  signal_names[SIGALRM] = "SIGALRM";
  sys_siglist[SIGTERM] = "Software termination";
  signal_names[SIGTERM] = "SIGTERM";
#ifdef SIGUSR1
  sys_siglist[SIGUSR1] = "User defined signal 1";
  signal_names[SIGUSR1] = "SIGUSR1";
#endif
#ifdef SIGUSR2
  sys_siglist[SIGUSR2] = "User defined signal 2";
  signal_names[SIGUSR2] = "SIGUSR2";
#endif
#ifdef SIGCLD
  sys_siglist[SIGCLD] = "Death of child";
  signal_names[SIGCLD] = "SIGCLD";
#endif
#if defined(SIGCHLD) && (!defined(SIGCLD) || SIGCHLD != SIGCLD)
  sys_siglist[SIGCHLD] = "Death of child";
  signal_names[SIGCHLD] = "SIGCHLD";
#endif
#ifdef SIGPWR
  sys_siglist[SIGPWR] = "Power fail restart";
  signal_names[SIGPWR] = "SIGPWR";
#endif
#ifdef SIGVTALRM
  sys_siglist[SIGVTALRM] = "Virtual timer alarm clock";
  signal_names[SIGVTALRM] = "SIGVTALRM";
#endif
#ifdef SIGPROF
  sys_siglist[SIGPROF] = "Profiling timer alarm clock";
  signal_names[SIGPROF] = "SIGPROF";
#endif
#ifdef SIGIO
  sys_siglist[SIGIO] = "Asynchronous I/O";
  signal_names[SIGIO] = "SIGIO";
#endif
#ifdef SIGWINDOW
  sys_siglist[SIGWINDOW] = "Window changed";
  signal_names[SIGWINDOW] = "SIGWINDOW";
#endif
#ifdef SIGWINCH
  sys_siglist[SIGWINCH] = "Window changed";
  signal_names[SIGWINCH] = "SIGWINCH";
#endif
#ifdef SIGSTOP
  sys_siglist[SIGSTOP] = "Stopped";
  signal_names[SIGSTOP] = "SIGSTOP";
#endif
#ifdef SIGTSTP
  sys_siglist[SIGTSTP] = "Stopped from keyboard";
  signal_names[SIGTSTP] = "SIGTSTP";
#endif
#ifdef SIGCONT
  sys_siglist[SIGCONT] = "Continued";
  signal_names[SIGCONT] = "SIGCONT";
#endif
#ifdef SIGTTIN
  sys_siglist[SIGTTIN] = "Attempted background read";
  signal_names[SIGTTIN] = "SIGTTIN";
#endif
#ifdef SIGTTOU
  sys_siglist[SIGTTOU] = "Attempted background write";
  signal_names[SIGTTOU] = "SIGTTOU";
#endif
#ifdef SIGURG
  sys_siglist[SIGURG] = "Urgent data";
  signal_names[SIGURG] = "SIGURG";
#endif
#ifdef SIGXCPU
  sys_siglist[SIGXCPU] = "CPU quota exceeded";
  signal_names[SIGXCPU] = "SIGXCPU";
#endif
#ifdef SIGXFSZ
  sys_siglist[SIGXFSZ] = "File space quota exceeded";
  signal_names[SIGXFSZ] = "SIGXFSZ";
#endif
#ifdef SIGLOST
  sys_siglist[SIGLOST] = "Resource lost";
  signal_names[SIGLOST] = "SIGLOST";
#endif
}

main()
{
  int i;

  setup_siglist();
  
  printf("/* This file was produced by running make_siglist.  Don't edit. */\n\
\n\
char *sys_siglist[] = {\n");
  for (i = 0; i < NSIG; i++) {
    sys_siglist[i] ?
      printf("  \"%s\"", sys_siglist[i]) :
	printf("  \"Signal %d\"", i);
    if (i < NSIG-1)
      putchar(',');
    putchar('\n');
  }
    
  printf("};\n\n");

  printf("char *signal_names[] = {\n");
  for (i = 0; i < NSIG; i++) {
    signal_names[i] ?
      printf(" \"%s\"", signal_names[i]) :
	printf("  \"0\"");
    if (i < NSIG-1)
      putchar(',');
    putchar('\n');
  }
  printf("};\n");

  exit(0);
}

-- 
Tor Lillqvist
Technical Research Centre of Finland, Computing Services (VTT/ATK)
tml at hemuli.atk.vtt.fi [130.188.52.2]



More information about the Alt.sources mailing list