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