| 1 | # |
| 2 | /* |
| 3 | * UNIX shell |
| 4 | * |
| 5 | * S. R. Bourne |
| 6 | * Bell Telephone Laboratories |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #include "defs.h" |
| 11 | |
| 12 | |
| 13 | /* ======== error handling ======== */ |
| 14 | |
| 15 | exitset() |
| 16 | { |
| 17 | assnum(&exitadr,exitval); |
| 18 | } |
| 19 | |
| 20 | sigchk() |
| 21 | { |
| 22 | /* Find out if it is time to go away. |
| 23 | * `trapnote' is set to SIGSET when fault is seen and |
| 24 | * no trap has been set. |
| 25 | */ |
| 26 | IF trapnote&SIGSET |
| 27 | THEN exitsh(SIGFAIL); |
| 28 | FI |
| 29 | } |
| 30 | |
| 31 | failed(s1,s2) |
| 32 | STRING s1, s2; |
| 33 | { |
| 34 | prp(); prs(s1); |
| 35 | IF s2 |
| 36 | THEN prs(colon); prs(s2); |
| 37 | FI |
| 38 | newline(); exitsh(ERROR); |
| 39 | } |
| 40 | |
| 41 | error(s) |
| 42 | STRING s; |
| 43 | { |
| 44 | failed(s,NIL); |
| 45 | } |
| 46 | |
| 47 | exitsh(xno) |
| 48 | INT xno; |
| 49 | { |
| 50 | /* Arrive here from `FATAL' errors |
| 51 | * a) exit command, |
| 52 | * b) default trap, |
| 53 | * c) fault with no trap set. |
| 54 | * |
| 55 | * Action is to return to command level or exit. |
| 56 | */ |
| 57 | exitval=xno; |
| 58 | IF (flags & (forked|errflg|ttyflg)) != ttyflg |
| 59 | THEN done(); |
| 60 | ELSE clearup(); |
| 61 | longjmp(errshell,1); |
| 62 | FI |
| 63 | } |
| 64 | |
| 65 | done() |
| 66 | { |
| 67 | REG STRING t; |
| 68 | IF t=trapcom[0] |
| 69 | THEN trapcom[0]=0; /*should free but not long */ |
| 70 | execexp(t,0); |
| 71 | FI |
| 72 | rmtemp(0); |
| 73 | exit(exitval); |
| 74 | } |
| 75 | |
| 76 | rmtemp(base) |
| 77 | IOPTR base; |
| 78 | { |
| 79 | WHILE iotemp>base |
| 80 | DO unlink(iotemp->ioname); |
| 81 | iotemp=iotemp->iolst; |
| 82 | OD |
| 83 | } |