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