5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER START
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The contents of this file are subject to the terms of the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Common Development and Distribution License (the "License").
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You may not use this file except in compliance with the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * or http://www.opensolaris.org/os/licensing.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * See the License for the specific language governing permissions
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * and limitations under the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * When distributing Covered Code, include this CDDL HEADER in each
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If applicable, add the following below this CDDL HEADER, with the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER END
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Use is subject to license terms.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* All Rights Reserved */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandextern int pkginfofind(char *path, char *pkg_dir, char *pkginst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s [-q] [-pi] [-x|l] [options] [pkg ...]\n" \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "%s -d device [-q] [-x|l] [options] [pkg ...]\n" \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland " -q #quiet mode\n" \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland " -p #select partially installed packages\n" \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland " -i #select completely installed packages\n" \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland " -x #extracted listing\n" \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland " -l #long listing\n" \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland " -r #relocation base \n" \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "and options may include:\n" \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland " -c category, [category...]\n" \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland " -a architecture\n" \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland " -v version\n"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define ERR_INCOMP0 "-L and -l/-x/-r flags are incompatible"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define ERR_INCOMP1 "-l and -x/-r flags are not compatible"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define ERR_INCOMP2 "-x and -l/-r flags are not compatible"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define ERR_INCOMP3 "-r and -x/-x flags are not compatible"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define ERR_NOINFO "ERROR: information for \"%s\" was not found"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define ERR_NOPINFO "ERROR: No partial information for \"%s\" was found"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define ERR_BADINFO "pkginfo file is corrupt or missing"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define ERR_ROOT_SET "Could not set install root from the environment."
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define ERR_ROOT_CMD "Command line install root contends with environment."
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* Format for dumping package attributes in dumpinfo() */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define nblock(size) ((size + (DEV_BSIZE - 1)) / DEV_BSIZE)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "DESC", "PSTAMP", "INSTDATE", "VSTOCK", "SERIALNUM", "HOTLINE",
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int selectp(char *p);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void usage(void), look_for_installed(void),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void pkgusage(struct cfstat *dp, struct cfent *pentry);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic void dumpinfo(struct cfstat *dp, int pkgLngth);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* initialize locale mechanism */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* determine program name */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* tell spmi zones interface how to access package output functions */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland z_set_output_functions(echo, echoDebug, progerr);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* establish installation root directory */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!set_inst_root(getenv("PKG_INSTALL_ROOT"))) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((c = getopt(argc, argv, "LNR:xv:a:d:qrpilc:?")) != EOF) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* -d could specify stream or mountable device */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* bug # 1081606 */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland ckcatg[ncatg++] = strtok(optarg, " \t\n, ");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while (ckcatg[ncatg] = strtok(NULL, " \t\n, "))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* added for newroot functions */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * implement the newroot option
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland set_PKGpaths(get_inst_root()); /* set up /var... directories */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Open the install DB, if one exists.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (pkg[0] && strcmp(pkg[0], "all") == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland pkgdir = get_PKGLOC(); /* we need this later */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* convert device appropriately */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If we are to inspect a spooled package we are only interested in
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik * the pkginfo file in the spooled pkg. We have a spooled pkg if
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * device is not NULL.
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik if (lflag && strcmp(pkgdir, get_PKGLOC()) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* look at contents file */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If we are to inspect a spooled package we are only interested in
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the pkginfo file in the spooled pkg so we skip any Reg 4 DB
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * lookups and use the old algorithm. We have a spooled pkg if
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * device is not NULL.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* get information about this package */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland continue; /* already used */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else if (!choice ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (strcmp(choice->pkginst, dp->pkginst) > 0))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break; /* no more packages */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (pkginfo(&info, choice->pkginst, ckarch, ckvers)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Confirm that the pkginfo file contains the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * required information.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (info.name == NULL || *(info.name) == NULL ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland info.arch == NULL || *(info.arch) == NULL ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland info.version == NULL || *(info.version) == NULL ||
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland info.catg == NULL || *(info.catg) == NULL) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* is it in an appropriate catgory? */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* don't include partially installed packages */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (choice->partial || (info.status == PI_PARTIAL) ||
9ab815e1e50104cb1004a5ccca7a6da582994b57Garrett D'Amore if (!iflag && (info.status == PI_INSTALLED)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* don't include completely installed packages */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* If no package matched and no output produced set error flag */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* verify that each package listed on command line was output */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; i < pkgcnt; ++i) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) pkginfo(&info, NULL); /* free up all memory and open fds */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland register int i;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return; /* print nothing */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) puts((info.basedir) ? info.basedir : "none");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) printf(XFMT, pkgLngth, pkgLngth, info.pkginst,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) printf(CFMT, pkgLngth, pkgLngth, "");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else if (!lflag) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) sscanf(info.catg, "%[^, \t\n]", category);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) printf(SFMT, category, pkgLngth, pkgLngth, info.pkginst,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) printf(FMT, "PKGINST", info.pkginst);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) printf(FMT, "VERSION", info.version);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (void) printf(FMT, "BASEDIR", info.basedir);
9ab815e1e50104cb1004a5ccca7a6da582994b57Garrett D'Amore for (i = 0; parmlst[i]; ++i) {
9ab815e1e50104cb1004a5ccca7a6da582994b57Garrett D'Amore if ((pt = pkgparam(info.pkginst, parmlst[i])) != NULL && *pt)
9ab815e1e50104cb1004a5ccca7a6da582994b57Garrett D'Amore (void) printf(FMT, "STATUS", gettext("spooled"));
9ab815e1e50104cb1004a5ccca7a6da582994b57Garrett D'Amore (void) printf(FMT, "STATUS", gettext("(unknown)"));
9ab815e1e50104cb1004a5ccca7a6da582994b57Garrett D'Amore (void) printf(gettext("%10s: %7ld spooled pathnames\n"),
9ab815e1e50104cb1004a5ccca7a6da582994b57Garrett D'Amore (void) printf(gettext("%10s: %7ld installed pathnames\n"),
9ab815e1e50104cb1004a5ccca7a6da582994b57Garrett D'Amore (void) printf(gettext("%20d partially installed pathnames\n"),
9ab815e1e50104cb1004a5ccca7a6da582994b57Garrett D'Amore (void) printf(gettext("%20d shared pathnames\n"), dp->shared);
9ab815e1e50104cb1004a5ccca7a6da582994b57Garrett D'Amore (void) printf(gettext("%20d linked files\n"), dp->link);
9ab815e1e50104cb1004a5ccca7a6da582994b57Garrett D'Amore (void) printf(gettext("%20d directories\n"), dp->dirs);
9ab815e1e50104cb1004a5ccca7a6da582994b57Garrett D'Amore (void) printf(gettext("%20d executables\n"), dp->exec);
9ab815e1e50104cb1004a5ccca7a6da582994b57Garrett D'Amore (void) printf(gettext("%20d setuid/setgid executables\n"),
9ab815e1e50104cb1004a5ccca7a6da582994b57Garrett D'Amore (void) printf(gettext("%20d package information files\n"),
9ab815e1e50104cb1004a5ccca7a6da582994b57Garrett D'Amore (void) printf(gettext("%20ld blocks used (approx)\n"),
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic struct cfstat *
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland dp = (struct cfstat *)calloc(1, sizeof (struct cfstat));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland progerr(gettext("no memory, malloc() failed"));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland register int i;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (0); /* no specification implies all packages */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (1); /* no category specified in pkginfo is a bug */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* bug id 1081607 */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (!pkginfofind(path, pkgdir, drp->d_name))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland continue; /* doesn't appear to be a package */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland register int i;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; i < pkgcnt; ++i) {
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik pkgopenfilter(server, pkgcnt == 1 ? pkg[0] : NULL) != 0)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* check the contents file to look for referenced packages */
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik while ((n = srchcfile(&entry, "*", server)) > 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (pinfo = entry.pinfo; pinfo; pinfo = pinfo->next) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* see if entry is used by indicated packaged */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Only objects specifically tagged with '!' event
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * character are considered "partial", everything
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * else is considered "installed" (even server
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland progerr(gettext("bad entry read in contents file"));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (entry.path && *entry.path) ? entry.path : "Unknown");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (vfpOpen(&vfp, pkgmap, "r", VFP_NEEDNOW) != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland progerr(gettext("unable open \"%s\" for reading"), pkgmap);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland while ((n = gpkgmapvfp(&entry, vfp)) > 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland progerr(gettext("bad entry read in pkgmap file"));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (entry.path && *entry.path) ? entry.path : "Unknown");
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandpkgusage(struct cfstat *dp, struct cfent *pentry)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if ((pentry->ftype == 'd') || (pentry->ftype == 'x'))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Only collect mode stats if they would be meaningful. */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* bug # 1081606 */