home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / libsrc87 / signal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-30  |  1.8 KB  |  92 lines

  1. /*
  2.  *        Cross Development System for Atari ST 
  3.  *     Copyright (c) 1988, Memorial University of Newfoundland
  4.  *
  5.  *   Signal routine - the signals are actually done by calling the _do_signal
  6.  * routine - similiar to kill() I guess.
  7.  *
  8.  * 1.3 ERS added SIGABRT handling, generally fixed up stuff
  9.  * 1.2 ERS added kill, changed _do_signal to an internal function
  10.  *
  11.  */
  12. #include    <signal.h>
  13. #include    <errno.h>
  14. #include    <string.h>
  15. #include    <unistd.h>
  16.  
  17. extern int __check_signals;        /* used in console i/o routines */
  18. #define SIG_EXIT    10        /* exit code */
  19.  
  20. struct sigarray_str {
  21.       __Sigfunc s_func;
  22. };
  23. /* SIG_DFL == 0, so everything is implicitly set to this */
  24.  
  25. static struct sigarray_str    sig_array[NSIG] ;
  26.  
  27. void
  28. _init_signal()            /* needed for dumping */
  29. {
  30.     bzero(sig_array, sizeof(sig_array)); /* for now */
  31. }
  32.  
  33. __Sigfunc signal(sig, func)
  34.     int    sig;
  35.       __Sigfunc func;
  36. {
  37.       __Sigfunc oldfunc;
  38.  
  39.     switch (sig) {
  40.     case SIGINT:
  41.     case SIGQUIT:
  42.         if (func != SIG_IGN)
  43.             __check_signals |= (sig==SIGINT ? 1 : 2);
  44.         else
  45.             __check_signals &= (sig==SIGINT ? ~1 : ~2);
  46.         /* falltrough */
  47.     case SIGALRM:
  48.     case SIGABRT:
  49.         oldfunc = sig_array[sig].s_func;
  50.         sig_array[sig].s_func = func;
  51.         break;
  52.     default:
  53.         errno = EINVAL;
  54.         oldfunc = SIG_ERR;
  55.     }
  56.     return oldfunc;
  57. }
  58.  
  59. static void
  60. _do_signal(sig)
  61.     int    sig;
  62. {
  63.       __Sigfunc func;
  64.  
  65.     if (sig >= 0 && sig < NSIG) {
  66.         func = sig_array[sig].s_func;
  67.         if (func == SIG_DFL)
  68.             switch (sig) {
  69.             case SIGQUIT:
  70.             case SIGINT:
  71.             case SIGALRM:
  72.             case SIGABRT:
  73.                 psignal(sig, "fatal signal received");
  74.                 _exit(SIG_EXIT + sig);
  75.             }
  76.         else if (func != SIG_IGN)
  77.             (*func)(sig);
  78.         /* else ignore it */
  79.     }
  80. }
  81.  
  82. int kill(pid, sig)
  83.     int pid, sig;
  84. {
  85.     if (pid != getpid()) {
  86.         errno = EACCESS;    /* I don't know if this is right */
  87.         return -1;
  88.     }
  89.     _do_signal(sig);
  90.     return 0;
  91. }
  92.