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