19781SMoriah.Waterland@Sun.COM /*
29781SMoriah.Waterland@Sun.COM * CDDL HEADER START
39781SMoriah.Waterland@Sun.COM *
49781SMoriah.Waterland@Sun.COM * The contents of this file are subject to the terms of the
59781SMoriah.Waterland@Sun.COM * Common Development and Distribution License (the "License").
69781SMoriah.Waterland@Sun.COM * You may not use this file except in compliance with the License.
79781SMoriah.Waterland@Sun.COM *
89781SMoriah.Waterland@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
99781SMoriah.Waterland@Sun.COM * or http://www.opensolaris.org/os/licensing.
109781SMoriah.Waterland@Sun.COM * See the License for the specific language governing permissions
119781SMoriah.Waterland@Sun.COM * and limitations under the License.
129781SMoriah.Waterland@Sun.COM *
139781SMoriah.Waterland@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
149781SMoriah.Waterland@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
159781SMoriah.Waterland@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
169781SMoriah.Waterland@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
179781SMoriah.Waterland@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
189781SMoriah.Waterland@Sun.COM *
199781SMoriah.Waterland@Sun.COM * CDDL HEADER END
209781SMoriah.Waterland@Sun.COM */
219781SMoriah.Waterland@Sun.COM
229781SMoriah.Waterland@Sun.COM /*
23*13093SRoger.Faulkner@Oracle.COM * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
249781SMoriah.Waterland@Sun.COM */
259781SMoriah.Waterland@Sun.COM
269781SMoriah.Waterland@Sun.COM /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
279781SMoriah.Waterland@Sun.COM /* All Rights Reserved */
289781SMoriah.Waterland@Sun.COM
299781SMoriah.Waterland@Sun.COM #include <stdio.h>
309781SMoriah.Waterland@Sun.COM #include <errno.h>
319781SMoriah.Waterland@Sun.COM #include <limits.h>
329781SMoriah.Waterland@Sun.COM #include <stdlib.h>
339781SMoriah.Waterland@Sun.COM #include <unistd.h>
349781SMoriah.Waterland@Sun.COM #include <string.h>
359781SMoriah.Waterland@Sun.COM #include <ctype.h>
369781SMoriah.Waterland@Sun.COM #include <dirent.h>
379781SMoriah.Waterland@Sun.COM #include <sys/types.h>
389781SMoriah.Waterland@Sun.COM #include <pkgstrct.h>
399781SMoriah.Waterland@Sun.COM #include <pkginfo.h>
409781SMoriah.Waterland@Sun.COM #include <locale.h>
419781SMoriah.Waterland@Sun.COM #include <libintl.h>
429781SMoriah.Waterland@Sun.COM #include <pkglib.h>
439781SMoriah.Waterland@Sun.COM #include "libinst.h"
449781SMoriah.Waterland@Sun.COM #include "libadm.h"
459781SMoriah.Waterland@Sun.COM #include "messages.h"
469781SMoriah.Waterland@Sun.COM
479781SMoriah.Waterland@Sun.COM #define LSIZE 256
489781SMoriah.Waterland@Sun.COM #define NVERS 50
499781SMoriah.Waterland@Sun.COM
509781SMoriah.Waterland@Sun.COM /*
519781SMoriah.Waterland@Sun.COM * internal global variables
529781SMoriah.Waterland@Sun.COM */
539781SMoriah.Waterland@Sun.COM
549781SMoriah.Waterland@Sun.COM static struct pkginfo info;
559781SMoriah.Waterland@Sun.COM
569781SMoriah.Waterland@Sun.COM static char type;
579781SMoriah.Waterland@Sun.COM static char *alist[NVERS];
589781SMoriah.Waterland@Sun.COM static char *rmpkginst;
599781SMoriah.Waterland@Sun.COM static char *vlist[NVERS];
609781SMoriah.Waterland@Sun.COM static char file[128];
619781SMoriah.Waterland@Sun.COM static char name[128];
629781SMoriah.Waterland@Sun.COM static char rmpkg[PKGSIZ+1];
639781SMoriah.Waterland@Sun.COM static char wabbrev[128];
649781SMoriah.Waterland@Sun.COM
659781SMoriah.Waterland@Sun.COM static int errflg = 0;
669781SMoriah.Waterland@Sun.COM static int nlist;
679781SMoriah.Waterland@Sun.COM static int pkgexist;
689781SMoriah.Waterland@Sun.COM static int pkgokay;
699781SMoriah.Waterland@Sun.COM static int is_update;
709781SMoriah.Waterland@Sun.COM static int is_patch_update;
719781SMoriah.Waterland@Sun.COM
729781SMoriah.Waterland@Sun.COM /*
739781SMoriah.Waterland@Sun.COM * IMPORTANT NOTE: THE SIZE OF 'abbrev' IS HARD CODED INTO THE CHARACTER
749781SMoriah.Waterland@Sun.COM * ARRAY SSCANF_FORMAT -- YOU MUST UPDATE BOTH VALUES AT THE SAME TIME!!
759781SMoriah.Waterland@Sun.COM */
769781SMoriah.Waterland@Sun.COM
779781SMoriah.Waterland@Sun.COM static char abbrev[128+1];
789781SMoriah.Waterland@Sun.COM static char *SSCANF_FORMAT = "%c %128s %[^\n]";
799781SMoriah.Waterland@Sun.COM
809781SMoriah.Waterland@Sun.COM /*
819781SMoriah.Waterland@Sun.COM * forward declarations
829781SMoriah.Waterland@Sun.COM */
839781SMoriah.Waterland@Sun.COM
849781SMoriah.Waterland@Sun.COM static void ckrdeps(boolean_t a_preinstallCheck);
859781SMoriah.Waterland@Sun.COM static void ckpreq(FILE *fp, char *dname, boolean_t a_preinstallCheck);
869781SMoriah.Waterland@Sun.COM static void deponme(char *pkginst, char *pkgname,
879781SMoriah.Waterland@Sun.COM boolean_t a_preinstallCheck);
889781SMoriah.Waterland@Sun.COM static void prereq(char *pkginst, char *pkgname,
899781SMoriah.Waterland@Sun.COM boolean_t a_preinstallCheck);
909781SMoriah.Waterland@Sun.COM static void incompat(char *pkginst, char *pkgname,
919781SMoriah.Waterland@Sun.COM boolean_t a_preinstallCheck);
92*13093SRoger.Faulkner@Oracle.COM static int getaline(FILE *fp);
939781SMoriah.Waterland@Sun.COM
949781SMoriah.Waterland@Sun.COM /*
959781SMoriah.Waterland@Sun.COM * *****************************************************************************
969781SMoriah.Waterland@Sun.COM * global external (public) functions
979781SMoriah.Waterland@Sun.COM * *****************************************************************************
989781SMoriah.Waterland@Sun.COM */
999781SMoriah.Waterland@Sun.COM
1009781SMoriah.Waterland@Sun.COM int
dockdeps(char * a_depfile,int a_removeFlag,boolean_t a_preinstallCheck)1019781SMoriah.Waterland@Sun.COM dockdeps(char *a_depfile, int a_removeFlag, boolean_t a_preinstallCheck)
1029781SMoriah.Waterland@Sun.COM {
1039781SMoriah.Waterland@Sun.COM FILE *fp;
1049781SMoriah.Waterland@Sun.COM int i;
1059781SMoriah.Waterland@Sun.COM char *inst;
1069781SMoriah.Waterland@Sun.COM
1079781SMoriah.Waterland@Sun.COM if (a_removeFlag) {
1089781SMoriah.Waterland@Sun.COM /* check removal dependencies */
1099781SMoriah.Waterland@Sun.COM rmpkginst = a_depfile;
1109781SMoriah.Waterland@Sun.COM (void) strncpy(rmpkg, rmpkginst, PKGSIZ);
1119781SMoriah.Waterland@Sun.COM (void) strtok(rmpkg, ".");
1129781SMoriah.Waterland@Sun.COM (void) snprintf(file, sizeof (file),
1139781SMoriah.Waterland@Sun.COM "%s/%s/%s", pkgdir, rmpkginst, DEPEND_FILE);
1149781SMoriah.Waterland@Sun.COM if ((fp = fopen(file, "r")) == NULL)
1159781SMoriah.Waterland@Sun.COM goto done;
1169781SMoriah.Waterland@Sun.COM } else {
1179781SMoriah.Waterland@Sun.COM if ((fp = fopen(a_depfile, "r")) == NULL) {
1189781SMoriah.Waterland@Sun.COM progerr(ERR_CANNOT_OPEN_DEPEND_FILE, a_depfile,
1199781SMoriah.Waterland@Sun.COM strerror(errno));
1209781SMoriah.Waterland@Sun.COM quit(99);
1219781SMoriah.Waterland@Sun.COM }
1229781SMoriah.Waterland@Sun.COM }
1239781SMoriah.Waterland@Sun.COM
124*13093SRoger.Faulkner@Oracle.COM while (getaline(fp)) {
1259781SMoriah.Waterland@Sun.COM switch (type) {
1269781SMoriah.Waterland@Sun.COM case 'I':
1279781SMoriah.Waterland@Sun.COM case 'P':
1289781SMoriah.Waterland@Sun.COM if (a_removeFlag) {
1299781SMoriah.Waterland@Sun.COM continue;
1309781SMoriah.Waterland@Sun.COM }
1319781SMoriah.Waterland@Sun.COM break;
1329781SMoriah.Waterland@Sun.COM
1339781SMoriah.Waterland@Sun.COM case 'R':
1349781SMoriah.Waterland@Sun.COM if (!a_removeFlag) {
1359781SMoriah.Waterland@Sun.COM continue;
1369781SMoriah.Waterland@Sun.COM }
1379781SMoriah.Waterland@Sun.COM break;
1389781SMoriah.Waterland@Sun.COM
1399781SMoriah.Waterland@Sun.COM default:
1409781SMoriah.Waterland@Sun.COM errflg++;
1419781SMoriah.Waterland@Sun.COM progerr(ERR_UNKNOWN_DEPENDENCY, type);
1429781SMoriah.Waterland@Sun.COM break;
1439781SMoriah.Waterland@Sun.COM }
1449781SMoriah.Waterland@Sun.COM
1459781SMoriah.Waterland@Sun.COM /* check to see if any versions listed are installed */
1469781SMoriah.Waterland@Sun.COM pkgexist = pkgokay = 0;
1479781SMoriah.Waterland@Sun.COM i = 0;
1489781SMoriah.Waterland@Sun.COM if (strchr(abbrev, '.')) {
1499781SMoriah.Waterland@Sun.COM progerr(ERR_PKGABRV, abbrev);
1509781SMoriah.Waterland@Sun.COM }
1519781SMoriah.Waterland@Sun.COM (void) snprintf(wabbrev, sizeof (wabbrev), "%s.*", abbrev);
1529781SMoriah.Waterland@Sun.COM
1539781SMoriah.Waterland@Sun.COM do {
1549781SMoriah.Waterland@Sun.COM inst = fpkginst(wabbrev, alist[i], vlist[i]);
1559781SMoriah.Waterland@Sun.COM if (inst && (pkginfo(&info, inst, NULL, NULL) == 0)) {
1569781SMoriah.Waterland@Sun.COM pkgexist++;
1579781SMoriah.Waterland@Sun.COM if ((info.status == PI_INSTALLED) ||
1589781SMoriah.Waterland@Sun.COM (info.status == PI_PRESVR4))
1599781SMoriah.Waterland@Sun.COM pkgokay++;
1609781SMoriah.Waterland@Sun.COM }
1619781SMoriah.Waterland@Sun.COM } while (++i < nlist);
1629781SMoriah.Waterland@Sun.COM (void) fpkginst(NULL); /* force closing/rewind of files */
1639781SMoriah.Waterland@Sun.COM
1649781SMoriah.Waterland@Sun.COM if (!info.name) {
1659781SMoriah.Waterland@Sun.COM info.name = name;
1669781SMoriah.Waterland@Sun.COM }
1679781SMoriah.Waterland@Sun.COM
1689781SMoriah.Waterland@Sun.COM switch (type) {
1699781SMoriah.Waterland@Sun.COM case 'I':
1709781SMoriah.Waterland@Sun.COM incompat(abbrev, info.name, a_preinstallCheck);
1719781SMoriah.Waterland@Sun.COM break;
1729781SMoriah.Waterland@Sun.COM
1739781SMoriah.Waterland@Sun.COM case 'P':
1749781SMoriah.Waterland@Sun.COM prereq(abbrev, name, a_preinstallCheck);
1759781SMoriah.Waterland@Sun.COM break;
1769781SMoriah.Waterland@Sun.COM
1779781SMoriah.Waterland@Sun.COM case 'R':
1789781SMoriah.Waterland@Sun.COM deponme(abbrev, info.name, a_preinstallCheck);
1799781SMoriah.Waterland@Sun.COM }
1809781SMoriah.Waterland@Sun.COM }
1819781SMoriah.Waterland@Sun.COM (void) fclose(fp);
1829781SMoriah.Waterland@Sun.COM
1839781SMoriah.Waterland@Sun.COM done:
1849781SMoriah.Waterland@Sun.COM if (a_removeFlag) {
1859781SMoriah.Waterland@Sun.COM ckrdeps(a_preinstallCheck);
1869781SMoriah.Waterland@Sun.COM }
1879781SMoriah.Waterland@Sun.COM
1889781SMoriah.Waterland@Sun.COM return (errflg);
1899781SMoriah.Waterland@Sun.COM }
1909781SMoriah.Waterland@Sun.COM
1919781SMoriah.Waterland@Sun.COM void
setPatchUpdate(void)1929781SMoriah.Waterland@Sun.COM setPatchUpdate(void)
1939781SMoriah.Waterland@Sun.COM {
1949781SMoriah.Waterland@Sun.COM is_patch_update = 1;
1959781SMoriah.Waterland@Sun.COM }
1969781SMoriah.Waterland@Sun.COM
1979781SMoriah.Waterland@Sun.COM int
isPatchUpdate(void)1989781SMoriah.Waterland@Sun.COM isPatchUpdate(void)
1999781SMoriah.Waterland@Sun.COM {
2009781SMoriah.Waterland@Sun.COM return ((is_patch_update) ? 1 : 0);
2019781SMoriah.Waterland@Sun.COM }
2029781SMoriah.Waterland@Sun.COM
2039781SMoriah.Waterland@Sun.COM void
setUpdate(void)2049781SMoriah.Waterland@Sun.COM setUpdate(void)
2059781SMoriah.Waterland@Sun.COM {
2069781SMoriah.Waterland@Sun.COM is_update = 1;
2079781SMoriah.Waterland@Sun.COM }
2089781SMoriah.Waterland@Sun.COM
2099781SMoriah.Waterland@Sun.COM int
isUpdate(void)2109781SMoriah.Waterland@Sun.COM isUpdate(void)
2119781SMoriah.Waterland@Sun.COM {
2129781SMoriah.Waterland@Sun.COM return ((is_update) ? 1 : 0);
2139781SMoriah.Waterland@Sun.COM }
2149781SMoriah.Waterland@Sun.COM
2159781SMoriah.Waterland@Sun.COM /*
2169781SMoriah.Waterland@Sun.COM * *****************************************************************************
2179781SMoriah.Waterland@Sun.COM * static internal (private) functions
2189781SMoriah.Waterland@Sun.COM * *****************************************************************************
2199781SMoriah.Waterland@Sun.COM */
2209781SMoriah.Waterland@Sun.COM
2219781SMoriah.Waterland@Sun.COM static void
incompat(char * pkginst,char * pkgname,boolean_t a_preinstallCheck)2229781SMoriah.Waterland@Sun.COM incompat(char *pkginst, char *pkgname, boolean_t a_preinstallCheck)
2239781SMoriah.Waterland@Sun.COM {
2249781SMoriah.Waterland@Sun.COM char buf[512];
2259781SMoriah.Waterland@Sun.COM
2269781SMoriah.Waterland@Sun.COM if (!pkgexist)
2279781SMoriah.Waterland@Sun.COM return;
2289781SMoriah.Waterland@Sun.COM
2299781SMoriah.Waterland@Sun.COM errflg++;
2309781SMoriah.Waterland@Sun.COM if (a_preinstallCheck == B_TRUE) {
2319781SMoriah.Waterland@Sun.COM (void) fprintf(stdout, "incompat=%s\n", pkginst);
2329781SMoriah.Waterland@Sun.COM return;
2339781SMoriah.Waterland@Sun.COM }
2349781SMoriah.Waterland@Sun.COM
2359781SMoriah.Waterland@Sun.COM logerr(ERR_WARNING);
2369781SMoriah.Waterland@Sun.COM (void) snprintf(buf, sizeof (buf), ERR_INCOMP_VERS, pkginst, pkgname);
2379781SMoriah.Waterland@Sun.COM puttext(stderr, buf, 4, 0);
2389781SMoriah.Waterland@Sun.COM (void) putc('\n', stderr);
2399781SMoriah.Waterland@Sun.COM }
2409781SMoriah.Waterland@Sun.COM
2419781SMoriah.Waterland@Sun.COM static void
prereq(char * pkginst,char * pkgname,boolean_t a_preinstallCheck)2429781SMoriah.Waterland@Sun.COM prereq(char *pkginst, char *pkgname, boolean_t a_preinstallCheck)
2439781SMoriah.Waterland@Sun.COM {
2449781SMoriah.Waterland@Sun.COM register int i;
2459781SMoriah.Waterland@Sun.COM char buf[512];
2469781SMoriah.Waterland@Sun.COM
2479781SMoriah.Waterland@Sun.COM if (pkgokay) {
2489781SMoriah.Waterland@Sun.COM return;
2499781SMoriah.Waterland@Sun.COM }
2509781SMoriah.Waterland@Sun.COM
2519781SMoriah.Waterland@Sun.COM errflg++;
2529781SMoriah.Waterland@Sun.COM
2539781SMoriah.Waterland@Sun.COM if (a_preinstallCheck == B_TRUE) {
2549781SMoriah.Waterland@Sun.COM if (pkgexist) {
2559781SMoriah.Waterland@Sun.COM (void) fprintf(stdout,
2569781SMoriah.Waterland@Sun.COM "prerequisite-incomplete=%s\n", pkginst);
2579781SMoriah.Waterland@Sun.COM } else {
2589781SMoriah.Waterland@Sun.COM (void) fprintf(stdout,
2599781SMoriah.Waterland@Sun.COM "prerequisite-installed=%s\n", pkginst);
2609781SMoriah.Waterland@Sun.COM }
2619781SMoriah.Waterland@Sun.COM return;
2629781SMoriah.Waterland@Sun.COM }
2639781SMoriah.Waterland@Sun.COM
2649781SMoriah.Waterland@Sun.COM logerr(ERR_WARNING);
2659781SMoriah.Waterland@Sun.COM if (pkgexist) {
2669781SMoriah.Waterland@Sun.COM (void) snprintf(buf, sizeof (buf), ERR_PRENCI, pkginst,
2679781SMoriah.Waterland@Sun.COM pkgname);
2689781SMoriah.Waterland@Sun.COM puttext(stderr, buf, 4, 0);
2699781SMoriah.Waterland@Sun.COM (void) putc('\n', stderr);
2709781SMoriah.Waterland@Sun.COM } else {
2719781SMoriah.Waterland@Sun.COM (void) snprintf(buf, sizeof (buf), ERR_PREREQ, pkginst,
2729781SMoriah.Waterland@Sun.COM pkgname);
2739781SMoriah.Waterland@Sun.COM if (nlist) {
2749781SMoriah.Waterland@Sun.COM (void) strcat(buf, ERR_VALINST);
2759781SMoriah.Waterland@Sun.COM }
2769781SMoriah.Waterland@Sun.COM puttext(stderr, buf, 4, 0);
2779781SMoriah.Waterland@Sun.COM (void) putc('\n', stderr);
2789781SMoriah.Waterland@Sun.COM for (i = 0; i < nlist; i++) {
2799781SMoriah.Waterland@Sun.COM (void) printf(" ");
2809781SMoriah.Waterland@Sun.COM if (alist[i])
2819781SMoriah.Waterland@Sun.COM (void) printf("(%s) ", alist[i]);
2829781SMoriah.Waterland@Sun.COM if (vlist[i])
2839781SMoriah.Waterland@Sun.COM (void) printf("%s", vlist[i]);
2849781SMoriah.Waterland@Sun.COM (void) printf("\n");
2859781SMoriah.Waterland@Sun.COM }
2869781SMoriah.Waterland@Sun.COM }
2879781SMoriah.Waterland@Sun.COM }
2889781SMoriah.Waterland@Sun.COM
2899781SMoriah.Waterland@Sun.COM static void
deponme(char * pkginst,char * pkgname,boolean_t a_preinstallCheck)2909781SMoriah.Waterland@Sun.COM deponme(char *pkginst, char *pkgname, boolean_t a_preinstallCheck)
2919781SMoriah.Waterland@Sun.COM {
2929781SMoriah.Waterland@Sun.COM char buf[512];
2939781SMoriah.Waterland@Sun.COM
2949781SMoriah.Waterland@Sun.COM if (!pkgexist)
2959781SMoriah.Waterland@Sun.COM return;
2969781SMoriah.Waterland@Sun.COM
2979781SMoriah.Waterland@Sun.COM errflg++;
2989781SMoriah.Waterland@Sun.COM
2999781SMoriah.Waterland@Sun.COM if (a_preinstallCheck == B_TRUE) {
3009781SMoriah.Waterland@Sun.COM if (!pkgname || !pkgname[0]) {
3019781SMoriah.Waterland@Sun.COM (void) snprintf(buf, sizeof (buf),
3029781SMoriah.Waterland@Sun.COM "dependonme=%s", pkginst);
3039781SMoriah.Waterland@Sun.COM } else {
3049781SMoriah.Waterland@Sun.COM (void) snprintf(buf, sizeof (buf),
3059781SMoriah.Waterland@Sun.COM "dependsonme=%s:%s", pkginst, pkgname);
3069781SMoriah.Waterland@Sun.COM }
3079781SMoriah.Waterland@Sun.COM (void) fprintf(stdout, "%s\n", buf);
3089781SMoriah.Waterland@Sun.COM return;
3099781SMoriah.Waterland@Sun.COM }
3109781SMoriah.Waterland@Sun.COM
3119781SMoriah.Waterland@Sun.COM logerr(ERR_WARNING);
3129781SMoriah.Waterland@Sun.COM if (!pkgname || !pkgname[0]) {
3139781SMoriah.Waterland@Sun.COM (void) snprintf(buf, sizeof (buf), ERR_DEPONME, pkginst);
3149781SMoriah.Waterland@Sun.COM } else {
3159781SMoriah.Waterland@Sun.COM (void) snprintf(buf, sizeof (buf), ERR_DEPNAM, pkginst,
3169781SMoriah.Waterland@Sun.COM pkgname);
3179781SMoriah.Waterland@Sun.COM }
3189781SMoriah.Waterland@Sun.COM puttext(stderr, buf, 4, 0);
3199781SMoriah.Waterland@Sun.COM (void) putc('\n', stderr);
3209781SMoriah.Waterland@Sun.COM }
3219781SMoriah.Waterland@Sun.COM
3229781SMoriah.Waterland@Sun.COM static int
getaline(FILE * fp)323*13093SRoger.Faulkner@Oracle.COM getaline(FILE *fp)
3249781SMoriah.Waterland@Sun.COM {
3259781SMoriah.Waterland@Sun.COM register int i, c, found;
3269781SMoriah.Waterland@Sun.COM char *pt, *new, line[LSIZE];
3279781SMoriah.Waterland@Sun.COM
3289781SMoriah.Waterland@Sun.COM abbrev[0] = name[0] = type = '\0';
3299781SMoriah.Waterland@Sun.COM
3309781SMoriah.Waterland@Sun.COM for (i = 0; i < nlist; i++) {
3319781SMoriah.Waterland@Sun.COM if (alist[i]) {
3329781SMoriah.Waterland@Sun.COM free(alist[i]);
3339781SMoriah.Waterland@Sun.COM alist[i] = NULL;
3349781SMoriah.Waterland@Sun.COM }
3359781SMoriah.Waterland@Sun.COM if (vlist[i]) {
3369781SMoriah.Waterland@Sun.COM free(vlist[i]);
3379781SMoriah.Waterland@Sun.COM vlist[i] = NULL;
3389781SMoriah.Waterland@Sun.COM }
3399781SMoriah.Waterland@Sun.COM }
3409781SMoriah.Waterland@Sun.COM alist[0] = vlist[0] = NULL;
3419781SMoriah.Waterland@Sun.COM
3429781SMoriah.Waterland@Sun.COM found = (-1);
3439781SMoriah.Waterland@Sun.COM nlist = 0;
3449781SMoriah.Waterland@Sun.COM while ((c = getc(fp)) != EOF) {
3459781SMoriah.Waterland@Sun.COM (void) ungetc(c, fp);
3469781SMoriah.Waterland@Sun.COM if ((found >= 0) && !isspace(c))
3479781SMoriah.Waterland@Sun.COM return (1);
3489781SMoriah.Waterland@Sun.COM
3499781SMoriah.Waterland@Sun.COM if (!fgets(line, LSIZE, fp))
3509781SMoriah.Waterland@Sun.COM break;
3519781SMoriah.Waterland@Sun.COM
3529781SMoriah.Waterland@Sun.COM for (pt = line; isspace(*pt); /* void */)
3539781SMoriah.Waterland@Sun.COM pt++;
3549781SMoriah.Waterland@Sun.COM if (!*pt || (*pt == '#'))
3559781SMoriah.Waterland@Sun.COM continue;
3569781SMoriah.Waterland@Sun.COM
3579781SMoriah.Waterland@Sun.COM if (pt == line) {
3589781SMoriah.Waterland@Sun.COM /* begin new definition */
3599781SMoriah.Waterland@Sun.COM /* LINTED variable format specifier to sscanf(): */
3609781SMoriah.Waterland@Sun.COM (void) sscanf(line, SSCANF_FORMAT, &type, abbrev, name);
3619781SMoriah.Waterland@Sun.COM found++;
3629781SMoriah.Waterland@Sun.COM continue;
3639781SMoriah.Waterland@Sun.COM }
3649781SMoriah.Waterland@Sun.COM if (found < 0)
3659781SMoriah.Waterland@Sun.COM return (0);
3669781SMoriah.Waterland@Sun.COM
3679781SMoriah.Waterland@Sun.COM if (*pt == '(') {
3689781SMoriah.Waterland@Sun.COM /* architecture is specified */
3699781SMoriah.Waterland@Sun.COM if (new = strchr(pt, ')'))
3709781SMoriah.Waterland@Sun.COM *new++ = '\0';
3719781SMoriah.Waterland@Sun.COM else
3729781SMoriah.Waterland@Sun.COM return (-1); /* bad specification */
3739781SMoriah.Waterland@Sun.COM alist[found] = qstrdup(pt+1);
3749781SMoriah.Waterland@Sun.COM pt = new;
3759781SMoriah.Waterland@Sun.COM }
3769781SMoriah.Waterland@Sun.COM while (isspace(*pt))
3779781SMoriah.Waterland@Sun.COM pt++;
3789781SMoriah.Waterland@Sun.COM if (*pt) {
3799781SMoriah.Waterland@Sun.COM vlist[found] = qstrdup(pt);
3809781SMoriah.Waterland@Sun.COM if (pt = strchr(vlist[found], '\n'))
3819781SMoriah.Waterland@Sun.COM *pt = '\0';
3829781SMoriah.Waterland@Sun.COM }
3839781SMoriah.Waterland@Sun.COM found++;
3849781SMoriah.Waterland@Sun.COM nlist++;
3859781SMoriah.Waterland@Sun.COM }
3869781SMoriah.Waterland@Sun.COM return ((found >= 0) ? 1 : 0);
3879781SMoriah.Waterland@Sun.COM }
3889781SMoriah.Waterland@Sun.COM
3899781SMoriah.Waterland@Sun.COM static void
ckrdeps(boolean_t a_preinstallCheck)3909781SMoriah.Waterland@Sun.COM ckrdeps(boolean_t a_preinstallCheck)
3919781SMoriah.Waterland@Sun.COM {
3929781SMoriah.Waterland@Sun.COM struct dirent *drp;
3939781SMoriah.Waterland@Sun.COM DIR *dirfp;
3949781SMoriah.Waterland@Sun.COM FILE *fp;
3959781SMoriah.Waterland@Sun.COM char depfile[PATH_MAX+1];
3969781SMoriah.Waterland@Sun.COM
3979781SMoriah.Waterland@Sun.COM if ((dirfp = opendir(pkgdir)) == NULL)
3989781SMoriah.Waterland@Sun.COM return;
3999781SMoriah.Waterland@Sun.COM
4009781SMoriah.Waterland@Sun.COM while ((drp = readdir(dirfp)) != NULL) {
4019781SMoriah.Waterland@Sun.COM if (drp->d_name[0] == '.')
4029781SMoriah.Waterland@Sun.COM continue;
4039781SMoriah.Waterland@Sun.COM
4049781SMoriah.Waterland@Sun.COM if (strcmp(drp->d_name, rmpkginst) == 0)
4059781SMoriah.Waterland@Sun.COM continue; /* others don't include me */
4069781SMoriah.Waterland@Sun.COM (void) snprintf(depfile, sizeof (depfile),
4079781SMoriah.Waterland@Sun.COM "%s/%s/%s", pkgdir, drp->d_name, DEPEND_FILE);
4089781SMoriah.Waterland@Sun.COM if ((fp = fopen(depfile, "r")) == NULL)
4099781SMoriah.Waterland@Sun.COM continue;
4109781SMoriah.Waterland@Sun.COM
4119781SMoriah.Waterland@Sun.COM ckpreq(fp, drp->d_name, a_preinstallCheck);
4129781SMoriah.Waterland@Sun.COM }
4139781SMoriah.Waterland@Sun.COM (void) closedir(dirfp);
4149781SMoriah.Waterland@Sun.COM }
4159781SMoriah.Waterland@Sun.COM
4169781SMoriah.Waterland@Sun.COM static void
ckpreq(FILE * fp,char * dname,boolean_t a_preinstallCheck)4179781SMoriah.Waterland@Sun.COM ckpreq(FILE *fp, char *dname, boolean_t a_preinstallCheck)
4189781SMoriah.Waterland@Sun.COM {
4199781SMoriah.Waterland@Sun.COM register int i;
4209781SMoriah.Waterland@Sun.COM char *inst;
4219781SMoriah.Waterland@Sun.COM
422*13093SRoger.Faulkner@Oracle.COM while (getaline(fp)) {
4239781SMoriah.Waterland@Sun.COM if (type != 'P')
4249781SMoriah.Waterland@Sun.COM continue;
4259781SMoriah.Waterland@Sun.COM
4269781SMoriah.Waterland@Sun.COM if (strcmp(abbrev, rmpkg))
4279781SMoriah.Waterland@Sun.COM continue;
4289781SMoriah.Waterland@Sun.COM
4299781SMoriah.Waterland@Sun.COM /* see if package is installed */
4309781SMoriah.Waterland@Sun.COM i = 0;
4319781SMoriah.Waterland@Sun.COM if (strchr(abbrev, '.') == 0) {
4329781SMoriah.Waterland@Sun.COM (void) strcat(abbrev, ".*");
4339781SMoriah.Waterland@Sun.COM }
4349781SMoriah.Waterland@Sun.COM pkgexist = 1;
4359781SMoriah.Waterland@Sun.COM
4369781SMoriah.Waterland@Sun.COM do {
4379781SMoriah.Waterland@Sun.COM if (inst = fpkginst(abbrev, alist[i], vlist[i])) {
4389781SMoriah.Waterland@Sun.COM if (strcmp(inst, rmpkginst) == 0) {
4399781SMoriah.Waterland@Sun.COM deponme(dname, "", a_preinstallCheck);
4409781SMoriah.Waterland@Sun.COM (void) fclose(fp);
4419781SMoriah.Waterland@Sun.COM (void) fpkginst(NULL);
4429781SMoriah.Waterland@Sun.COM return;
4439781SMoriah.Waterland@Sun.COM }
4449781SMoriah.Waterland@Sun.COM }
4459781SMoriah.Waterland@Sun.COM } while (++i < nlist);
4469781SMoriah.Waterland@Sun.COM (void) fpkginst(NULL);
4479781SMoriah.Waterland@Sun.COM }
4489781SMoriah.Waterland@Sun.COM (void) fclose(fp);
4499781SMoriah.Waterland@Sun.COM }
450