xref: /titanic_52/usr/src/cmd/sh/error.c (revision 39e7390a771e8a17884d4f1558a2a41422b38104)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*39e7390aSna195498  * Common Development and Distribution License (the "License").
6*39e7390aSna195498  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21965005c8Schin 
22965005c8Schin /*
23*39e7390aSna195498  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24965005c8Schin  * Use is subject to license terms.
25965005c8Schin  */
26965005c8Schin 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate 
31965005c8Schin #pragma ident	"%Z%%M%	%I%	%E% SMI"
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * UNIX shell
347c478bd9Sstevel@tonic-gate  */
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include	"defs.h"
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /* ========	error handling	======== */
407c478bd9Sstevel@tonic-gate 
41965005c8Schin void
42*39e7390aSna195498 error(const char *s)
437c478bd9Sstevel@tonic-gate {
447c478bd9Sstevel@tonic-gate 	prp();
45*39e7390aSna195498 	prs(_gettext(s));
467c478bd9Sstevel@tonic-gate 	newline();
477c478bd9Sstevel@tonic-gate 	exitsh(ERROR);
487c478bd9Sstevel@tonic-gate }
497c478bd9Sstevel@tonic-gate 
50*39e7390aSna195498 static void
51*39e7390aSna195498 failed_body(unsigned char *s1, const char *s2, unsigned char *s3, int gflag)
527c478bd9Sstevel@tonic-gate {
53*39e7390aSna195498 	prp();
54*39e7390aSna195498 	if (gflag)
55*39e7390aSna195498 		prs(_gettext((const char *)s1));
56*39e7390aSna195498 	else
57*39e7390aSna195498 		prs_cntl(s1);
58*39e7390aSna195498 	prs(colon);
59*39e7390aSna195498 	prs(_gettext(s2));
60*39e7390aSna195498 	if (s3)
61*39e7390aSna195498 		prs(s3);
62*39e7390aSna195498 	newline();
63*39e7390aSna195498 }
64*39e7390aSna195498 
65*39e7390aSna195498 void
66*39e7390aSna195498 failed_real(unsigned char *s1, const char *s2, unsigned char *s3)
67*39e7390aSna195498 {
68*39e7390aSna195498 	failed_body(s1, s2, s3, 0);
69*39e7390aSna195498 	exitsh(ERROR);
70*39e7390aSna195498 }
71*39e7390aSna195498 
72*39e7390aSna195498 void
73*39e7390aSna195498 failure_real(unsigned char *s1, const char *s2, int gflag)
74*39e7390aSna195498 {
75*39e7390aSna195498 	failed_body(s1, s2, NULL, gflag);
76*39e7390aSna195498 
77*39e7390aSna195498 	if (flags & errflg)
78*39e7390aSna195498 		exitsh(ERROR);
79*39e7390aSna195498 
80*39e7390aSna195498 	flags |= eflag;
81*39e7390aSna195498 	exitval = ERROR;
82*39e7390aSna195498 	exitset();
837c478bd9Sstevel@tonic-gate }
847c478bd9Sstevel@tonic-gate 
85965005c8Schin void
86965005c8Schin exitsh(int xno)
877c478bd9Sstevel@tonic-gate {
887c478bd9Sstevel@tonic-gate 	/*
897c478bd9Sstevel@tonic-gate 	 * Arrive here from `FATAL' errors
907c478bd9Sstevel@tonic-gate 	 *  a) exit command,
917c478bd9Sstevel@tonic-gate 	 *  b) default trap,
927c478bd9Sstevel@tonic-gate 	 *  c) fault with no trap set.
937c478bd9Sstevel@tonic-gate 	 *
947c478bd9Sstevel@tonic-gate 	 * Action is to return to command level or exit.
957c478bd9Sstevel@tonic-gate 	 */
967c478bd9Sstevel@tonic-gate 	exitval = xno;
977c478bd9Sstevel@tonic-gate 	flags |= eflag;
987c478bd9Sstevel@tonic-gate 	if ((flags & (forcexit | forked | errflg | ttyflg)) != ttyflg)
997c478bd9Sstevel@tonic-gate 		done(0);
1007c478bd9Sstevel@tonic-gate 	else
1017c478bd9Sstevel@tonic-gate 	{
1027c478bd9Sstevel@tonic-gate 		clearup();
1037c478bd9Sstevel@tonic-gate 		restore(0);
1047c478bd9Sstevel@tonic-gate 		(void) setb(1);
1057c478bd9Sstevel@tonic-gate 		execbrk = breakcnt = funcnt = 0;
1067c478bd9Sstevel@tonic-gate 		longjmp(errshell, 1);
1077c478bd9Sstevel@tonic-gate 	}
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate 
110965005c8Schin void
111965005c8Schin rmtemp(struct ionod *base)
1127c478bd9Sstevel@tonic-gate {
113965005c8Schin 	while (iotemp > base) {
1147c478bd9Sstevel@tonic-gate 		unlink(iotemp->ioname);
1157c478bd9Sstevel@tonic-gate 		free(iotemp->iolink);
1167c478bd9Sstevel@tonic-gate 		iotemp = iotemp->iolst;
1177c478bd9Sstevel@tonic-gate 	}
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate 
120965005c8Schin void
121965005c8Schin rmfunctmp(void)
1227c478bd9Sstevel@tonic-gate {
123965005c8Schin 	while (fiotemp) {
1247c478bd9Sstevel@tonic-gate 		unlink(fiotemp->ioname);
1257c478bd9Sstevel@tonic-gate 		fiotemp = fiotemp->iolst;
1267c478bd9Sstevel@tonic-gate 	}
1277c478bd9Sstevel@tonic-gate }
128