main.c revision 9ab815e1e50104cb1004a5ccca7a6da582994b57
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* System includes
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <locale.h>
#include <libintl.h>
#include <pkgstrct.h>
#include <pkgdev.h>
#include <pkginfo.h>
#include <pkglocs.h>
#include <pkglib.h>
#include <assert.h>
/*
* libinstzones includes
*/
#include <instzones_api.h>
/*
* consolidation pkg command library includes
*/
#include <pkglib.h>
/*
* local pkg command library includes
*/
#include "install.h"
#include "libinst.h"
#include "libadm.h"
#include "messages.h"
/*
* pkgrm local includes
*/
#include "quit.h"
/*
* exported global variables
*/
/* these globals are set by ckreturn and used by quit.c */
int admnflag = 0; /* != 0 if any pkg op admin setting failure (4) */
int doreboot = 0; /* != 0 if reboot required after installation */
int failflag = 0; /* != 0 if fatal error has occurred (1) */
int intrflag = 0; /* != 0 if user selected quit (3) */
int ireboot = 0; /* != 0 if immediate reboot required */
int nullflag = 0; /* != 0 if admin interaction required (5) */
int warnflag = 0; /* != 0 if non-fatal error has occurred (2) */
/* imported by quit.c */
int npkgs = 0; /* the number of packages yet to be installed */
/* imported by presvr4.c */
int started = 0;
/* imported by various (many) */
/*
* internal global variables
*/
static char *vfstab_file = NULL;
static char *zoneTempDir = (char *)NULL;
/* set by ckreturn() */
static int interrupted = 0; /* last pkg op was quit (1,2,3,4,5) */
static int nointeract = 0; /* non-zero - no user interaction */
static int pkgrmremote = 0; /* remove pkg objs stored remotely */
static int pkgverbose = 0; /* non-zero if verbose mode selected */
/*
* Assume the package complies with the standards as regards user
* interaction during procedure scripts.
*/
static int old_pkg = 0;
static int old_symlinks = 0;
static int no_map_client = 0;
/* Set by -O nozones: do not process any zones */
/* Set by -O zonelist=<names...>: process only named zones */
/* Set by -O debug: debug output is enabled? */
/*
* imported (external) functions
*/
/* check.c */
char *a_zoneTempDir);
/* quit.c */
/*
* imported (external) variables
*/
extern char *pkgdir;
/* printable string - if string is null results in ??? */
#define MAX_FDS 20
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#define TEXT_DOMAIN "SYS_TEST"
#endif
/*
* forward declarations
*/
static void create_zone_adminfile(char **r_zoneAdminFile,
char *a_zoneTempDir, char *a_admnfile);
static void create_zone_tempdir(char **r_zoneTempDir,
char *a_tmpdir);
int a_longestPkg, char *a_adminFile,
char *a_adminFile);
char *a_adminFile, char *a_stdoutPath,
char *a_altBinDir, char *a_adminFile,
static void resetreturn();
static void usage(void);
char *a_pkgInst, char *a_rootPath,
int a_longestPkg, int a_repeat,
char *a_altBinDir, char *a_pkgdir,
char *a_altBinDir);
char *a_altBinDir);
char *a_altBinDir, char *a_pkgdir,
char *a_altBinDir, char *a_pkgdir);
/*
* *****************************************************************************
* global external (public) functions
* *****************************************************************************
*/
/*
* Name: main
* Description: main entry point for pkgrm
* Returns: int
* 0 Successful completion
* 1 Fatal error.
* 2 Warning.
* 3 Interruption.
* 4 Administration.
* 5 Administration. Interaction is required. Do not use pkgrm -n.
* 10 Reboot after removal of all packages.
* 20 Reboot after removal of this package.
*/
int
{
char *p;
char *prog_full_name = NULL;
char *spoolDir = 0;
int c;
int longestPkg = 0;
int n;
int pkgLgth = 0;
int repeat;
/* initialize locale environment */
(void) textdomain(TEXT_DOMAIN);
/* initialize program name */
prog_full_name = argv[0];
(void) set_prog_name(argv[0]);
/* tell spmi zones interface how to access package output functions */
/* tell quit which ckreturn function to call */
/* Read PKG_INSTALL_ROOT from the environment, if it's there. */
exit(1);
}
if (z_running_in_global_zone() && !enable_local_fs()) {
}
/*
* ********************************************************************
* parse command line options
* ********************************************************************
*/
switch (c) {
/*
* Public interface: Allow admin to remove objects
* from a service area via a reference client.
* Remove the package files from the client's file
* system, absolutely. If a file is shared with other
* packages, the default behavior is to not remove
* the file from the client's file system.
*/
case 'A':
pkgrmremote++;
break;
/*
* Public interface: Use the installation
* administration file, admin, in place of the
* default admin file. pkgrm first looks in the
* current working directory for the administration
* file. If the specified administration file is not
* in the current working directory, pkgrm looks in
* administra- tion file.
*/
case 'a':
break;
/*
* Not a public interface: location where package executables
*/
case 'b':
if (!path_valid(optarg)) {
quit(1);
}
quit(1);
}
break;
/*
* Not a public interface: pass -F option to
* pkgremove which suppresses the removal of any
* files and any class action scripts, and suppresses
* the running of any class action scripts. The
* package files remain but the package looks like it
* is not installed. This is mainly for use by the
* upgrade process.
*/
case 'F':
nodelete++;
break;
/*
* Public interface: Instruct pkgrm not to use the
* client's mount points. This option assumes the
* mount points are correct on the server and it
* behaves consistently with Solaris 2.5 and earlier
* releases.
*/
case 'M':
no_map_client = 1;
break;
/*
* Public interface: package removal occurs in
* non-interactive mode. Suppress output of the list of
* removed files. The default mode is interactive.
*/
case 'n':
nointeract++;
(void) echoSetFlag(B_FALSE);
break;
/*
* Not a public interface: the -O option allows the behavior
* of the package tools to be modified. Recognized options:
* -> debug
* ---> enable debugging output
* -> nozones
* ---> act as though in global zone with no non-global zones
* -> enable-hollow-package-support
* --> Enable hollow package support. When specified, for any
* --> package that has SUNW_PKG_HOLLOW=true:
* --> Do not calculate and verify package size against target
* --> Do not run any package procedure or class action scripts
* --> Do not create or remove any target directories
* --> Do not perform any script locking
* --> Do not install or uninstall any components of any package
* --> Do not output any status or database update messages
* -> zonelist="<names...>"
* ---> add package to space-separated list of zones only
*/
case 'O':
if (strcmp(p, "nozones") == 0) {
continue;
}
if (strcmp(p,
"enable-hollow-package-support") == 0) {
continue;
}
if (strcmp(p, "debug") == 0) {
(void) echoDebugSetFlag(debugFlag);
/* debug info on arguments to pkgadd */
}
continue;
}
quit(1);
continue;
}
/* -O option not recognized - issue warning */
continue;
}
break;
/*
* Public interface: defines the full path name of a
* directory to use as the root_path. All files,
* including package system information files, are
* relocated to a directory tree starting in the
* specified root_path.
*/
case 'R':
if (!set_inst_root(optarg)) {
exit(1);
}
break;
/*
* Public interface: remove the specified package(s)
* from the directory spool. The default directory
*/
case 's':
break;
/*
* Public interface: Allow admin to establish the client
* filesystem using a vfstab-like file of stable format.
*/
case 'V':
no_map_client = 0;
break;
/*
* Public interface: trace all of the scripts that
* get executed by pkgrm, located in the
* debugging the procedural and non- procedural
* scripts.
*/
case 'v':
pkgverbose++;
break;
/*
* Public interface: remove packages based on the
* pkginfo file
*/
case 'Y':
exit(1);
} else if (is_not_valid_category(category,
get_prog_name())) {
exit(1);
} else if (is_not_valid_length(category)) {
exit(1);
}
break;
/*
* unrecognized option
*/
default:
usage();
/* NOTREACHED */
}
}
/*
* ********************************************************************
* validate command line options
* ********************************************************************
*/
/* set "debug echo" flag according to setting of "-O debug" option */
(void) echoDebugSetFlag(debugFlag);
/* output entry debugging information */
if (z_running_in_global_zone()) {
} else {
z_get_zonename());
}
/* -s cannot be used with several */
usage();
/* NOTREACHED */
}
if (pkgrmremote != 0) {
usage();
/* NOTREACHED */
}
if (pkgverbose != 0) {
usage();
/* NOTREACHED */
}
if (is_an_inst_root() != 0) {
usage();
/* NOTREACHED */
}
}
/* -V cannot be used with -A */
if (no_map_client && pkgrmremote) {
usage();
/* NOTREACHED */
}
/* -n used without pkg names or category */
usage();
/* NOTREACHED */
}
/* Error if specified zone list isn't valid on target */
usage();
/*
* hook SIGINT and SIGHUP interrupts into quit.c's trap handler
*/
/* connect quit.c:trap() to SIGINT */
/* connect quit.c:trap() to SIGHUP */
/* release hold on signals */
/* establish temporary directory to use */
}
/* initialize path parameters */
/*
* initialize installation admin parameters - if removing from a spool
* directory then the admin file is ignore.
*/
}
/*
* if running in the global zone, and non-global zones exist, then
* enable hollow package support so that any packages that are marked
* SUNW_PKG_HOLLOW=true will be correctly removed in non-global zones
* when removed directly in the global zone by the global zone admin.
*/
if (is_depend_pkginfo_DB()) {
} else if ((z_running_in_global_zone() == B_TRUE) &&
(z_non_global_zones_exist() == B_TRUE)) {
}
/*
* See if user wants this to be handled as an old style pkg.
* NOTE : the ``exception_pkg()'' stuff is to be used only
* through on495. This function comes out for on1095. See
* PSARC 1993-546. -- JST
*/
old_pkg = 1;
}
/*
* See if the user wants to process symlinks consistent with
* the old behavior.
*/
old_symlinks = 1;
}
quit(1);
/* NOTREACHED */
}
/*
* error if there are packages on the command line and a category
* was specified
*/
usage();
/* NOTREACHED */
}
/*
* ********************************************************************
* main package processing "loop"
* ********************************************************************
*/
for (;;) {
boolean_t b;
char **pkglist; /* points to array of pkgs */
/*
* mount the spool device if required
*/
quit(n);
/* NOTREACHED */
}
}
quit(1);
/* NOTREACHED */
}
/*
* packages to remove
*/
switch (n) {
case -1: /* no packages found */
quit(1);
/* NOTREACHED */
case 0: /* packages found */
break;
default: /* "quit" error */
quit(n);
/* NOTREACHED */
}
/*
* count the number of packages to remove
* NOTE: npkgs is a global variable that is referenced by quit.c
* when error messages are generated - it is referenced directly
* by the other functions called below...
*/
if (pkgLgth > longestPkg) {
}
npkgs++;
}
/* output number of packages to be removed */
/*
* package list generated - remove packages
*/
/*
* unmount the spool directory if necessary
*/
(void) chdir("/");
quit(99);
/* NOTREACHED */
}
}
/*
* continue with next sequence of packages if continue set
*/
if (b == B_TRUE) {
continue;
}
/*
* not continuing - quit with 0 exit code
*/
quit(0);
/* NOTREACHED */
#ifdef lint
return (0);
#endif /* lint */
}
}
/*
* *****************************************************************************
* static internal (private) functions
* *****************************************************************************
*/
/*
* Name: doRemove
* Description: Remove a package from the global zone, and optionally from one
* or more non-global zones.
* Arguments: a_nodelete: should the files and scripts remain installed?
* - if != 0 pass -F flag to pkgremove - suppress
* the removal of any files and any class action scripts
* and suppress the running of any class action scripts.
* The package files remain but the package looks like it
* is not installed. This is mainly for use by upgrade.
* - if == 0 do not pass -F flag to pkgremove - all
* files and class action scripts are removed, and any
* appropriate class action scripts are run.
* a_altBinDir - pointer to string representing location of the
* pkgremove executable to run. If not NULL, then pass
* the path specified to the -b option to pkgremove.
* a_longestPkg - length of the longest package "name" (for
* output format alignment)
* a_adminFile - pointer to string representing the admin
* file to pass to pkgremove when removing a package from
* the global zone only. Typically the admin file used for
* the global zone is the admin file passed in by the user.
* If this is == NULL no admin file is given to pkgremove.
* a_zoneAdminFile - pointer to string representing the admin
* file to pass to pkgremove when removing the package
* from a non-global zone only. Typically the admin file
* used for non-global zones supresses all checks since
* the dependency checking is done for all zones first
* before proceeding.
* A zoneAdminFile MUST be specified if a_zlst != NULL.
* A zoneAdminFile must NOT be specified if a_zlst == NULL.
* a_zlst - list of zones to process; NULL if no zones to process.
* Returns: int (see ckreturn() function for details)
* 0 - success
* 1 - package operation failed (fatal error)
* 2 - non-fatal error (warning)
* 3 - user selected quit (operation interrupted)
* 4 - admin settings prevented operation
* 5 - interaction required and -n (non-interactive) specified
* "10" will be added to indicate "immediate reboot required"
* "20" will be added to indicate "reboot after install required"
*/
static int
{
boolean_t b;
char *zoneName;
int n;
int zoneIndex;
int zonesSkipped;
/* entry assertions */
/* zone list specified - zone admin file required */
} else {
/* no zone list specified - no zone admin file needed */
}
/* NOTE: required 'pkgdir' set to spool directory or NULL */
if (b == B_FALSE) {
pkginfoFree(&pinfo);
return (2);
}
/* entry debugging info */
if (!nointeract) {
char fmt1[100];
/* create format based on max pkg name length */
} else {
if (getuid()) {
exit(1);
}
}
char fmt2[100];
/* create format based on max pkg name length */
/* LINTED variable format specifier to fprintf() */
}
}
}
if (n != 0) {
quit(n);
/* NOTREACHED */
}
pkginfoFree(&pinfo);
return (0);
}
}
/* removal from a directory */
pkginfoFree(&pinfo);
}
/* exit if not root */
if (getuid()) {
exit(1);
}
pkginfoFree(&pinfo);
zonesSkipped = 0;
if (interrupted != 0) {
return (n);
}
for (zoneIndex = 0;
zoneIndex++) {
/* skip the zone if it is NOT running */
zonesSkipped++;
continue;
}
/*
* remove package from zone; use the zone admin file which
* suppresses all checks.
*/
ckreturn(n);
}
if (zonesSkipped > 0) {
for (zoneIndex = 0;
/* skip the zone if it IS running */
if (zst == ZONE_STATE_RUNNING ||
zst == ZONE_STATE_MOUNTED) {
zonesSkipped++;
continue;
}
/* skip the zone if it is NOT bootable */
zoneName);
continue;
}
/* mount up the zone */
if (b == B_FALSE) {
/* set fatal error return condition */
ckreturn(1);
continue;
}
/*
* remove package from zone; use the zone admin file
* which suppresses all checks.
*/
ckreturn(n);
/* restore original state of zone */
}
}
/*
* Process global zone if it was either the only possible
* target (no list of zones specified) or it appears in the list
*/
/* reset interrupted flag before calling pkgremove */
interrupted = 0; /* last action was NOT quit */
/*
* call pkgremove for this package for the global zone;
* use the admin file passed in by the user via -a.
*/
ckreturn(n);
}
return (n);
}
/*
* function to clear out any exisiting error return conditions that may have
* been set by previous calls to ckreturn()
*/
static void
{
admnflag = 0; /* != 0 if any pkg op admin setting failure (4) */
doreboot = 0; /* != 0 if reboot required after installation (>= 10) */
failflag = 0; /* != 0 if fatal error has occurred (1) */
intrflag = 0; /* != 0 if user selected quit (3) */
ireboot = 0; /* != 0 if immediate reboot required (>= 20) */
nullflag = 0; /* != 0 if admin interaction required (5) */
warnflag = 0; /* != 0 if non-fatal error has occurred (2) */
interrupted = 0; /* last pkg op was quit (1,2,3,4,5) */
}
/*
* function which checks the indicated return value
* and indicates disposition of installation
*/
static void
{
/*
* entry debugging info
*/
switch (retcode) {
case 0: /* successful */
case 10:
case 20:
break; /* empty case */
case 1: /* package operation failed (fatal error) */
case 11:
case 21:
failflag++;
interrupted++;
break;
case 2: /* non-fatal error (warning) */
case 12:
case 22:
warnflag++;
interrupted++;
break;
case 3: /* user selected quit; operation interrupted */
case 13:
case 23:
intrflag++;
interrupted++;
break;
case 4: /* admin settings prevented operation */
case 14:
case 24:
admnflag++;
interrupted++;
break;
case 5: /* administration: interaction req (no -n) */
case 15:
case 25:
nullflag++;
interrupted++;
break;
default:
failflag++;
interrupted++;
return;
}
if (retcode >= 20) {
ireboot++;
} else if (retcode >= 10) {
doreboot++;
}
}
static int
{
char *p;
char adminfd_path[PATH_MAX];
int maxfds;
int n;
int nargs;
/* entry assertions */
/* entry debugging info */
/* generate path to pkgremove */
/* start at first file descriptor */
maxfds = 0;
/*
* generate argument list for call to pkgremove
*/
/* start at argument 0 */
nargs = 0;
/* first argument is path to executable */
/* second argument is always: pass -O debug to pkgremove: debug mode */
}
/* pkgrm -b dir: pass -b to pkgremove */
if (a_altBinDir != (char *)NULL) {
}
/*
* NONABI_SCRIPTS defined: pass -o to pkgremove; refers to a
* pkg requiring operator interaction during a procedure script
* (common before on1093)
*/
if (old_pkg) {
}
/*
* PKG_NONABI_SYMLINKS defined: pass -y to pkgremove; process
* symlinks consistent with old behavior
*/
if (old_symlinks) {
}
/* pkgrm -M: pass -M to pkgremove: don't mount client file systems */
/* pkgrm -A: pass -A to pkgremove */
if (pkgrmremote) {
}
/* pkgrm -v: pass -v to pkgremove: never trace scripts */
/* pass "-O enable-hollow-package-support" */
if (is_depend_pkginfo_DB()) {
}
/* pass -n to pkgremove: always in noninteractive mode */
/* pkgrm -a admin: pass -a admin to pkgremove: admin file */
if (a_adminFile) {
int fd;
if (fd < 0) {
return (1);
}
}
/*
* pkgadd -R root: pass -R /a to pkgremove in mounted zone
*/
if (a_zoneState == ZONE_STATE_MOUNTED) {
}
/* pkgrm -F: pass -F to pkgremove: always update DB only */
/* pass "-O preremovecheck" */
/* add "-O addzonename" */
/*
*/
p = z_get_zonename();
if ((p != NULL) && (*p != '\0')) {
char zn[MAXPATHLEN];
"parent-zone-name=%s", p);
}
/* current zone type */
if (z_running_in_global_zone() == B_TRUE) {
char zn[MAXPATHLEN];
"parent-zone-type=%s",
} else {
char zn[MAXPATHLEN];
"parent-zone-type=%s",
}
/* Add arguments how to start the pkgserv */
/* pass -N to pkgremove: program name to report */
/* add package instance name */
/* terminate argument list */
/* execute pkgremove command */
for (n = 0; arg[n]; n++) {
}
}
/* terminate file descriptor list */
/* exec command in zone */
PSTR(a_stdoutPath));
/*
* close any files that were opened for use by the
* via the z_zone_exec() interface
*/
}
/* return results of pkgremove in zone execution */
return (n);
}
static int
{
char *p;
char adminfd_path[PATH_MAX];
int maxfds;
int n;
int nargs;
/* entry assertions */
/* entry debugging info */
/* generate path to pkgremove */
/* start at first file descriptor */
maxfds = 0;
/*
* generate argument list for call to pkgremove
*/
/* start at argument 0 */
nargs = 0;
/* first argument is path to executable */
/* second argument is always: pass -O debug to pkgremove: debug mode */
}
/* pkgrm -b dir: pass -b to pkgremove */
if (a_altBinDir != (char *)NULL) {
}
/*
* NONABI_SCRIPTS defined: pass -o to pkgremove; refers to a
* pkg requiring operator interaction during a procedure script
* (common before on1093)
*/
if (old_pkg) {
}
/*
* PKG_NONABI_SYMLINKS defined: pass -y to pkgremove; process
* symlinks consistent with old behavior
*/
if (old_symlinks) {
}
/* pkgrm -M: pass -M to pkgremove: don't mount client file systems */
/* pkgrm -A: pass -A to pkgremove */
if (pkgrmremote) {
}
/* pkgrm -v: pass -v to pkgremove: trace scripts */
if (pkgverbose) {
}
/* pass "-O enable-hollow-package-support" */
if (is_depend_pkginfo_DB()) {
}
/* pkgrm -n: pass -n to pkgremove: noninteractive mode */
if (nointeract) {
}
/* pkgrm -a admin: pass -a admin to pkgremove: admin file */
if (a_adminFile) {
int fd;
if (fd < 0) {
return (1);
}
}
/*
* pkgadd -R root: pass -R /a to pkgremove in mounted zone
*/
if (a_zoneState == ZONE_STATE_MOUNTED) {
}
/* pkgrm -F: pass -F to pkgremove: update DB only */
if (a_nodelete) {
}
/* add "-O addzonename" */
/*
*/
p = z_get_zonename();
if ((p != NULL) && (*p != '\0')) {
char zn[MAXPATHLEN];
"parent-zone-name=%s", p);
}
/* current zone type */
if (z_running_in_global_zone() == B_TRUE) {
char zn[MAXPATHLEN];
"parent-zone-type=%s",
} else {
char zn[MAXPATHLEN];
"parent-zone-type=%s",
}
/* Add arguments how to start the pkgserv */
/* pass -N to pkgremove: program name to report */
/* add package instance name */
/* terminate argument list */
/* execute pkgremove command */
for (n = 0; arg[n]; n++) {
}
}
/* terminate file descriptor list */
/* exec command in zone */
/*
* close any files that were opened for use by the
* via the z_zone_exec() interface
*/
}
return (n);
}
/*
* Name: pkgRemove
* Description: Invoke pkgremove in the current zone to perform a remove
* of a single package from the current zone or standalone system
* Arguments: a_nodelete: should the files and scripts remain installed?
* - if != 0 pass -F flag to pkgremove - suppress
* the removal of any files and any class action scripts
* and suppress the running of any class action scripts.
* The package files remain but the package looks like it
* is not installed. This is mainly for use by upgrade.
* - if == 0 do not pass -F flag to pkgremove - all
* files and class action scripts are removed, and any
* appropriate class action scripts are run.
* a_altBinDir - pointer to string representing location of the
* pkgremove executable to run. If not NULL, then pass
* the path specified to the -b option to pkgremove.
* a_adminFile - pointer to string representing the admin
* file to pass to pkgremove when removing the package.
* If this is == NULL no admin file is given to pkgremove.
* Returns: int (see ckreturn() function for details)
* 0 - success
* 1 - package operation failed (fatal error)
* 2 - non-fatal error (warning)
* 3 - user selected quit (operation interrupted)
* 4 - admin settings prevented operation
* 5 - interaction required and -n (non-interactive) specified
* "10" will be added to indicate "immediate reboot required"
* "20" will be added to indicate "reboot after install required"
*/
static int
{
char *p;
int n;
int nargs;
/* entry debugging info */
nargs = 0;
/* first argument is path to executable */
/* second argument is always: pass -O debug to pkgremove: debug mode */
}
/* Add arguments how to start the pkgserv */
/* pkgrm -b dir: pass -b to pkgremove */
if (a_altBinDir != (char *)NULL) {
}
/*
* NONABI_SCRIPTS defined: pass -o to pkgremove; refers to a
* pkg requiring operator interaction during a procedure script
* (common before on1093)
*/
if (old_pkg) {
}
/*
* PKG_NONABI_SYMLINKS defined: pass -y to pkgremove; process
* symlinks consistent with old behavior
*/
if (old_symlinks) {
}
/* pkgrm -M: pass -M to pkgrm: dont mount client file systems */
if (no_map_client) {
}
/* pkgrm -A: pass -A to pkgrm */
if (pkgrmremote) {
}
/* pkgrm -v: pass -v to pkgremove: trace scripts */
if (pkgverbose) {
}
/* pkgrm -n: pass -n to pkgremove: noninteractive mode */
if (nointeract) {
}
/* pkgrm -a admin: pass -a admin to pkgremove: admin file */
if (a_adminFile) {
}
/* pkgrm -V vfstab: pass -V vfstab to pkgremove: alternate vfstab */
if (vfstab_file) {
}
/* pkgrm -R root: pass -R root to pkgremove: alternative root */
if (is_an_inst_root()) {
}
/* pkgrm -F: pass -F to pkgremove: update DB only */
if (a_nodelete) {
}
/*
*/
p = z_get_zonename();
if ((p != NULL) && (*p != '\0')) {
char zn[MAXPATHLEN];
"parent-zone-name=%s", p);
}
/* current zone type */
if (z_running_in_global_zone() == B_TRUE) {
char zn[MAXPATHLEN];
"parent-zone-type=%s",
} else {
char zn[MAXPATHLEN];
"parent-zone-type=%s",
}
/* pass -N to pkgremove: program name to report */
/* add package instance name */
/* terminate argument list */
/*
* run the appropriate pkgremove command in the specified zone
*/
for (n = 0; arg[n]; n++) {
}
}
/* execute pkgremove command */
/* return results of pkgrm in this zone */
return (n);
}
static void
usage(void)
{
char *prog = get_prog_name();
exit(1);
}
/*
* Name: remove_packages_in_global_with_zones
* Description: Remove packages from the global zone and from non-global zones
* when run from the global zone and when non-global zones are
* present.
* Arguments: a_pkgList - pointer to array of strings, each string specifying
* the name of one package to be removed.
* a_nodelete: should the files and scripts remain installed?
* - if != 0 pass -F flag to pkgremove - suppress
* the removal of any files and any class action scripts
* and suppress the running of any class action scripts.
* The package files remain but the package looks like it
* is not installed. This is mainly for use by upgrade.
* - if == 0 do not pass -F flag to pkgremove - all
* files and class action scripts are removed, and any
* appropriate class action scripts are run.
* a_longestPkg - length of the longest package "name" (for
* output format alignment)
* a_repeat - are there more packages avialable in "optind"
* - B_TRUE - process packages from optind
* - B_FALSE - do not process packages from optind
* a_altBinDir - pointer to string representing location of the
* pkgremove executable to run. If not NULL, then pass
* the path specified to the -b option to pkgremove.
* a_pkgdir - pointer to string representing the directory
* where the packages to be removed are located.
* a_zlst - list of zones to process; NULL if no zones to process.
* Returns: int (see ckreturn() function for details)
* 0 - success
* 1 - package operation failed (fatal error)
* 2 - non-fatal error (warning)
* 3 - user selected quit (operation interrupted)
* 4 - admin settings prevented operation
* 5 - interaction required and -n (non-interactive) specified
* "10" will be added to indicate "immediate reboot required"
* "20" will be added to indicate "reboot after install required"
*/
static boolean_t
{
static char *zoneAdminFile = (char *)NULL;
boolean_t b;
char *zoneName;
char *scratchName;
int i;
int n;
int zoneIndex;
int zonesSkipped;
/* entry assertions */
assert(a_longestPkg > 0);
/* entry debugging info */
/* check all packages */
quit(1);
}
/* create temporary directory for use by zone operations */
/* create hands off settings admin file for use in a non-global zone */
/*
* all of the packages (as listed in the package list) are
* removed one at a time from all non-global zones and then
* from the global zone.
*/
/* reset interrupted flag before calling pkgremove */
interrupted = 0; /* last action was NOT quit */
/* skip package if it is "in the global zone only" */
continue;
}
/*
* if operation failed in global zone do not propagate to
* non-global zones
*/
zonesSkipped = 0;
if (interrupted != 0) {
break;
}
for (zoneIndex = 0;
/* skip the zone if it is NOT running */
if (zst != ZONE_STATE_RUNNING &&
zst != ZONE_STATE_MOUNTED) {
zonesSkipped++;
continue;
}
zoneName);
(void) snprintf(preremovecheckPath,
sizeof (preremovecheckPath),
"%s/%s.%s.preremovecheck.txt",
/*
* dependency check this package this zone; use the
* user supplied admin file so that the appropriate
* level of dependency checking is (or is not) done.
*/
ckreturn(n);
"after pkgzonecheckremove",
}
if (zonesSkipped == 0) {
continue;
}
for (zoneIndex = 0;
/* skip the zone if it IS running */
if (zst == ZONE_STATE_RUNNING ||
zst == ZONE_STATE_MOUNTED) {
zonesSkipped++;
continue;
}
/* skip the zone if it is NOT bootable */
zoneName);
continue;
}
/* mount up the zone */
if (b == B_FALSE) {
/* set fatal error return condition */
ckreturn(1);
continue;
}
zoneName);
(void) snprintf(preremovecheckPath,
sizeof (preremovecheckPath),
"%s/%s.%s.preremovecheck.txt",
/*
* dependency check this package this zone; use the
* user supplied admin file so that the appropriate
* level of dependency checking is (or is not) done.
*/
ckreturn(n);
"after pkgzonecheckremove",
/* restore original state of zone */
}
npkgs--;
}
/*
* look at all pre-remove check files
*/
if (i != 0) {
quit(i);
}
/*
* reset all error return condition variables that may have been
* set during package removal dependency checking so that they
* removal operations
*/
resetreturn();
/*
* all of the packages (as listed in the package list) are
* removed one at a time.
*/
interrupted = 0;
started = 0;
continue;
}
/* reset interrupted flag before calling pkgremove */
interrupted = 0;
/*
* pkgrm invoked from within the global zone and there are
* non-global zones configured:
* Remove the package from the global zone.
* If not removing the package from the global zone only,
* then remove the package from the list of zones specified.
*/
if (in_gz_only) {
/* global zone only */
} else {
/* global zone and non-global zones */
}
ckreturn(n);
npkgs--;
}
/*
* all packages in the package list have been removed.
* Continue with removal if:
* -- immediate reboot is NOT required
* -- there are more packages to remove
* else return do NOT continue.
*/
return (B_TRUE);
}
/* return 'dont continue' */
return (B_FALSE);
}
/*
* Name: remove_packages_in_nonglobal_zone
* Description: Remove packages in a non-global zone when run from a
* non-global zone.
* Arguments: a_pkgList - pointer to array of strings, each string specifying
* the name of one package to be removed.
* a_nodelete: should the files and scripts remain installed?
* - if != 0 pass -F flag to pkgremove - suppress
* the removal of any files and any class action scripts
* and suppress the running of any class action scripts.
* The package files remain but the package looks like it
* is not installed. This is mainly for use by upgrade.
* - if == 0 do not pass -F flag to pkgremove - all
* files and class action scripts are removed, and any
* appropriate class action scripts are run.
* a_longestPkg - length of the longest package "name" (for
* output format alignment)
* a_repeat - are there more packages avialable in "optind"
* - B_TRUE - process packages from optind
* - B_FALSE - do not process packages from optind
* a_altBinDir - pointer to string representing location of the
* pkgremove executable to run. If not NULL, then pass
* the path specified to the -b option to pkgremove.
* a_pkgdir - pointer to string representing the directory
* where the packages to be removed are located.
* Returns: int (see ckreturn() function for details)
* 0 - success
* 1 - package operation failed (fatal error)
* 2 - non-fatal error (warning)
* 3 - user selected quit (operation interrupted)
* 4 - admin settings prevented operation
* 5 - interaction required and -n (non-interactive) specified
* "10" will be added to indicate "immediate reboot required"
* "20" will be added to indicate "reboot after install required"
*/
static boolean_t
{
static char *zoneAdminFile = (char *)NULL;
int n;
int i;
/* entry assertions */
assert(a_longestPkg > 0);
/* entry debugging info */
/* check all package */
quit(1);
}
/* create temporary directory for use by zone operations */
/* create hands off settings admin file for use in a non-global zone */
/*
* all of the packages (as listed in the package list) are
* removed one at a time.
*/
interrupted = 0;
started = 0;
continue;
}
interrupted = 0;
/*
* pkgrm invoked from within a non-global zone: remove
* the package from the current zone only - no non-global
* zones are possible.
*/
ckreturn(n);
npkgs--;
}
/*
* all packages in the package list have been removed.
* Continue with removal if:
* -- immediate reboot is NOT required
* -- there are more packages to remove
* else return do NOT continue.
*/
return (B_TRUE);
}
/* return 'dont continue' */
return (B_FALSE);
}
/*
* Name: remove_packages_in_global_no_zones
* Description: Remove packages from the global zone only when run in the
* global zone and no non-global zones are installed.
* Arguments: a_pkgList - pointer to array of strings, each string specifying
* the name of one package to be removed.
* a_nodelete: should the files and scripts remain installed?
* - if != 0 pass -F flag to pkgremove - suppress
* the removal of any files and any class action scripts
* and suppress the running of any class action scripts.
* The package files remain but the package looks like it
* is not installed. This is mainly for use by upgrade.
* - if == 0 do not pass -F flag to pkgremove - all
* files and class action scripts are removed, and any
* appropriate class action scripts are run.
* a_longestPkg - length of the longest package "name" (for
* output format alignment)
* a_repeat - are there more packages avialable in "optind"
* - B_TRUE - process packages from optind
* - B_FALSE - do not process packages from optind
* a_altBinDir - pointer to string representing location of the
* pkgremove executable to run. If not NULL, then pass
* the path specified to the -b option to pkgremove.
* Returns: int (see ckreturn() function for details)
* 0 - success
* 1 - package operation failed (fatal error)
* 2 - non-fatal error (warning)
* 3 - user selected quit (operation interrupted)
* 4 - admin settings prevented operation
* 5 - interaction required and -n (non-interactive) specified
* "10" will be added to indicate "immediate reboot required"
* "20" will be added to indicate "reboot after install required"
*/
static boolean_t
{
int n;
int i;
/* entry assertions */
assert(a_longestPkg > 0);
/* entry debugging info */
/*
* all of the packages (as listed in the package list) are
* removed one at a time.
*/
interrupted = 0;
started = 0;
continue;
}
interrupted = 0;
/*
* pkgrm invoked from within the global zone and there are
* NO non-global zones configured:
* Remove the package from the global zone only.
*/
ckreturn(n);
npkgs--;
}
/*
* all packages in the package list have been removed.
* Continue with removal if:
* -- immediate reboot is NOT required
* -- there are more packages to remove
* else return do NOT continue.
*/
return (B_TRUE);
}
/* return 'dont continue' */
return (B_FALSE);
}
/*
* Name: remove_packages_from_spool_directory
* Description: Remove packages from a spool directory only.
* Arguments: a_pkgList - pointer to array of strings, each string specifying
* the name of one package to be removed.
* a_nodelete: should the files and scripts remain installed?
* - if != 0 pass -F flag to pkgremove - suppress
* the removal of any files and any class action scripts
* and suppress the running of any class action scripts.
* The package files remain but the package looks like it
* is not installed. This is mainly for use by upgrade.
* - if == 0 do not pass -F flag to pkgremove - all
* files and class action scripts are removed, and any
* appropriate class action scripts are run.
* a_longestPkg - length of the longest package "name" (for
* output format alignment)
* a_repeat - are there more packages avialable in "optind"
* - B_TRUE - process packages from optind
* - B_FALSE - do not process packages from optind
* a_altBinDir - pointer to string representing location of the
* pkgremove executable to run. If not NULL, then pass
* the path specified to the -b option to pkgremove.
* Returns: int (see ckreturn() function for details)
* 0 - success
* 1 - package operation failed (fatal error)
* 2 - non-fatal error (warning)
* 3 - user selected quit (operation interrupted)
* 4 - admin settings prevented operation
* 5 - interaction required and -n (non-interactive) specified
* "10" will be added to indicate "immediate reboot required"
* "20" will be added to indicate "reboot after install required"
*/
static boolean_t
{
int n;
int i;
/* entry assertions */
assert(a_longestPkg > 0);
/*
* all of the packages (as listed in the package list) are
* removed one at a time.
*/
interrupted = 0;
started = 0;
continue;
}
interrupted = 0;
/*
* pkgrm invoked from any type of zone BUT the target
* to be removed is a local spool directory: remove the
* packages from the spool directory only.
*/
ckreturn(n);
npkgs--;
}
/*
* all packages in the package list have been removed.
* Continue with removal if:
* -- immediate reboot is NOT required
* -- there are more packages to remove
* else return do NOT continue.
*/
return (B_TRUE);
}
/* return 'dont continue' */
return (B_FALSE);
}
/*
* Name: remove_packages
* Description: Remove packages from the global zone, and optionally from one
* or more non-global zones, or from a specified spool directory.
* Arguments: a_pkgList - pointer to array of strings, each string specifying
* the name of one package to be removed.
* a_nodelete: should the files and scripts remain installed?
* - if != 0 pass -F flag to pkgremove - suppress
* the removal of any files and any class action scripts
* and suppress the running of any class action scripts.
* The package files remain but the package looks like it
* is not installed. This is mainly for use by upgrade.
* - if == 0 do not pass -F flag to pkgremove - all
* files and class action scripts are removed, and any
* appropriate class action scripts are run.
* a_longestPkg - length of the longest package "name" (for
* output format alignment)
* a_repeat - are there more packages avialable in "optind"
* - B_TRUE - process packages from optind
* - B_FALSE - do not process packages from optind
* a_altBinDir - pointer to string representing location of the
* pkgremove executable to run. If not NULL, then pass
* the path specified to the -b option to pkgremove.
* a_pkgdir - pointer to string representing the directory
* where the packages to be removed are located.
* a_spoolDir - pointer to string specifying spool directory
* to remove packages from. If != NULL then all zones
* processing is bypassed and the packages are removed
* from the specified spool directory only.
* a_noZones - if non-global zones are configured, should the
* packages be removed from the non-global zones?
* - B_TRUE - do NOT remove packages from non-global zones
* - B_FALSE - remove packages from non-global zones
* Returns: int (see ckreturn() function for details)
* 0 - success
* 1 - package operation failed (fatal error)
* 2 - non-fatal error (warning)
* 3 - user selected quit (operation interrupted)
* 4 - admin settings prevented operation
* 5 - interaction required and -n (non-interactive) specified
* "10" will be added to indicate "immediate reboot required"
* "20" will be added to indicate "reboot after install required"
*/
static boolean_t
{
boolean_t b;
/* entry assertions */
/*
* if removing from spool directory, bypass all zones checks
*/
if (a_spoolDir != (char *)NULL) {
/* in non-global zone */
return (B_FALSE);
}
/* exit if not root */
if (getuid()) {
exit(1);
}
/*
* if running in the global zone AND one or more non-global
* zones exist, add packages in a 'zones aware' manner, else
* add packages in the standard 'non-zones aware' manner.
*/
/* in non-global zone */
if (b != B_TRUE) {
/* set fatal error return condition */
ckreturn(1);
return (B_FALSE);
}
(void) z_unlock_this_zone(ZLOCKS_ALL);
return (B_FALSE);
}
/* running in the global zone */
b = z_non_global_zones_exist();
/* get a list of all non-global zones */
quit(1);
}
/* need to lock all of the zones */
if (b == B_FALSE) {
/* set fatal error return condition */
ckreturn(1);
return (B_FALSE);
}
/* add packages to all zones */
/* unlock all zones */
/* free list of all non-global zones */
return (B_FALSE);
}
/* in global zone no non-global zones */
if (b != B_TRUE) {
/* set fatal error return condition */
ckreturn(1);
return (B_FALSE);
}
(void) z_unlock_this_zone(ZLOCKS_ALL);
return (B_FALSE);
}
/*
* Name: path_valid
* Description: Checks a string for being a valid path
*
* Arguments: path - path to validate
*
* Returns : B_TRUE - success, B_FALSE otherwise.
* B_FALSE means path was null, too long (>PATH_MAX),
* or too short (<1)
*/
static boolean_t
path_valid(char *path)
{
return (B_FALSE);
return (B_FALSE);
return (B_TRUE);
} else {
/* path < 1 */
return (B_FALSE);
}
}
/*
*/
static boolean_t
{
int i;
/* set flags for applicability check */
if (z_running_in_global_zone() == B_TRUE) {
}
/*
* for each package to remove, verify that the package is installed
* and is removable.
*/
/* check package applicability */
return (B_FALSE);
}
npkgs--;
}
return (B_TRUE);
}
/*
* - is this package removable from this zone?
* - does the scope of remove conflict with existing installation
*/
static boolean_t
{
char pkginfoPath[PATH_MAX];
int len;
/* entry assertions */
/* normalize root path */
if (a_rootPath == (char *)NULL) {
a_rootPath = "";
}
/*
* determine if this package is currently installed
* if not installed return success - operation will fail
* when the removal is attempted
*/
B_TRUE) {
return (B_TRUE);
}
/*
* calculate paths to various objects
*/
return (B_FALSE);
}
/* if not installed then just return */
return (B_TRUE);
}
return (B_FALSE);
}
/*
* gather information from this packages pkginfo file
*/
return (B_FALSE);
}
/* determine "ALLZONES" setting for this package */
"true", B_FALSE);
/* close pkginfo file */
/* gather information from the global zone only file */
/*
* verify package applicability based on information gathered;
* the package IS currently installed....
*/
/* pkg ALLZONES=true & not running in global zone */
return (B_FALSE);
}
return (B_TRUE);
}
/*
* Name: shall_we_continue
* Description: Called from within a loop that is installing packages,
* this function examines various global variables and decides
* whether or not to ask an appropriate question, and wait for
* and appropriate reply.
* Arguments: <<global variables>>
* Returns: B_TRUE - continue processing with next package
* B_FALSE - do not continue processing with next package
*/
static boolean_t
{
int n;
/* return FALSE if immediate reboot required */
if (ireboot) {
return (B_FALSE);
}
/* return TRUE if not interrupted */
if (!interrupted) {
return (B_TRUE);
}
/* output appropriate interrupt message */
/* if running with no interaction (-n) do not ask question */
if (nointeract) {
quit(0);
/* NOTREACHED */
}
/* interaction possible: ask question */
if (n != 0) {
quit(n);
/* NOTREACHED */
}
quit(0);
/* NOTREACHED */
}
return (B_TRUE);
}
/*
* Name: create_zone_adminfile
* Description: Given a zone temporary directory and optionally an existing
* administration file, generate an administration file that
* can be used to perform "non-interactive" operations in a
* non-global zone.
* Arguments: r_zoneAdminFile - pointer to handle that will contain a
* string representing the path to the temporary
* administration file created - this must be NULL
* before the first call to this function - on
* subsequent calls if the pointer is NOT null then
* the existing string will NOT be overwritten.
* a_zoneTempDir - pointer to string representing the path
* to the zone temporary directory to create the
* temporary administration file in
* a_admnfile - pointer to string representing the path to
* an existing "user" administration file - the
* administration file created will contain the
* settings contained in this file, modified as
* appropriate to supress any interaction;
* If this is == NULL then the administration file
* created will not contain any extra settings
* Returns: void
* NOTE: Any string returned is placed in new storage for the
* calling method. The caller must use 'free' to dispose
* of the storage once the string is no longer needed.
* NOTE: On any error this function will call 'quit(1)'
*/
static void
char *a_admnfile)
{
boolean_t b;
/* entry assertions */
/* entry debugging info */
/* if temporary name already exists, do not overwrite */
if (*r_zoneAdminFile != (char *)NULL) {
return;
}
/* create temporary name */
if (b == B_FALSE) {
quit(1);
/* NOTREACHED */
}
}
/*
* Name: create_zone_tempdir
* Description: Given a system temporary directory, create a "zone" specific
* temporary directory and return the path to the directory
* created.
* Arguments: r_zoneTempDir - pointer to handle that will contain a
* string representing the path to the temporary
* directory created - this must be NULL before the
* first call to this function - on subsequent calls
* if the pointer is NOT null then the existing string
* will NOT be overwritten.
* a_zoneTempDir - pointer to string representing the path
* to the system temporary directory to create the
* temporary zone directory in
* Returns: void
* NOTE: Any string returned is placed in new storage for the
* calling method. The caller must use 'free' to dispose
* of the storage once the string is no longer needed.
* NOTE: On any error this function will call 'quit(1)'
* NOTE: This function calls "quitSetZoneTmpdir" on success to
* register the directory created with quit() so that the
* directory will be automatically deleted on exit.
*/
static void
{
boolean_t b;
/* entry assertions */
/* entry debugging info */
/* if temporary directory already exists, do not overwrite */
if (*r_zoneTempDir != (char *)NULL) {
return;
}
/* create temporary directory */
if (b == B_FALSE) {
quit(1);
/* NOTREACHED */
}
/* register with quit() to directory is removed on exit */
/* exit debugging info */
}