xref: /illumos-gate/usr/src/cmd/sh/error.c (revision 7ae111d47a973fff4c6e231cc31f271dd9cef473)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 /*
33  * UNIX shell
34  */
35 
36 #include	"defs.h"
37 
38 
39 /* ========	error handling	======== */
40 
41 void
42 error(const char *s)
43 {
44 	prp();
45 	prs(_gettext(s));
46 	newline();
47 	exitsh(ERROR);
48 }
49 
50 static void
51 failed_body(unsigned char *s1, const char *s2, unsigned char *s3, int gflag)
52 {
53 	prp();
54 	if (gflag)
55 		prs(_gettext((const char *)s1));
56 	else
57 		prs_cntl(s1);
58 	prs(colon);
59 	prs(_gettext(s2));
60 	if (s3)
61 		prs(s3);
62 	newline();
63 }
64 
65 void
66 failed_real(unsigned char *s1, const char *s2, unsigned char *s3)
67 {
68 	failed_body(s1, s2, s3, 0);
69 	exitsh(ERROR);
70 }
71 
72 void
73 failure_real(unsigned char *s1, const char *s2, int gflag)
74 {
75 	failed_body(s1, s2, NULL, gflag);
76 
77 	if (flags & errflg)
78 		exitsh(ERROR);
79 
80 	flags |= eflag;
81 	exitval = ERROR;
82 	exitset();
83 }
84 
85 void
86 exitsh(int xno)
87 {
88 	/*
89 	 * Arrive here from `FATAL' errors
90 	 *  a) exit command,
91 	 *  b) default trap,
92 	 *  c) fault with no trap set.
93 	 *
94 	 * Action is to return to command level or exit.
95 	 */
96 	exitval = xno;
97 	flags |= eflag;
98 	if ((flags & (forcexit | forked | errflg | ttyflg)) != ttyflg)
99 		done(0);
100 	else
101 	{
102 		clearup();
103 		restore(0);
104 		(void) setb(1);
105 		execbrk = breakcnt = funcnt = 0;
106 		longjmp(errshell, 1);
107 	}
108 }
109 
110 void
111 rmtemp(struct ionod *base)
112 {
113 	while (iotemp > base) {
114 		unlink(iotemp->ioname);
115 		free(iotemp->iolink);
116 		iotemp = iotemp->iolst;
117 	}
118 }
119 
120 void
121 rmfunctmp(void)
122 {
123 	while (fiotemp) {
124 		unlink(fiotemp->ioname);
125 		fiotemp = fiotemp->iolst;
126 	}
127 }
128