xref: /onnv-gate/usr/src/cmd/sh/error.c (revision 2256:a9ca1c675600)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2256Sna195498  * Common Development and Distribution License (the "License").
6*2256Sna195498  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21527Schin 
22527Schin /*
23*2256Sna195498  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24527Schin  * Use is subject to license terms.
25527Schin  */
26527Schin 
270Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate 
31527Schin #pragma ident	"%Z%%M%	%I%	%E% SMI"
320Sstevel@tonic-gate /*
330Sstevel@tonic-gate  * UNIX shell
340Sstevel@tonic-gate  */
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #include	"defs.h"
370Sstevel@tonic-gate 
380Sstevel@tonic-gate 
390Sstevel@tonic-gate /* ========	error handling	======== */
400Sstevel@tonic-gate 
41527Schin void
error(const char * s)42*2256Sna195498 error(const char *s)
430Sstevel@tonic-gate {
440Sstevel@tonic-gate 	prp();
45*2256Sna195498 	prs(_gettext(s));
460Sstevel@tonic-gate 	newline();
470Sstevel@tonic-gate 	exitsh(ERROR);
480Sstevel@tonic-gate }
490Sstevel@tonic-gate 
50*2256Sna195498 static void
failed_body(unsigned char * s1,const char * s2,unsigned char * s3,int gflag)51*2256Sna195498 failed_body(unsigned char *s1, const char *s2, unsigned char *s3, int gflag)
52*2256Sna195498 {
53*2256Sna195498 	prp();
54*2256Sna195498 	if (gflag)
55*2256Sna195498 		prs(_gettext((const char *)s1));
56*2256Sna195498 	else
57*2256Sna195498 		prs_cntl(s1);
58*2256Sna195498 	prs(colon);
59*2256Sna195498 	prs(_gettext(s2));
60*2256Sna195498 	if (s3)
61*2256Sna195498 		prs(s3);
62*2256Sna195498 	newline();
63*2256Sna195498 }
64*2256Sna195498 
65527Schin void
failed_real(unsigned char * s1,const char * s2,unsigned char * s3)66*2256Sna195498 failed_real(unsigned char *s1, const char *s2, unsigned char *s3)
67*2256Sna195498 {
68*2256Sna195498 	failed_body(s1, s2, s3, 0);
69*2256Sna195498 	exitsh(ERROR);
70*2256Sna195498 }
71*2256Sna195498 
72*2256Sna195498 void
failure_real(unsigned char * s1,const char * s2,int gflag)73*2256Sna195498 failure_real(unsigned char *s1, const char *s2, int gflag)
740Sstevel@tonic-gate {
75*2256Sna195498 	failed_body(s1, s2, NULL, gflag);
76*2256Sna195498 
77*2256Sna195498 	if (flags & errflg)
78*2256Sna195498 		exitsh(ERROR);
79*2256Sna195498 
80*2256Sna195498 	flags |= eflag;
81*2256Sna195498 	exitval = ERROR;
82*2256Sna195498 	exitset();
830Sstevel@tonic-gate }
840Sstevel@tonic-gate 
85527Schin void
exitsh(int xno)86527Schin exitsh(int xno)
870Sstevel@tonic-gate {
880Sstevel@tonic-gate 	/*
890Sstevel@tonic-gate 	 * Arrive here from `FATAL' errors
900Sstevel@tonic-gate 	 *  a) exit command,
910Sstevel@tonic-gate 	 *  b) default trap,
920Sstevel@tonic-gate 	 *  c) fault with no trap set.
930Sstevel@tonic-gate 	 *
940Sstevel@tonic-gate 	 * Action is to return to command level or exit.
950Sstevel@tonic-gate 	 */
960Sstevel@tonic-gate 	exitval = xno;
970Sstevel@tonic-gate 	flags |= eflag;
980Sstevel@tonic-gate 	if ((flags & (forcexit | forked | errflg | ttyflg)) != ttyflg)
990Sstevel@tonic-gate 		done(0);
1000Sstevel@tonic-gate 	else
1010Sstevel@tonic-gate 	{
1020Sstevel@tonic-gate 		clearup();
1030Sstevel@tonic-gate 		restore(0);
104527Schin 		(void) setb(1);
1050Sstevel@tonic-gate 		execbrk = breakcnt = funcnt = 0;
1060Sstevel@tonic-gate 		longjmp(errshell, 1);
1070Sstevel@tonic-gate 	}
1080Sstevel@tonic-gate }
1090Sstevel@tonic-gate 
110527Schin void
rmtemp(struct ionod * base)111527Schin rmtemp(struct ionod *base)
1120Sstevel@tonic-gate {
113527Schin 	while (iotemp > base) {
1140Sstevel@tonic-gate 		unlink(iotemp->ioname);
1150Sstevel@tonic-gate 		free(iotemp->iolink);
1160Sstevel@tonic-gate 		iotemp = iotemp->iolst;
1170Sstevel@tonic-gate 	}
1180Sstevel@tonic-gate }
1190Sstevel@tonic-gate 
120527Schin void
rmfunctmp(void)121527Schin rmfunctmp(void)
1220Sstevel@tonic-gate {
123527Schin 	while (fiotemp) {
1240Sstevel@tonic-gate 		unlink(fiotemp->ioname);
1250Sstevel@tonic-gate 		fiotemp = fiotemp->iolst;
1260Sstevel@tonic-gate 	}
1270Sstevel@tonic-gate }
128