home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / NETWORK / ISP / bind.4.8.3.lzh / BIND483 / RES / signal.c < prev    next >
C/C++ Source or Header  |  1994-01-31  |  1KB  |  64 lines

  1. #include <signal.h>
  2.  
  3. typedef int (*pfi)();
  4.  
  5. #define SIGHANDS 32
  6.  
  7. int siginit;
  8. int nhands;
  9. struct sighand {int signo; pfi action;} sighands[SIGHANDS];
  10.  
  11. static int catch();
  12.  
  13. pfi signal(sig, func)
  14. int sig;
  15. pfi func;
  16. {
  17.     register struct sighand *sp;
  18.     pfi p = SIG_DFL;
  19.  
  20.     if(!siginit) {
  21.         siginit = 1;
  22.     intercept(catch);
  23.     }
  24.     for(sp = &sighands[0]; sp < &sighands[SIGHANDS]; sp++) {
  25.         if(sp->signo == sig) {
  26.         p = sp->action;
  27.         sp->action = func;
  28.         return p;
  29.     }
  30.     }
  31.     for(sp = &sighands[0]; sp < &sighands[SIGHANDS]; sp++) {
  32.         if(sp->action == SIG_DFL) {
  33.         sp->signo = sig;
  34.         sp->action = func;
  35.         return SIG_DFL;
  36.     }
  37.     }
  38.     return (pfi)-1;
  39. }
  40.  
  41. static catch(sig)
  42. int sig;
  43. {
  44.     register struct sighand *sp;
  45.  
  46.     for(sp = &sighands[0]; sp < &sighands[SIGHANDS]; sp++) {
  47.         if(sig == sp->signo) {
  48.         /* note the sys V bug of removing the handler is not done */
  49.         /* (bsd does not have this bug) */
  50.         if(sp->action == SIG_IGN) return;
  51.         if(sp->action == SIG_DFL) break;
  52.         (*sp->action)(sig);
  53.  
  54.         return;
  55.     }
  56.     }
  57.     switch(sig) {
  58.     case SIGWAKE:
  59.         return;
  60.     default:
  61.         exit(sig);
  62.     }
  63. }
  64.