xref: /onnv-gate/usr/src/cmd/svr4pkg/pkgrm/quit.c (revision 9781:ccf49524d5dc)
1*9781SMoriah.Waterland@Sun.COM /*
2*9781SMoriah.Waterland@Sun.COM  * CDDL HEADER START
3*9781SMoriah.Waterland@Sun.COM  *
4*9781SMoriah.Waterland@Sun.COM  * The contents of this file are subject to the terms of the
5*9781SMoriah.Waterland@Sun.COM  * Common Development and Distribution License (the "License").
6*9781SMoriah.Waterland@Sun.COM  * You may not use this file except in compliance with the License.
7*9781SMoriah.Waterland@Sun.COM  *
8*9781SMoriah.Waterland@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*9781SMoriah.Waterland@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*9781SMoriah.Waterland@Sun.COM  * See the License for the specific language governing permissions
11*9781SMoriah.Waterland@Sun.COM  * and limitations under the License.
12*9781SMoriah.Waterland@Sun.COM  *
13*9781SMoriah.Waterland@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*9781SMoriah.Waterland@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*9781SMoriah.Waterland@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*9781SMoriah.Waterland@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*9781SMoriah.Waterland@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*9781SMoriah.Waterland@Sun.COM  *
19*9781SMoriah.Waterland@Sun.COM  * CDDL HEADER END
20*9781SMoriah.Waterland@Sun.COM  */
21*9781SMoriah.Waterland@Sun.COM 
22*9781SMoriah.Waterland@Sun.COM /*
23*9781SMoriah.Waterland@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24*9781SMoriah.Waterland@Sun.COM  * Use is subject to license terms.
25*9781SMoriah.Waterland@Sun.COM  */
26*9781SMoriah.Waterland@Sun.COM 
27*9781SMoriah.Waterland@Sun.COM /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*9781SMoriah.Waterland@Sun.COM /* All Rights Reserved */
29*9781SMoriah.Waterland@Sun.COM 
30*9781SMoriah.Waterland@Sun.COM 
31*9781SMoriah.Waterland@Sun.COM #include <stdio.h>
32*9781SMoriah.Waterland@Sun.COM #include <signal.h>
33*9781SMoriah.Waterland@Sun.COM #include <stdlib.h>
34*9781SMoriah.Waterland@Sun.COM #include <unistd.h>
35*9781SMoriah.Waterland@Sun.COM #include <locale.h>
36*9781SMoriah.Waterland@Sun.COM #include <libintl.h>
37*9781SMoriah.Waterland@Sun.COM #include <pkgdev.h>
38*9781SMoriah.Waterland@Sun.COM #include <pkglib.h>
39*9781SMoriah.Waterland@Sun.COM #include <instzones_api.h>
40*9781SMoriah.Waterland@Sun.COM #include <libadm.h>
41*9781SMoriah.Waterland@Sun.COM #include <libinst.h>
42*9781SMoriah.Waterland@Sun.COM #include <messages.h>
43*9781SMoriah.Waterland@Sun.COM #include "quit.h"
44*9781SMoriah.Waterland@Sun.COM 
45*9781SMoriah.Waterland@Sun.COM /*
46*9781SMoriah.Waterland@Sun.COM  * imported global variables
47*9781SMoriah.Waterland@Sun.COM  */
48*9781SMoriah.Waterland@Sun.COM 
49*9781SMoriah.Waterland@Sun.COM /* imported from main.c */
50*9781SMoriah.Waterland@Sun.COM 
51*9781SMoriah.Waterland@Sun.COM extern struct pkgdev pkgdev;	/* holds info about the installation device */
52*9781SMoriah.Waterland@Sun.COM 
53*9781SMoriah.Waterland@Sun.COM extern int	npkgs;		/* the number of packages yet to be installed */
54*9781SMoriah.Waterland@Sun.COM extern int	admnflag;	/* != 0 if any pkgop admin setting failed (4) */
55*9781SMoriah.Waterland@Sun.COM extern int	doreboot;	/* != 0 if reboot required after installation */
56*9781SMoriah.Waterland@Sun.COM extern int	failflag;	/* != 0 if fatal error has occurred (1) */
57*9781SMoriah.Waterland@Sun.COM extern int	intrflag;	/* != 0 if user selected quit (3) */
58*9781SMoriah.Waterland@Sun.COM extern int	ireboot;	/* != 0 if immediate reboot required */
59*9781SMoriah.Waterland@Sun.COM extern int	nullflag;	/* != 0 if admin interaction required (5) */
60*9781SMoriah.Waterland@Sun.COM extern int	warnflag;	/* != 0 if non-fatal error has occurred (2) */
61*9781SMoriah.Waterland@Sun.COM 
62*9781SMoriah.Waterland@Sun.COM /*
63*9781SMoriah.Waterland@Sun.COM  * forward declarations
64*9781SMoriah.Waterland@Sun.COM  */
65*9781SMoriah.Waterland@Sun.COM 
66*9781SMoriah.Waterland@Sun.COM static ckreturnFunc_t	*ckreturnFunc = (ckreturnFunc_t *)NULL;
67*9781SMoriah.Waterland@Sun.COM static intfRelocFunc_t	*intfRelocFunc = (intfRelocFunc_t *)NULL;
68*9781SMoriah.Waterland@Sun.COM static char		*zoneTempDir = (char *)NULL;
69*9781SMoriah.Waterland@Sun.COM static void		trap(int signo);
70*9781SMoriah.Waterland@Sun.COM static zoneList_t	zoneList = (zoneList_t)NULL;
71*9781SMoriah.Waterland@Sun.COM static int		trapEntered = 0;
72*9781SMoriah.Waterland@Sun.COM 
73*9781SMoriah.Waterland@Sun.COM /*
74*9781SMoriah.Waterland@Sun.COM  * exported functions
75*9781SMoriah.Waterland@Sun.COM  */
76*9781SMoriah.Waterland@Sun.COM 
77*9781SMoriah.Waterland@Sun.COM void		quit(int retcode);
78*9781SMoriah.Waterland@Sun.COM void		quitSetCkreturnFunc(ckreturnFunc_t *a_ckreturnFunc);
79*9781SMoriah.Waterland@Sun.COM void		quitSetZoneName(char *a_zoneName);
80*9781SMoriah.Waterland@Sun.COM void		quitSetZoneTmpdir(char *z_zoneTempDir);
81*9781SMoriah.Waterland@Sun.COM void		quitSetZonelist(zoneList_t a_zlst);
82*9781SMoriah.Waterland@Sun.COM sighdlrFunc_t	*quitGetTrapHandler(void);
83*9781SMoriah.Waterland@Sun.COM 
84*9781SMoriah.Waterland@Sun.COM /*
85*9781SMoriah.Waterland@Sun.COM  * *****************************************************************************
86*9781SMoriah.Waterland@Sun.COM  * global external (public) functions
87*9781SMoriah.Waterland@Sun.COM  * *****************************************************************************
88*9781SMoriah.Waterland@Sun.COM  */
89*9781SMoriah.Waterland@Sun.COM 
90*9781SMoriah.Waterland@Sun.COM /*
91*9781SMoriah.Waterland@Sun.COM  * Name:	quitGetTrapHandler
92*9781SMoriah.Waterland@Sun.COM  * Description:	return address of this modules "signal trap" handler
93*9781SMoriah.Waterland@Sun.COM  * Arguments:	void
94*9781SMoriah.Waterland@Sun.COM  * Returns:	sighdlrFunc_t
95*9781SMoriah.Waterland@Sun.COM  *			The address of the trap handler that can be passed to
96*9781SMoriah.Waterland@Sun.COM  *			the signal() type system calls
97*9781SMoriah.Waterland@Sun.COM  */
98*9781SMoriah.Waterland@Sun.COM 
99*9781SMoriah.Waterland@Sun.COM sighdlrFunc_t *
quitGetTrapHandler()100*9781SMoriah.Waterland@Sun.COM quitGetTrapHandler()
101*9781SMoriah.Waterland@Sun.COM {
102*9781SMoriah.Waterland@Sun.COM 	return (&trap);
103*9781SMoriah.Waterland@Sun.COM }
104*9781SMoriah.Waterland@Sun.COM 
105*9781SMoriah.Waterland@Sun.COM /*
106*9781SMoriah.Waterland@Sun.COM  * Name:	quitSetIntfReloc
107*9781SMoriah.Waterland@Sun.COM  * Description:	set the "intf_reloc" interface to run when quit() is called
108*9781SMoriah.Waterland@Sun.COM  * Arguments:	a_intfReloc - pointer to function to call when quit() is called
109*9781SMoriah.Waterland@Sun.COM  * Returns:	void
110*9781SMoriah.Waterland@Sun.COM  * NOTE:	When quit() is called, if an "intf_reloc" function is set, quit
111*9781SMoriah.Waterland@Sun.COM  *		will call that function to perform whatever operations it needs
112*9781SMoriah.Waterland@Sun.COM  *		to perform - typically this is needed to run "intf_reloc" when
113*9781SMoriah.Waterland@Sun.COM  *		pre-SVR4 packages have been removed
114*9781SMoriah.Waterland@Sun.COM  */
115*9781SMoriah.Waterland@Sun.COM 
116*9781SMoriah.Waterland@Sun.COM void
quitSetIntfReloc(intfRelocFunc_t * a_intfReloc)117*9781SMoriah.Waterland@Sun.COM quitSetIntfReloc(intfRelocFunc_t *a_intfReloc)
118*9781SMoriah.Waterland@Sun.COM {
119*9781SMoriah.Waterland@Sun.COM 	intfRelocFunc = a_intfReloc;
120*9781SMoriah.Waterland@Sun.COM }
121*9781SMoriah.Waterland@Sun.COM 
122*9781SMoriah.Waterland@Sun.COM /*
123*9781SMoriah.Waterland@Sun.COM  * Name:	quitSetCkreturnFunc
124*9781SMoriah.Waterland@Sun.COM  * Description:	set the ckreturn() interface to call when quit() is called
125*9781SMoriah.Waterland@Sun.COM  * Arguments:	a_ckreturnFunc - pointer to function to call when quit() is
126*9781SMoriah.Waterland@Sun.COM  *			called
127*9781SMoriah.Waterland@Sun.COM  * Returns:	void
128*9781SMoriah.Waterland@Sun.COM  * NOTE:	When quit() is called if a "ckreturnfunc" is set, then the first
129*9781SMoriah.Waterland@Sun.COM  *		action quit() takes is to call the "ckreturnfunc" specified with
130*9781SMoriah.Waterland@Sun.COM  *		the value passed to quit as the first argument. Quit will then
131*9781SMoriah.Waterland@Sun.COM  *		set the final return code to be used when exit() is called based
132*9781SMoriah.Waterland@Sun.COM  *		on the contents of these global variables:
133*9781SMoriah.Waterland@Sun.COM  *		 - admnflag - != 0 if any pkgop admin setting failed (4)
134*9781SMoriah.Waterland@Sun.COM  *		 - doreboot - != 0 if reboot required after installation
135*9781SMoriah.Waterland@Sun.COM  *		 - failflag - != 0 if fatal error has occurred (1)
136*9781SMoriah.Waterland@Sun.COM  *		 - intrflag - != 0 if user selected quit (3)
137*9781SMoriah.Waterland@Sun.COM  *		 - ireboot - != 0 if immediate reboot required
138*9781SMoriah.Waterland@Sun.COM  *		 - nullflag - != 0 if admin interaction required (5)
139*9781SMoriah.Waterland@Sun.COM  *		 - warnflag - != 0 if non-fatal error has occurred (2)
140*9781SMoriah.Waterland@Sun.COM  */
141*9781SMoriah.Waterland@Sun.COM 
142*9781SMoriah.Waterland@Sun.COM void
quitSetCkreturnFunc(ckreturnFunc_t * a_ckreturnFunc)143*9781SMoriah.Waterland@Sun.COM quitSetCkreturnFunc(ckreturnFunc_t *a_ckreturnFunc)
144*9781SMoriah.Waterland@Sun.COM {
145*9781SMoriah.Waterland@Sun.COM 	ckreturnFunc = a_ckreturnFunc;
146*9781SMoriah.Waterland@Sun.COM }
147*9781SMoriah.Waterland@Sun.COM 
148*9781SMoriah.Waterland@Sun.COM /*
149*9781SMoriah.Waterland@Sun.COM  * Name:	quitSetZonelist
150*9781SMoriah.Waterland@Sun.COM  * Description:	set the list of zones that are "locked" so that the zones can
151*9781SMoriah.Waterland@Sun.COM  *		be unlocked if quit() is called to exit
152*9781SMoriah.Waterland@Sun.COM  * Arguments:	a_zlst - list of zones that are "locked"
153*9781SMoriah.Waterland@Sun.COM  * Returns:	void
154*9781SMoriah.Waterland@Sun.COM  * NOTE:	When quit() is called, if this list is set, then z_unlock_zones
155*9781SMoriah.Waterland@Sun.COM  *		is called to unlock all of the zones in the list. If this list
156*9781SMoriah.Waterland@Sun.COM  *		is NOT set, then z_unlock_this_zone is called to unlock this
157*9781SMoriah.Waterland@Sun.COM  *		zone.
158*9781SMoriah.Waterland@Sun.COM  */
159*9781SMoriah.Waterland@Sun.COM 
160*9781SMoriah.Waterland@Sun.COM void
quitSetZonelist(zoneList_t a_zlst)161*9781SMoriah.Waterland@Sun.COM quitSetZonelist(zoneList_t a_zlst)
162*9781SMoriah.Waterland@Sun.COM {
163*9781SMoriah.Waterland@Sun.COM 	zoneList = a_zlst;
164*9781SMoriah.Waterland@Sun.COM }
165*9781SMoriah.Waterland@Sun.COM 
166*9781SMoriah.Waterland@Sun.COM /*
167*9781SMoriah.Waterland@Sun.COM  * Name:	quitSetZoneName
168*9781SMoriah.Waterland@Sun.COM  * Description:	set the zone name the program is running in
169*9781SMoriah.Waterland@Sun.COM  * Arguments:	a_zoneName - pointer to string representing the name of the zone
170*9781SMoriah.Waterland@Sun.COM  *			that the program is running in
171*9781SMoriah.Waterland@Sun.COM  * Returns:	void
172*9781SMoriah.Waterland@Sun.COM  */
173*9781SMoriah.Waterland@Sun.COM 
174*9781SMoriah.Waterland@Sun.COM /* ARGSUSED */
175*9781SMoriah.Waterland@Sun.COM void
quitSetZoneName(char * a_zoneName)176*9781SMoriah.Waterland@Sun.COM quitSetZoneName(char *a_zoneName)
177*9781SMoriah.Waterland@Sun.COM {
178*9781SMoriah.Waterland@Sun.COM }
179*9781SMoriah.Waterland@Sun.COM 
180*9781SMoriah.Waterland@Sun.COM /*
181*9781SMoriah.Waterland@Sun.COM  * Name:	quitSetZoneTmpdir
182*9781SMoriah.Waterland@Sun.COM  * Description:	set the path to the "zone temporary directory" in use
183*9781SMoriah.Waterland@Sun.COM  * Arguments:	a_zoneTempDir - pointer to string representing the full path to
184*9781SMoriah.Waterland@Sun.COM  *			the temporary directory used to hold files used during
185*9781SMoriah.Waterland@Sun.COM  *			zone operations
186*9781SMoriah.Waterland@Sun.COM  * Returns:	void
187*9781SMoriah.Waterland@Sun.COM  * NOTE:	If a zone temporary directory is set when quit() is called, the
188*9781SMoriah.Waterland@Sun.COM  *		directory is recursively removed before quit() calls exit
189*9781SMoriah.Waterland@Sun.COM  */
190*9781SMoriah.Waterland@Sun.COM 
191*9781SMoriah.Waterland@Sun.COM void
quitSetZoneTmpdir(char * a_zoneTempDir)192*9781SMoriah.Waterland@Sun.COM quitSetZoneTmpdir(char *a_zoneTempDir)
193*9781SMoriah.Waterland@Sun.COM {
194*9781SMoriah.Waterland@Sun.COM 	zoneTempDir = a_zoneTempDir;
195*9781SMoriah.Waterland@Sun.COM }
196*9781SMoriah.Waterland@Sun.COM 
197*9781SMoriah.Waterland@Sun.COM /*
198*9781SMoriah.Waterland@Sun.COM  * Name:	quit
199*9781SMoriah.Waterland@Sun.COM  * Description:	cleanup and exit
200*9781SMoriah.Waterland@Sun.COM  * Arguments:	a_retcode - the code to use to determine final exit status;
201*9781SMoriah.Waterland@Sun.COM  *			if this is NOT "99" and if a "ckreturnFunc" is
202*9781SMoriah.Waterland@Sun.COM  *			set, then that function is called with a_retcode
203*9781SMoriah.Waterland@Sun.COM  *			to set the final exit status.
204*9781SMoriah.Waterland@Sun.COM  *		Valid values are:
205*9781SMoriah.Waterland@Sun.COM  *		0 - success
206*9781SMoriah.Waterland@Sun.COM  *		1 - package operation failed (fatal error)
207*9781SMoriah.Waterland@Sun.COM  *		2 - non-fatal error (warning)
208*9781SMoriah.Waterland@Sun.COM  *		3 - user selected quit (operation interrupted)
209*9781SMoriah.Waterland@Sun.COM  *		4 - admin settings prevented operation
210*9781SMoriah.Waterland@Sun.COM  *		5 - interaction required and -n (non-interactive) specified
211*9781SMoriah.Waterland@Sun.COM  *		"10" is added to indicate "immediate reboot required"
212*9781SMoriah.Waterland@Sun.COM  *		"20" is be added to indicate "reboot after install required"
213*9781SMoriah.Waterland@Sun.COM  *		99 - do not interpret the code - just exit "99"
214*9781SMoriah.Waterland@Sun.COM  * Returns:	<<this function does not return - calls exit()>>
215*9781SMoriah.Waterland@Sun.COM  */
216*9781SMoriah.Waterland@Sun.COM 
217*9781SMoriah.Waterland@Sun.COM void
quit(int retcode)218*9781SMoriah.Waterland@Sun.COM quit(int retcode)
219*9781SMoriah.Waterland@Sun.COM {
220*9781SMoriah.Waterland@Sun.COM 	/* disable interrupts */
221*9781SMoriah.Waterland@Sun.COM 
222*9781SMoriah.Waterland@Sun.COM 	(void) signal(SIGINT, SIG_IGN);
223*9781SMoriah.Waterland@Sun.COM 	(void) signal(SIGHUP, SIG_IGN);
224*9781SMoriah.Waterland@Sun.COM 
225*9781SMoriah.Waterland@Sun.COM 	if (!(restore_local_fs())) {
226*9781SMoriah.Waterland@Sun.COM 		progerr(ERR_CANNOT_RESTORE_LOCAL_FS);
227*9781SMoriah.Waterland@Sun.COM 	}
228*9781SMoriah.Waterland@Sun.COM 
229*9781SMoriah.Waterland@Sun.COM 	/* process return code if not quit(99) */
230*9781SMoriah.Waterland@Sun.COM 
231*9781SMoriah.Waterland@Sun.COM 	if (retcode != 99) {
232*9781SMoriah.Waterland@Sun.COM 		if (ckreturnFunc != (ckreturnFunc_t *)NULL) {
233*9781SMoriah.Waterland@Sun.COM 			(ckreturnFunc)(retcode);
234*9781SMoriah.Waterland@Sun.COM 		}
235*9781SMoriah.Waterland@Sun.COM 		if (failflag) {
236*9781SMoriah.Waterland@Sun.COM 			retcode = 1;
237*9781SMoriah.Waterland@Sun.COM 		} else if (warnflag) {
238*9781SMoriah.Waterland@Sun.COM 			retcode = 2;
239*9781SMoriah.Waterland@Sun.COM 		} else if (intrflag) {
240*9781SMoriah.Waterland@Sun.COM 			retcode = 3;
241*9781SMoriah.Waterland@Sun.COM 		} else if (admnflag) {
242*9781SMoriah.Waterland@Sun.COM 			retcode = 4;
243*9781SMoriah.Waterland@Sun.COM 		} else if (nullflag) {
244*9781SMoriah.Waterland@Sun.COM 			retcode = 5;
245*9781SMoriah.Waterland@Sun.COM 		} else {
246*9781SMoriah.Waterland@Sun.COM 			retcode = 0;
247*9781SMoriah.Waterland@Sun.COM 		}
248*9781SMoriah.Waterland@Sun.COM 		if (ireboot) {
249*9781SMoriah.Waterland@Sun.COM 			retcode += 20;
250*9781SMoriah.Waterland@Sun.COM 		}
251*9781SMoriah.Waterland@Sun.COM 		if (doreboot) {
252*9781SMoriah.Waterland@Sun.COM 			retcode += 10;
253*9781SMoriah.Waterland@Sun.COM 		}
254*9781SMoriah.Waterland@Sun.COM 	}
255*9781SMoriah.Waterland@Sun.COM 
256*9781SMoriah.Waterland@Sun.COM 	if (doreboot || ireboot) {
257*9781SMoriah.Waterland@Sun.COM 		ptext(stderr, gettext(MSG_REBOOT));
258*9781SMoriah.Waterland@Sun.COM 	}
259*9781SMoriah.Waterland@Sun.COM 
260*9781SMoriah.Waterland@Sun.COM 	if (pkgdev.mount) {
261*9781SMoriah.Waterland@Sun.COM 		(void) chdir("/");
262*9781SMoriah.Waterland@Sun.COM 		(void) pkgumount(&pkgdev);
263*9781SMoriah.Waterland@Sun.COM 	}
264*9781SMoriah.Waterland@Sun.COM 
265*9781SMoriah.Waterland@Sun.COM 	/* if set remove zone temporary directory */
266*9781SMoriah.Waterland@Sun.COM 
267*9781SMoriah.Waterland@Sun.COM 	if (zoneTempDir != (char *)NULL) {
268*9781SMoriah.Waterland@Sun.COM 		echoDebug(DBG_REMOVING_ZONE_TMPDIR, zoneTempDir);
269*9781SMoriah.Waterland@Sun.COM 		(void) rrmdir(zoneTempDir);
270*9781SMoriah.Waterland@Sun.COM 		zoneTempDir = (char *)NULL;
271*9781SMoriah.Waterland@Sun.COM 	}
272*9781SMoriah.Waterland@Sun.COM 
273*9781SMoriah.Waterland@Sun.COM 	/*
274*9781SMoriah.Waterland@Sun.COM 	 * issue final exit message depending on number of packages left
275*9781SMoriah.Waterland@Sun.COM 	 * to process
276*9781SMoriah.Waterland@Sun.COM 	 */
277*9781SMoriah.Waterland@Sun.COM 
278*9781SMoriah.Waterland@Sun.COM 	if (npkgs == 1) {
279*9781SMoriah.Waterland@Sun.COM 		echo(MSG_1_PKG_NOT_PROCESSED);
280*9781SMoriah.Waterland@Sun.COM 	} else if (npkgs) {
281*9781SMoriah.Waterland@Sun.COM 		echo(MSG_N_PKGS_NOT_PROCESSED, npkgs);
282*9781SMoriah.Waterland@Sun.COM 	}
283*9781SMoriah.Waterland@Sun.COM 
284*9781SMoriah.Waterland@Sun.COM 	/* call intf_reloc function if registered */
285*9781SMoriah.Waterland@Sun.COM 
286*9781SMoriah.Waterland@Sun.COM 	if (intfRelocFunc != (intfRelocFunc_t *)NULL) {
287*9781SMoriah.Waterland@Sun.COM 		(intfRelocFunc)();
288*9781SMoriah.Waterland@Sun.COM 	}
289*9781SMoriah.Waterland@Sun.COM 
290*9781SMoriah.Waterland@Sun.COM 	/* if a zone list exists, unlock all zones */
291*9781SMoriah.Waterland@Sun.COM 
292*9781SMoriah.Waterland@Sun.COM 	if (zoneList != (zoneList_t)NULL) {
293*9781SMoriah.Waterland@Sun.COM 		(void) z_unlock_zones(zoneList, ZLOCKS_ALL);
294*9781SMoriah.Waterland@Sun.COM 	} else {
295*9781SMoriah.Waterland@Sun.COM 		(void) z_unlock_this_zone(ZLOCKS_ALL);
296*9781SMoriah.Waterland@Sun.COM 	}
297*9781SMoriah.Waterland@Sun.COM 
298*9781SMoriah.Waterland@Sun.COM 	/* final exit debugging message */
299*9781SMoriah.Waterland@Sun.COM 
300*9781SMoriah.Waterland@Sun.COM 	echoDebug(DBG_EXIT_WITH_CODE, retcode);
301*9781SMoriah.Waterland@Sun.COM 
302*9781SMoriah.Waterland@Sun.COM 	exit(retcode);
303*9781SMoriah.Waterland@Sun.COM 	/* NOTREACHED */
304*9781SMoriah.Waterland@Sun.COM }
305*9781SMoriah.Waterland@Sun.COM 
306*9781SMoriah.Waterland@Sun.COM /*
307*9781SMoriah.Waterland@Sun.COM  * *****************************************************************************
308*9781SMoriah.Waterland@Sun.COM  * static internal (private) functions
309*9781SMoriah.Waterland@Sun.COM  * *****************************************************************************
310*9781SMoriah.Waterland@Sun.COM  */
311*9781SMoriah.Waterland@Sun.COM 
312*9781SMoriah.Waterland@Sun.COM /*
313*9781SMoriah.Waterland@Sun.COM  * Name:	trap
314*9781SMoriah.Waterland@Sun.COM  * Description:	signal handler connected via quitGetTrapHandler()
315*9781SMoriah.Waterland@Sun.COM  * Arguments:	signo - [RO, *RO] - (int)
316*9781SMoriah.Waterland@Sun.COM  *			Integer representing the signal that caused the trap
317*9781SMoriah.Waterland@Sun.COM  *			to this function to occur
318*9781SMoriah.Waterland@Sun.COM  * Returns:	<< NONE >>
319*9781SMoriah.Waterland@Sun.COM  * NOTE:	This function exits the program after doing mandatory cleanup.
320*9781SMoriah.Waterland@Sun.COM  * NOTE:	Even though quit() should NOT return, there is a call to _exit()
321*9781SMoriah.Waterland@Sun.COM  *		put after each call to quit() just in case quit() ever returned
322*9781SMoriah.Waterland@Sun.COM  *		by mistake.
323*9781SMoriah.Waterland@Sun.COM  */
324*9781SMoriah.Waterland@Sun.COM 
325*9781SMoriah.Waterland@Sun.COM static void
trap(int signo)326*9781SMoriah.Waterland@Sun.COM trap(int signo)
327*9781SMoriah.Waterland@Sun.COM {
328*9781SMoriah.Waterland@Sun.COM 	/* prevent reentrance */
329*9781SMoriah.Waterland@Sun.COM 
330*9781SMoriah.Waterland@Sun.COM 	if (trapEntered++ != 0) {
331*9781SMoriah.Waterland@Sun.COM 		return;
332*9781SMoriah.Waterland@Sun.COM 	}
333*9781SMoriah.Waterland@Sun.COM 
334*9781SMoriah.Waterland@Sun.COM 	if ((signo == SIGINT) || (signo == SIGHUP)) {
335*9781SMoriah.Waterland@Sun.COM 		quit(3);
336*9781SMoriah.Waterland@Sun.COM 		_exit(3);
337*9781SMoriah.Waterland@Sun.COM 	}
338*9781SMoriah.Waterland@Sun.COM 	quit(1);
339*9781SMoriah.Waterland@Sun.COM 	_exit(1);
340*9781SMoriah.Waterland@Sun.COM }
341