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