4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2017 Peter Tribble.
27 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
32 /* All Rights Reserved */
51 * imported global variables
54 /* imported from main.c */
56 extern struct pkgdev pkgdev
; /* holds info about the installation device */
58 extern int npkgs
; /* the number of packages yet to be installed */
59 extern int admnflag
; /* != 0 if any pkgop admin setting failed (4) */
60 extern int doreboot
; /* != 0 if reboot required after installation */
61 extern int failflag
; /* != 0 if fatal error has occurred (1) */
62 extern int intrflag
; /* != 0 if user selected quit (3) */
63 extern int ireboot
; /* != 0 if immediate reboot required */
64 extern int nullflag
; /* != 0 if admin interaction required (5) */
65 extern int warnflag
; /* != 0 if non-fatal error has occurred (2) */
68 * forward declarations
71 static char *idsName
= (char *)NULL
;
72 static char *zoneTempDir
= (char *)NULL
;
73 static ckreturnFunc_t
*ckreturnFunc
= (ckreturnFunc_t
*)NULL
;
74 static int trapEntered
= 0;
75 static void trap(int signo
);
76 static zoneList_t zoneList
= (zoneList_t
)NULL
;
82 void quit(int retcode
);
83 void quitSetCkreturnFunc(ckreturnFunc_t
*a_ckreturnFunc
);
84 void quitSetIdsName(char *a_idsName
);
85 void quitSetZoneName(char *a_zoneName
);
86 void quitSetZoneTmpdir(char *z_zoneTempDir
);
87 void quitSetZonelist(zoneList_t a_zlst
);
88 sighdlrFunc_t
*quitGetTrapHandler(void);
91 * *****************************************************************************
92 * global external (public) functions
93 * *****************************************************************************
97 * Name: quitGetTrapHandler
98 * Description: return address of this modules "signal trap" handler
100 * Returns: sighdlrFunc_t
101 * The address of the trap handler that can be passed to
102 * the signal() type system calls
112 * Name: quitSetIdsName
113 * Description: set the input data stream name to use when quit() is called
114 * Arguments: a_idsName - pointer to string representing the input data
115 * stream object currently open
116 * == NULL - there is no input datastream object to use
118 * NOTE: When quit() is called, if an input datastream object is set,
119 * quit will close the datastream and cleanup certain objects
120 * associated with the datastream
124 quitSetIdsName(char *a_idsName
)
130 * Name: quitSetCkreturnFunc
131 * Description: set the ckreturn() interface to call when quit() is called
132 * Arguments: a_ckreturnFunc - pointer to function to call when quit() is
135 * NOTE: When quit() is called if a "ckreturnfunc" is set, then the first
136 * action quit() takes is to call the "ckreturnfunc" specified with
137 * the value passed to quit as the first argument. Quit will then
138 * set the final return code to be used when exit() is called based
139 * on the contents of these global variables:
140 * - admnflag - != 0 if any pkgop admin setting failed (4)
141 * - doreboot - != 0 if reboot required after installation
142 * - failflag - != 0 if fatal error has occurred (1)
143 * - intrflag - != 0 if user selected quit (3)
144 * - ireboot - != 0 if immediate reboot required
145 * - nullflag - != 0 if admin interaction required (5)
146 * - warnflag - != 0 if non-fatal error has occurred (2)
150 quitSetCkreturnFunc(ckreturnFunc_t
*a_ckreturnFunc
)
152 ckreturnFunc
= a_ckreturnFunc
;
156 * Name: quitSetZonelist
157 * Description: set the list of zones that are "locked" so that the zones can
158 * be unlocked if quit() is called to exit
159 * Arguments: a_zlst - list of zones that are "locked"
161 * NOTE: When quit() is called, if this list is set, then z_unlock_zones
162 * is called to unlock all of the zones in the list. If this list
163 * is NOT set, then z_unlock_this_zone is called to unlock this
168 quitSetZonelist(zoneList_t a_zlst
)
174 * Name: quitSetZoneName
175 * Description: set the zone name the program is running in
176 * Arguments: a_zoneName - pointer to string representing the name of the zone
177 * that the program is running in
183 quitSetZoneName(char *a_zoneName
)
188 * Name: quitSetZoneTmpdir
189 * Description: set the path to the "zone temporary directory" in use
190 * Arguments: a_zoneTempDir - pointer to string representing the full path to
191 * the temporary directory used to hold files used during
194 * NOTE: If a zone temporary directory is set when quit() is called, the
195 * directory is recursively removed before quit() calls exit
199 quitSetZoneTmpdir(char *a_zoneTempDir
)
201 zoneTempDir
= a_zoneTempDir
;
206 * Description: cleanup and exit
207 * Arguments: a_retcode - the code to use to determine final exit status;
208 * if this is NOT "99" and if a "ckreturnFunc" is
209 * set, then that function is called with a_retcode
210 * to set the final exit status.
213 * 1 - package operation failed (fatal error)
214 * 2 - non-fatal error (warning)
215 * 3 - user selected quit (operation interrupted)
216 * 4 - admin settings prevented operation
217 * 5 - interaction required and -n (non-interactive) specified
218 * "10" is added to indicate "immediate reboot required"
219 * "20" is be added to indicate "reboot after install required"
220 * 99 - do not interpret the code - just exit "99"
221 * Returns: <<this function does not return - calls exit()>>
227 /* disable interrupts */
229 (void) signal(SIGINT
, SIG_IGN
);
230 (void) signal(SIGHUP
, SIG_IGN
);
232 if (!restore_local_fs()) {
233 progerr(ERR_CANNOT_RESTORE_LOCAL_FS
);
236 /* process return code if not quit(99) */
238 if (a_retcode
!= 99) {
239 if (ckreturnFunc
!= (ckreturnFunc_t
*)NULL
) {
240 (ckreturnFunc
)(a_retcode
);
244 } else if (warnflag
) {
246 } else if (intrflag
) {
248 } else if (admnflag
) {
250 } else if (nullflag
) {
256 a_retcode
= (a_retcode
% 10) + 20;
259 a_retcode
= (a_retcode
% 10) + 10;
263 if (doreboot
|| ireboot
) {
264 ptext(stderr
, MSG_REBOOT
);
269 /* if set remove zone temporary directory */
271 if (zoneTempDir
!= (char *)NULL
) {
272 echoDebug(DBG_REMOVING_ZONE_TMPDIR
, zoneTempDir
);
273 (void) rrmdir(zoneTempDir
);
274 zoneTempDir
= (char *)NULL
;
277 /* close and cleanup if input datastream is set */
279 if (idsName
!= (char *)NULL
) { /* datastream */
280 if (pkgdev
.dirname
!= NULL
) {
281 echoDebug(DBG_REMOVING_DSTREAM_TMPDIR
, pkgdev
.dirname
);
282 (void) rrmdir(pkgdev
.dirname
); /* from tempnam */
285 } else if (pkgdev
.mount
) {
286 (void) pkgumount(&pkgdev
);
290 * issue final exit message depending on number of packages left
295 echo(MSG_1_PKG_NOT_PROCESSED
);
297 echo(MSG_N_PKGS_NOT_PROCESSED
, npkgs
);
300 /* if a zone list exists, unlock all zones */
302 if (zoneList
!= (zoneList_t
)NULL
) {
303 (void) z_unlock_zones(zoneList
, ZLOCKS_ALL
);
305 (void) z_unlock_this_zone(ZLOCKS_ALL
);
308 /* final exit debugging message */
310 echoDebug(DBG_EXIT_WITH_CODE
, a_retcode
);
317 * *****************************************************************************
318 * static internal (private) functions
319 * *****************************************************************************
324 * Description: signal handler connected via quitGetTrapHandler()
325 * Arguments: signo - [RO, *RO] - (int)
326 * Integer representing the signal that caused the trap
327 * to this function to occur
328 * Returns: << NONE >>
329 * NOTE: This function exits the program after doing mandatory cleanup.
330 * NOTE: Even though quit() should NOT return, there is a call to _exit()
331 * put after each call to quit() just in case quit() ever returned
338 /* prevent reentrance */
340 if (trapEntered
++ != 0) {
344 if ((signo
== SIGINT
) || (signo
== SIGHUP
)) {