15c51f124SMoriah Waterland /*
25c51f124SMoriah Waterland  * CDDL HEADER START
35c51f124SMoriah Waterland  *
45c51f124SMoriah Waterland  * The contents of this file are subject to the terms of the
55c51f124SMoriah Waterland  * Common Development and Distribution License (the "License").
65c51f124SMoriah Waterland  * You may not use this file except in compliance with the License.
75c51f124SMoriah Waterland  *
85c51f124SMoriah Waterland  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95c51f124SMoriah Waterland  * or http://www.opensolaris.org/os/licensing.
105c51f124SMoriah Waterland  * See the License for the specific language governing permissions
115c51f124SMoriah Waterland  * and limitations under the License.
125c51f124SMoriah Waterland  *
135c51f124SMoriah Waterland  * When distributing Covered Code, include this CDDL HEADER in each
145c51f124SMoriah Waterland  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155c51f124SMoriah Waterland  * If applicable, add the following below this CDDL HEADER, with the
165c51f124SMoriah Waterland  * fields enclosed by brackets "[]" replaced with your own identifying
175c51f124SMoriah Waterland  * information: Portions Copyright [yyyy] [name of copyright owner]
185c51f124SMoriah Waterland  *
195c51f124SMoriah Waterland  * CDDL HEADER END
205c51f124SMoriah Waterland  */
215c51f124SMoriah Waterland 
225c51f124SMoriah Waterland /*
2323a1cceaSRoger A. Faulkner  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
245c51f124SMoriah Waterland  */
255c51f124SMoriah Waterland 
265c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
275c51f124SMoriah Waterland /* All Rights Reserved */
285c51f124SMoriah Waterland 
295c51f124SMoriah Waterland #include <stdio.h>
305c51f124SMoriah Waterland #include <errno.h>
315c51f124SMoriah Waterland #include <limits.h>
325c51f124SMoriah Waterland #include <stdlib.h>
335c51f124SMoriah Waterland #include <unistd.h>
345c51f124SMoriah Waterland #include <string.h>
355c51f124SMoriah Waterland #include <ctype.h>
365c51f124SMoriah Waterland #include <dirent.h>
375c51f124SMoriah Waterland #include <sys/types.h>
385c51f124SMoriah Waterland #include <pkgstrct.h>
395c51f124SMoriah Waterland #include <pkginfo.h>
405c51f124SMoriah Waterland #include <locale.h>
415c51f124SMoriah Waterland #include <libintl.h>
425c51f124SMoriah Waterland #include <pkglib.h>
435c51f124SMoriah Waterland #include "libinst.h"
445c51f124SMoriah Waterland #include "libadm.h"
455c51f124SMoriah Waterland #include "messages.h"
465c51f124SMoriah Waterland 
475c51f124SMoriah Waterland #define	LSIZE	256
485c51f124SMoriah Waterland #define	NVERS	50
495c51f124SMoriah Waterland 
505c51f124SMoriah Waterland /*
515c51f124SMoriah Waterland  * internal global variables
525c51f124SMoriah Waterland  */
535c51f124SMoriah Waterland 
545c51f124SMoriah Waterland static struct pkginfo info;
555c51f124SMoriah Waterland 
565c51f124SMoriah Waterland static char	type;
575c51f124SMoriah Waterland static char	*alist[NVERS];
585c51f124SMoriah Waterland static char	*rmpkginst;
595c51f124SMoriah Waterland static char	*vlist[NVERS];
605c51f124SMoriah Waterland static char	file[128];
615c51f124SMoriah Waterland static char	name[128];
625c51f124SMoriah Waterland static char	rmpkg[PKGSIZ+1];
635c51f124SMoriah Waterland static char	wabbrev[128];
645c51f124SMoriah Waterland 
655c51f124SMoriah Waterland static int	errflg = 0;
665c51f124SMoriah Waterland static int	nlist;
675c51f124SMoriah Waterland static int	pkgexist;
685c51f124SMoriah Waterland static int	pkgokay;
695c51f124SMoriah Waterland static int	is_update;
705c51f124SMoriah Waterland 
715c51f124SMoriah Waterland /*
725c51f124SMoriah Waterland  * IMPORTANT NOTE: THE SIZE OF 'abbrev' IS HARD CODED INTO THE CHARACTER
735c51f124SMoriah Waterland  * ARRAY SSCANF_FORMAT -- YOU MUST UPDATE BOTH VALUES AT THE SAME TIME!!
745c51f124SMoriah Waterland  */
755c51f124SMoriah Waterland 
765c51f124SMoriah Waterland static char	abbrev[128+1];
775c51f124SMoriah Waterland static char	*SSCANF_FORMAT = "%c %128s %[^\n]";
785c51f124SMoriah Waterland 
795c51f124SMoriah Waterland /*
805c51f124SMoriah Waterland  * forward declarations
815c51f124SMoriah Waterland  */
825c51f124SMoriah Waterland 
835c51f124SMoriah Waterland static void	ckrdeps(boolean_t a_preinstallCheck);
845c51f124SMoriah Waterland static void	ckpreq(FILE *fp, char *dname, boolean_t a_preinstallCheck);
855c51f124SMoriah Waterland static void	deponme(char *pkginst, char *pkgname,
865c51f124SMoriah Waterland 				boolean_t a_preinstallCheck);
875c51f124SMoriah Waterland static void	prereq(char *pkginst, char *pkgname,
885c51f124SMoriah Waterland 				boolean_t a_preinstallCheck);
895c51f124SMoriah Waterland static void	incompat(char *pkginst, char *pkgname,
905c51f124SMoriah Waterland 				boolean_t a_preinstallCheck);
9123a1cceaSRoger A. Faulkner static int	getaline(FILE *fp);
925c51f124SMoriah Waterland 
935c51f124SMoriah Waterland /*
945c51f124SMoriah Waterland  * *****************************************************************************
955c51f124SMoriah Waterland  * global external (public) functions
965c51f124SMoriah Waterland  * *****************************************************************************
975c51f124SMoriah Waterland  */
985c51f124SMoriah Waterland 
995c51f124SMoriah Waterland int
dockdeps(char * a_depfile,int a_removeFlag,boolean_t a_preinstallCheck)1005c51f124SMoriah Waterland dockdeps(char *a_depfile, int a_removeFlag, boolean_t a_preinstallCheck)
1015c51f124SMoriah Waterland {
1025c51f124SMoriah Waterland 	FILE	*fp;
1035c51f124SMoriah Waterland 	int	i;
1045c51f124SMoriah Waterland 	char	*inst;
1055c51f124SMoriah Waterland 
1065c51f124SMoriah Waterland 	if (a_removeFlag) {
1075c51f124SMoriah Waterland 		/* check removal dependencies */
1085c51f124SMoriah Waterland 		rmpkginst = a_depfile;
1095c51f124SMoriah Waterland 		(void) strncpy(rmpkg, rmpkginst, PKGSIZ);
1105c51f124SMoriah Waterland 		(void) strtok(rmpkg, ".");
1115c51f124SMoriah Waterland 		(void) snprintf(file, sizeof (file),
1125c51f124SMoriah Waterland 				"%s/%s/%s", pkgdir, rmpkginst, DEPEND_FILE);
1135c51f124SMoriah Waterland 		if ((fp = fopen(file, "r")) == NULL)
1145c51f124SMoriah Waterland 			goto done;
1155c51f124SMoriah Waterland 	} else {
1165c51f124SMoriah Waterland 		if ((fp = fopen(a_depfile, "r")) == NULL) {
1175c51f124SMoriah Waterland 			progerr(ERR_CANNOT_OPEN_DEPEND_FILE, a_depfile,
1185c51f124SMoriah Waterland 					strerror(errno));
1195c51f124SMoriah Waterland 			quit(99);
1205c51f124SMoriah Waterland 		}
1215c51f124SMoriah Waterland 	}
1225c51f124SMoriah Waterland 
12323a1cceaSRoger A. Faulkner 	while (getaline(fp)) {
1245c51f124SMoriah Waterland 		switch (type) {
1255c51f124SMoriah Waterland 		    case 'I':
1265c51f124SMoriah Waterland 		    case 'P':
1275c51f124SMoriah Waterland 			if (a_removeFlag) {
1285c51f124SMoriah Waterland 				continue;
1295c51f124SMoriah Waterland 			}
1305c51f124SMoriah Waterland 			break;
1315c51f124SMoriah Waterland 
1325c51f124SMoriah Waterland 		    case 'R':
1335c51f124SMoriah Waterland 			if (!a_removeFlag) {
1345c51f124SMoriah Waterland 				continue;
1355c51f124SMoriah Waterland 			}
1365c51f124SMoriah Waterland 			break;
1375c51f124SMoriah Waterland 
1385c51f124SMoriah Waterland 		    default:
1395c51f124SMoriah Waterland 			errflg++;
1405c51f124SMoriah Waterland 			progerr(ERR_UNKNOWN_DEPENDENCY, type);
1415c51f124SMoriah Waterland 			break;
1425c51f124SMoriah Waterland 		}
1435c51f124SMoriah Waterland 
1445c51f124SMoriah Waterland 		/* check to see if any versions listed are installed */
1455c51f124SMoriah Waterland 		pkgexist = pkgokay = 0;
1465c51f124SMoriah Waterland 		i = 0;
1475c51f124SMoriah Waterland 		if (strchr(abbrev, '.')) {
1485c51f124SMoriah Waterland 			progerr(ERR_PKGABRV, abbrev);
1495c51f124SMoriah Waterland 		}
1505c51f124SMoriah Waterland 		(void) snprintf(wabbrev, sizeof (wabbrev), "%s.*", abbrev);
1515c51f124SMoriah Waterland 
1525c51f124SMoriah Waterland 		do {
1535c51f124SMoriah Waterland 			inst = fpkginst(wabbrev, alist[i], vlist[i]);
1545c51f124SMoriah Waterland 			if (inst && (pkginfo(&info, inst, NULL, NULL) == 0)) {
1555c51f124SMoriah Waterland 				pkgexist++;
156*9ab815e1SGarrett D'Amore 				if (info.status == PI_INSTALLED)
1575c51f124SMoriah Waterland 					pkgokay++;
1585c51f124SMoriah Waterland 			}
1595c51f124SMoriah Waterland 		} while (++i < nlist);
1605c51f124SMoriah Waterland 		(void) fpkginst(NULL); 	/* force closing/rewind of files */
1615c51f124SMoriah Waterland 
1625c51f124SMoriah Waterland 		if (!info.name) {
1635c51f124SMoriah Waterland 			info.name = name;
1645c51f124SMoriah Waterland 		}
1655c51f124SMoriah Waterland 
1665c51f124SMoriah Waterland 		switch (type) {
1675c51f124SMoriah Waterland 		    case 'I':
1685c51f124SMoriah Waterland 			incompat(abbrev, info.name, a_preinstallCheck);
1695c51f124SMoriah Waterland 			break;
1705c51f124SMoriah Waterland 
1715c51f124SMoriah Waterland 		    case 'P':
1725c51f124SMoriah Waterland 			prereq(abbrev, name, a_preinstallCheck);
1735c51f124SMoriah Waterland 			break;
1745c51f124SMoriah Waterland 
1755c51f124SMoriah Waterland 		    case 'R':
1765c51f124SMoriah Waterland 			deponme(abbrev, info.name, a_preinstallCheck);
1775c51f124SMoriah Waterland 		}
1785c51f124SMoriah Waterland 	}
1795c51f124SMoriah Waterland 	(void) fclose(fp);
1805c51f124SMoriah Waterland 
1815c51f124SMoriah Waterland done:
1825c51f124SMoriah Waterland 	if (a_removeFlag) {
1835c51f124SMoriah Waterland 		ckrdeps(a_preinstallCheck);
1845c51f124SMoriah Waterland 	}
1855c51f124SMoriah Waterland 
1865c51f124SMoriah Waterland 	return (errflg);
1875c51f124SMoriah Waterland }
1885c51f124SMoriah Waterland 
1895c51f124SMoriah Waterland void
setUpdate(void)1905c51f124SMoriah Waterland setUpdate(void)
1915c51f124SMoriah Waterland {
1925c51f124SMoriah Waterland 	is_update = 1;
1935c51f124SMoriah Waterland }
1945c51f124SMoriah Waterland 
1955c51f124SMoriah Waterland int
isUpdate(void)1965c51f124SMoriah Waterland isUpdate(void)
1975c51f124SMoriah Waterland {
1985c51f124SMoriah Waterland 	return ((is_update) ? 1 : 0);
1995c51f124SMoriah Waterland }
2005c51f124SMoriah Waterland 
2015c51f124SMoriah Waterland /*
2025c51f124SMoriah Waterland  * *****************************************************************************
2035c51f124SMoriah Waterland  * static internal (private) functions
2045c51f124SMoriah Waterland  * *****************************************************************************
2055c51f124SMoriah Waterland  */
2065c51f124SMoriah Waterland 
2075c51f124SMoriah Waterland static void
incompat(char * pkginst,char * pkgname,boolean_t a_preinstallCheck)2085c51f124SMoriah Waterland incompat(char *pkginst, char *pkgname, boolean_t a_preinstallCheck)
2095c51f124SMoriah Waterland {
2105c51f124SMoriah Waterland 	char buf[512];
2115c51f124SMoriah Waterland 
2125c51f124SMoriah Waterland 	if (!pkgexist)
2135c51f124SMoriah Waterland 		return;
2145c51f124SMoriah Waterland 
2155c51f124SMoriah Waterland 	errflg++;
2165c51f124SMoriah Waterland 	if (a_preinstallCheck == B_TRUE) {
2175c51f124SMoriah Waterland 		(void) fprintf(stdout, "incompat=%s\n", pkginst);
2185c51f124SMoriah Waterland 		return;
2195c51f124SMoriah Waterland 	}
2205c51f124SMoriah Waterland 
2215c51f124SMoriah Waterland 	logerr(ERR_WARNING);
2225c51f124SMoriah Waterland 	(void) snprintf(buf, sizeof (buf), ERR_INCOMP_VERS, pkginst, pkgname);
2235c51f124SMoriah Waterland 	puttext(stderr, buf, 4, 0);
2245c51f124SMoriah Waterland 	(void) putc('\n', stderr);
2255c51f124SMoriah Waterland }
2265c51f124SMoriah Waterland 
2275c51f124SMoriah Waterland static void
prereq(char * pkginst,char * pkgname,boolean_t a_preinstallCheck)2285c51f124SMoriah Waterland prereq(char *pkginst, char *pkgname, boolean_t a_preinstallCheck)
2295c51f124SMoriah Waterland {
2305c51f124SMoriah Waterland 	register int i;
2315c51f124SMoriah Waterland 	char buf[512];
2325c51f124SMoriah Waterland 
2335c51f124SMoriah Waterland 	if (pkgokay) {
2345c51f124SMoriah Waterland 		return;
2355c51f124SMoriah Waterland 	}
2365c51f124SMoriah Waterland 
2375c51f124SMoriah Waterland 	errflg++;
2385c51f124SMoriah Waterland 
2395c51f124SMoriah Waterland 	if (a_preinstallCheck == B_TRUE) {
2405c51f124SMoriah Waterland 		if (pkgexist) {
2415c51f124SMoriah Waterland 			(void) fprintf(stdout,
2425c51f124SMoriah Waterland 				"prerequisite-incomplete=%s\n", pkginst);
2435c51f124SMoriah Waterland 		} else {
2445c51f124SMoriah Waterland 			(void) fprintf(stdout,
2455c51f124SMoriah Waterland 				"prerequisite-installed=%s\n", pkginst);
2465c51f124SMoriah Waterland 		}
2475c51f124SMoriah Waterland 		return;
2485c51f124SMoriah Waterland 	}
2495c51f124SMoriah Waterland 
2505c51f124SMoriah Waterland 	logerr(ERR_WARNING);
2515c51f124SMoriah Waterland 	if (pkgexist) {
2525c51f124SMoriah Waterland 		(void) snprintf(buf, sizeof (buf), ERR_PRENCI, pkginst,
2535c51f124SMoriah Waterland 					pkgname);
2545c51f124SMoriah Waterland 		puttext(stderr, buf, 4, 0);
2555c51f124SMoriah Waterland 		(void) putc('\n', stderr);
2565c51f124SMoriah Waterland 	} else {
2575c51f124SMoriah Waterland 		(void) snprintf(buf, sizeof (buf), ERR_PREREQ, pkginst,
2585c51f124SMoriah Waterland 					pkgname);
2595c51f124SMoriah Waterland 		if (nlist) {
2605c51f124SMoriah Waterland 			(void) strcat(buf, ERR_VALINST);
2615c51f124SMoriah Waterland 		}
2625c51f124SMoriah Waterland 		puttext(stderr, buf, 4, 0);
2635c51f124SMoriah Waterland 		(void) putc('\n', stderr);
2645c51f124SMoriah Waterland 		for (i = 0; i < nlist; i++) {
2655c51f124SMoriah Waterland 			(void) printf("          ");
2665c51f124SMoriah Waterland 			if (alist[i])
2675c51f124SMoriah Waterland 				(void) printf("(%s) ", alist[i]);
2685c51f124SMoriah Waterland 			if (vlist[i])
2695c51f124SMoriah Waterland 				(void) printf("%s", vlist[i]);
2705c51f124SMoriah Waterland 			(void) printf("\n");
2715c51f124SMoriah Waterland 		}
2725c51f124SMoriah Waterland 	}
2735c51f124SMoriah Waterland }
2745c51f124SMoriah Waterland 
2755c51f124SMoriah Waterland static void
deponme(char * pkginst,char * pkgname,boolean_t a_preinstallCheck)2765c51f124SMoriah Waterland deponme(char *pkginst, char *pkgname, boolean_t a_preinstallCheck)
2775c51f124SMoriah Waterland {
2785c51f124SMoriah Waterland 	char buf[512];
2795c51f124SMoriah Waterland 
2805c51f124SMoriah Waterland 	if (!pkgexist)
2815c51f124SMoriah Waterland 		return;
2825c51f124SMoriah Waterland 
2835c51f124SMoriah Waterland 	errflg++;
2845c51f124SMoriah Waterland 
2855c51f124SMoriah Waterland 	if (a_preinstallCheck == B_TRUE) {
2865c51f124SMoriah Waterland 		if (!pkgname || !pkgname[0]) {
2875c51f124SMoriah Waterland 			(void) snprintf(buf, sizeof (buf),
2885c51f124SMoriah Waterland 					"dependonme=%s", pkginst);
2895c51f124SMoriah Waterland 		} else {
2905c51f124SMoriah Waterland 			(void) snprintf(buf, sizeof (buf),
2915c51f124SMoriah Waterland 				"dependsonme=%s:%s", pkginst, pkgname);
2925c51f124SMoriah Waterland 		}
2935c51f124SMoriah Waterland 		(void) fprintf(stdout, "%s\n", buf);
2945c51f124SMoriah Waterland 		return;
2955c51f124SMoriah Waterland 	}
2965c51f124SMoriah Waterland 
2975c51f124SMoriah Waterland 	logerr(ERR_WARNING);
2985c51f124SMoriah Waterland 	if (!pkgname || !pkgname[0]) {
2995c51f124SMoriah Waterland 		(void) snprintf(buf, sizeof (buf), ERR_DEPONME, pkginst);
3005c51f124SMoriah Waterland 	} else {
3015c51f124SMoriah Waterland 		(void) snprintf(buf, sizeof (buf), ERR_DEPNAM, pkginst,
3025c51f124SMoriah Waterland 				pkgname);
3035c51f124SMoriah Waterland 	}
3045c51f124SMoriah Waterland 	puttext(stderr, buf, 4, 0);
3055c51f124SMoriah Waterland 	(void) putc('\n', stderr);
3065c51f124SMoriah Waterland }
3075c51f124SMoriah Waterland 
3085c51f124SMoriah Waterland static int
getaline(FILE * fp)30923a1cceaSRoger A. Faulkner getaline(FILE *fp)
3105c51f124SMoriah Waterland {
3115c51f124SMoriah Waterland 	register int i, c, found;
3125c51f124SMoriah Waterland 	char *pt, *new, line[LSIZE];
3135c51f124SMoriah Waterland 
3145c51f124SMoriah Waterland 	abbrev[0] = name[0] = type = '\0';
3155c51f124SMoriah Waterland 
3165c51f124SMoriah Waterland 	for (i = 0; i < nlist; i++) {
3175c51f124SMoriah Waterland 		if (alist[i]) {
3185c51f124SMoriah Waterland 			free(alist[i]);
3195c51f124SMoriah Waterland 			alist[i] = NULL;
3205c51f124SMoriah Waterland 		}
3215c51f124SMoriah Waterland 		if (vlist[i]) {
3225c51f124SMoriah Waterland 			free(vlist[i]);
3235c51f124SMoriah Waterland 			vlist[i] = NULL;
3245c51f124SMoriah Waterland 		}
3255c51f124SMoriah Waterland 	}
3265c51f124SMoriah Waterland 	alist[0] = vlist[0] = NULL;
3275c51f124SMoriah Waterland 
3285c51f124SMoriah Waterland 	found = (-1);
3295c51f124SMoriah Waterland 	nlist = 0;
3305c51f124SMoriah Waterland 	while ((c = getc(fp)) != EOF) {
3315c51f124SMoriah Waterland 		(void) ungetc(c, fp);
3325c51f124SMoriah Waterland 		if ((found >= 0) && !isspace(c))
3335c51f124SMoriah Waterland 			return (1);
3345c51f124SMoriah Waterland 
3355c51f124SMoriah Waterland 		if (!fgets(line, LSIZE, fp))
3365c51f124SMoriah Waterland 			break;
3375c51f124SMoriah Waterland 
3385c51f124SMoriah Waterland 		for (pt = line; isspace(*pt); /* void */)
3395c51f124SMoriah Waterland 			pt++;
3405c51f124SMoriah Waterland 		if (!*pt || (*pt == '#'))
3415c51f124SMoriah Waterland 			continue;
3425c51f124SMoriah Waterland 
3435c51f124SMoriah Waterland 		if (pt == line) {
3445c51f124SMoriah Waterland 			/* begin new definition */
3455c51f124SMoriah Waterland 			/* LINTED variable format specifier to sscanf(): */
3465c51f124SMoriah Waterland 			(void) sscanf(line, SSCANF_FORMAT, &type, abbrev, name);
3475c51f124SMoriah Waterland 			found++;
3485c51f124SMoriah Waterland 			continue;
3495c51f124SMoriah Waterland 		}
3505c51f124SMoriah Waterland 		if (found < 0)
3515c51f124SMoriah Waterland 			return (0);
3525c51f124SMoriah Waterland 
3535c51f124SMoriah Waterland 		if (*pt == '(') {
3545c51f124SMoriah Waterland 			/* architecture is specified */
3555c51f124SMoriah Waterland 			if (new = strchr(pt, ')'))
3565c51f124SMoriah Waterland 				*new++ = '\0';
3575c51f124SMoriah Waterland 			else
3585c51f124SMoriah Waterland 				return (-1); /* bad specification */
3595c51f124SMoriah Waterland 			alist[found] = qstrdup(pt+1);
3605c51f124SMoriah Waterland 			pt = new;
3615c51f124SMoriah Waterland 		}
3625c51f124SMoriah Waterland 		while (isspace(*pt))
3635c51f124SMoriah Waterland 			pt++;
3645c51f124SMoriah Waterland 		if (*pt) {
3655c51f124SMoriah Waterland 			vlist[found] = qstrdup(pt);
3665c51f124SMoriah Waterland 			if (pt = strchr(vlist[found], '\n'))
3675c51f124SMoriah Waterland 				*pt = '\0';
3685c51f124SMoriah Waterland 		}
3695c51f124SMoriah Waterland 		found++;
3705c51f124SMoriah Waterland 		nlist++;
3715c51f124SMoriah Waterland 	}
3725c51f124SMoriah Waterland 	return ((found >= 0) ? 1 : 0);
3735c51f124SMoriah Waterland }
3745c51f124SMoriah Waterland 
3755c51f124SMoriah Waterland static void
ckrdeps(boolean_t a_preinstallCheck)3765c51f124SMoriah Waterland ckrdeps(boolean_t a_preinstallCheck)
3775c51f124SMoriah Waterland {
3785c51f124SMoriah Waterland 	struct dirent *drp;
3795c51f124SMoriah Waterland 	DIR	*dirfp;
3805c51f124SMoriah Waterland 	FILE	*fp;
3815c51f124SMoriah Waterland 	char	depfile[PATH_MAX+1];
3825c51f124SMoriah Waterland 
3835c51f124SMoriah Waterland 	if ((dirfp = opendir(pkgdir)) == NULL)
3845c51f124SMoriah Waterland 		return;
3855c51f124SMoriah Waterland 
3865c51f124SMoriah Waterland 	while ((drp = readdir(dirfp)) != NULL) {
3875c51f124SMoriah Waterland 		if (drp->d_name[0] == '.')
3885c51f124SMoriah Waterland 			continue;
3895c51f124SMoriah Waterland 
3905c51f124SMoriah Waterland 		if (strcmp(drp->d_name, rmpkginst) == 0)
3915c51f124SMoriah Waterland 			continue; /* others don't include me */
3925c51f124SMoriah Waterland 		(void) snprintf(depfile, sizeof (depfile),
3935c51f124SMoriah Waterland 				"%s/%s/%s", pkgdir, drp->d_name, DEPEND_FILE);
3945c51f124SMoriah Waterland 		if ((fp = fopen(depfile, "r")) == NULL)
3955c51f124SMoriah Waterland 			continue;
3965c51f124SMoriah Waterland 
3975c51f124SMoriah Waterland 		ckpreq(fp, drp->d_name, a_preinstallCheck);
3985c51f124SMoriah Waterland 	}
3995c51f124SMoriah Waterland 	(void) closedir(dirfp);
4005c51f124SMoriah Waterland }
4015c51f124SMoriah Waterland 
4025c51f124SMoriah Waterland static void
ckpreq(FILE * fp,char * dname,boolean_t a_preinstallCheck)4035c51f124SMoriah Waterland ckpreq(FILE *fp, char *dname, boolean_t a_preinstallCheck)
4045c51f124SMoriah Waterland {
4055c51f124SMoriah Waterland 	register int i;
4065c51f124SMoriah Waterland 	char	*inst;
4075c51f124SMoriah Waterland 
40823a1cceaSRoger A. Faulkner 	while (getaline(fp)) {
4095c51f124SMoriah Waterland 		if (type != 'P')
4105c51f124SMoriah Waterland 			continue;
4115c51f124SMoriah Waterland 
4125c51f124SMoriah Waterland 		if (strcmp(abbrev, rmpkg))
4135c51f124SMoriah Waterland 			continue;
4145c51f124SMoriah Waterland 
4155c51f124SMoriah Waterland 		/* see if package is installed */
4165c51f124SMoriah Waterland 		i = 0;
4175c51f124SMoriah Waterland 		if (strchr(abbrev, '.') == 0) {
4185c51f124SMoriah Waterland 			(void) strcat(abbrev, ".*");
4195c51f124SMoriah Waterland 		}
4205c51f124SMoriah Waterland 		pkgexist = 1;
4215c51f124SMoriah Waterland 
4225c51f124SMoriah Waterland 		do {
4235c51f124SMoriah Waterland 			if (inst = fpkginst(abbrev, alist[i], vlist[i])) {
4245c51f124SMoriah Waterland 				if (strcmp(inst, rmpkginst) == 0) {
4255c51f124SMoriah Waterland 					deponme(dname, "", a_preinstallCheck);
4265c51f124SMoriah Waterland 					(void) fclose(fp);
4275c51f124SMoriah Waterland 					(void) fpkginst(NULL);
4285c51f124SMoriah Waterland 					return;
4295c51f124SMoriah Waterland 				}
4305c51f124SMoriah Waterland 			}
4315c51f124SMoriah Waterland 		} while (++i < nlist);
4325c51f124SMoriah Waterland 		(void) fpkginst(NULL);
4335c51f124SMoriah Waterland 	}
4345c51f124SMoriah Waterland 	(void) fclose(fp);
4355c51f124SMoriah Waterland }
436