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