1: #ifndef lint
   2: static char sccsid[] = "@(#)fault.c	4.3 8/11/83";
   3: #endif
   4: 
   5: #
   6: /*
   7:  * UNIX shell
   8:  *
   9:  * S. R. Bourne
  10:  * Bell Telephone Laboratories
  11:  *
  12:  */
  13: 
  14: #include    "defs.h"
  15: 
  16: 
  17: STRING      trapcom[MAXTRAP];
  18: BOOL        trapflg[MAXTRAP];
  19: BOOL        trapjmp[MAXTRAP];
  20: 
  21: /* ========	fault handling routines	   ======== */
  22: 
  23: 
  24: VOID    fault(sig)
  25:     REG INT     sig;
  26: {
  27:     REG INT     flag;
  28: 
  29:     IF sig==MEMF
  30:     THEN    IF setbrk(brkincr) == -1
  31:         THEN    error(nospace);
  32:         FI
  33:     ELIF sig==ALARM
  34:     THEN    IF flags&waiting
  35:         THEN    done();
  36:         FI
  37:     ELSE    flag = (trapcom[sig] ? TRAPSET : SIGSET);
  38:         trapnote |= flag;
  39:         trapflg[sig] |= flag;
  40:     FI
  41:     IF trapjmp[sig] ANDF sig==INTR
  42:     THEN
  43:         trapjmp[sig] = 0;
  44:         longjmp(INTbuf, 1);
  45:     FI
  46: }
  47: 
  48: stdsigs()
  49: {
  50:     ignsig(QUIT);
  51:     getsig(INTR);
  52:     getsig(MEMF);
  53:     getsig(ALARM);
  54: }
  55: 
  56: ignsig(n)
  57: {
  58:     REG INT     s, i;
  59: 
  60:     IF (s=signal(i=n,1)&01)==0
  61:     THEN    trapflg[i] |= SIGMOD;
  62:     FI
  63:     return(s);
  64: }
  65: 
  66: getsig(n)
  67: {
  68:     REG INT     i;
  69: 
  70:     IF trapflg[i=n]&SIGMOD ORF ignsig(i)==0
  71:     THEN    signal(i,fault);
  72:     FI
  73: }
  74: 
  75: oldsigs()
  76: {
  77:     REG INT     i;
  78:     REG STRING  t;
  79: 
  80:     i=MAXTRAP;
  81:     WHILE i--
  82:     DO  t=trapcom[i];
  83:         IF t==0 ORF *t
  84:         THEN clrsig(i);
  85:         FI
  86:         trapflg[i]=0;
  87:     OD
  88:     trapnote=0;
  89: }
  90: 
  91: clrsig(i)
  92:     INT     i;
  93: {
  94:     free(trapcom[i]); trapcom[i]=0;
  95:     IF trapflg[i]&SIGMOD
  96:     THEN    signal(i,fault);
  97:         trapflg[i] &= ~SIGMOD;
  98:     FI
  99: }
 100: 
 101: chktrap()
 102: {
 103:     /* check for traps */
 104:     REG INT     i=MAXTRAP;
 105:     REG STRING  t;
 106: 
 107:     trapnote &= ~TRAPSET;
 108:     WHILE --i
 109:     DO IF trapflg[i]&TRAPSET
 110:        THEN trapflg[i] &= ~TRAPSET;
 111:         IF t=trapcom[i]
 112:         THEN    INT savxit=exitval;
 113:             execexp(t,0);
 114:             exitval=savxit; exitset();
 115:         FI
 116:        FI
 117:     OD
 118: }

Defined functions

chktrap defined in line 101; used 2 times
clrsig defined in line 91; used 2 times
fault defined in line 24; used 3 times
getsig defined in line 66; used 4 times
ignsig defined in line 56; used 4 times
oldsigs defined in line 75; used 2 times
stdsigs defined in line 48; used 1 times

Defined variables

sccsid defined in line 2; never used
Last modified: 1983-08-12
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2861
Valid CSS Valid XHTML 1.0 Strict