xref: /titanic_44/usr/src/cmd/sh/error.c (revision b7f45089ccbe01bab3d7c7377b49d80d2ae18a69)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.9.5.1	*/
27 /*
28  * UNIX shell
29  */
30 
31 #include	"defs.h"
32 
33 
34 /* ========	error handling	======== */
35 
36 extern void done();
37 
38 failed(s1, s2)
39 unsigned char	*s1, *s2;
40 {
41 	prp();
42 	prs_cntl(s1);
43 	if (s2)
44 	{
45 		prs(colon);
46 		prs(s2);
47 	}
48 	newline();
49 	exitsh(ERROR);
50 }
51 
52 error(s)
53 unsigned char	*s;
54 {
55 	failed(s, NIL);
56 }
57 
58 exitsh(xno)
59 int	xno;
60 {
61 	/*
62 	 * Arrive here from `FATAL' errors
63 	 *  a) exit command,
64 	 *  b) default trap,
65 	 *  c) fault with no trap set.
66 	 *
67 	 * Action is to return to command level or exit.
68 	 */
69 	exitval = xno;
70 	flags |= eflag;
71 	if ((flags & (forcexit | forked | errflg | ttyflg)) != ttyflg)
72 		done(0);
73 	else
74 	{
75 		clearup();
76 		restore(0);
77 		(void)setb(1);
78 		execbrk = breakcnt = funcnt = 0;
79 		longjmp(errshell, 1);
80 	}
81 }
82 
83 rmtemp(base)
84 struct ionod	*base;
85 {
86 	while (iotemp > base)
87 	{
88 		unlink(iotemp->ioname);
89 		free(iotemp->iolink);
90 		iotemp = iotemp->iolst;
91 	}
92 }
93 
94 rmfunctmp()
95 {
96 	while (fiotemp)
97 	{
98 		unlink(fiotemp->ioname);
99 		fiotemp = fiotemp->iolst;
100 	}
101 }
102 
103 failure(s1, s2)
104 unsigned char	*s1, *s2;
105 {
106 	prp();
107 	prs_cntl(s1);
108 	if (s2)
109 	{
110 		prs(colon);
111 		prs(s2);
112 	}
113 	newline();
114 
115 	if (flags & errflg)
116 		exitsh(ERROR);
117 
118 	flags |= eflag;
119 	exitval = ERROR;
120 	exitset();
121 }
122