xref: /onnv-gate/usr/src/cmd/svr4pkg/pkginstall/sortmap.c (revision 9869:9bff8d14ecc3)
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*9869SCasper.Dik@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
249781SMoriah.Waterland@Sun.COM  * Use is subject to license terms.
259781SMoriah.Waterland@Sun.COM  */
269781SMoriah.Waterland@Sun.COM 
279781SMoriah.Waterland@Sun.COM /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
289781SMoriah.Waterland@Sun.COM /* All Rights Reserved */
299781SMoriah.Waterland@Sun.COM 
309781SMoriah.Waterland@Sun.COM 
319781SMoriah.Waterland@Sun.COM /*
329781SMoriah.Waterland@Sun.COM  * This module constructs a list of entries from the pkgmap associated
339781SMoriah.Waterland@Sun.COM  * with this package. When finished, this list is sorted in alphabetical
349781SMoriah.Waterland@Sun.COM  * order and an accompanying structure list, mergstat, provides
359781SMoriah.Waterland@Sun.COM  * information about how these new files merge with existing files
369781SMoriah.Waterland@Sun.COM  * already on the system.
379781SMoriah.Waterland@Sun.COM  */
389781SMoriah.Waterland@Sun.COM 
399781SMoriah.Waterland@Sun.COM #include <stdio.h>
409781SMoriah.Waterland@Sun.COM #include <string.h>
419781SMoriah.Waterland@Sun.COM #include <limits.h>
429781SMoriah.Waterland@Sun.COM #include <stdlib.h>
439781SMoriah.Waterland@Sun.COM #include <unistd.h>
449781SMoriah.Waterland@Sun.COM #include <sys/types.h>
459781SMoriah.Waterland@Sun.COM #include <pkgstrct.h>
469781SMoriah.Waterland@Sun.COM #include <pkglocs.h>
479781SMoriah.Waterland@Sun.COM #include <locale.h>
489781SMoriah.Waterland@Sun.COM #include <libintl.h>
499781SMoriah.Waterland@Sun.COM #include <install.h>
509781SMoriah.Waterland@Sun.COM #include <pkglib.h>
519781SMoriah.Waterland@Sun.COM #include <libadm.h>
529781SMoriah.Waterland@Sun.COM #include <libinst.h>
539781SMoriah.Waterland@Sun.COM 
549781SMoriah.Waterland@Sun.COM /* libinst/ocfile.c */
559781SMoriah.Waterland@Sun.COM extern int	dbchg;
569781SMoriah.Waterland@Sun.COM 
579781SMoriah.Waterland@Sun.COM static int	client_refer(struct cfextra **ext);
589781SMoriah.Waterland@Sun.COM static int	server_refer(struct cfextra **ext);
599781SMoriah.Waterland@Sun.COM 
609781SMoriah.Waterland@Sun.COM int
sortmap(struct cfextra *** extlist,VFP_T * pkgmapVfp,PKGserver pkgserver,VFP_T * tmpvfp,char * a_zoneName)619781SMoriah.Waterland@Sun.COM sortmap(struct cfextra ***extlist, VFP_T *pkgmapVfp,
62*9869SCasper.Dik@Sun.COM     PKGserver pkgserver, VFP_T *tmpvfp, char *a_zoneName)
639781SMoriah.Waterland@Sun.COM {
649781SMoriah.Waterland@Sun.COM 	int	i, n, nparts;
659781SMoriah.Waterland@Sun.COM 	char *db_mrg = "unable to merge package and system information";
669781SMoriah.Waterland@Sun.COM 
679781SMoriah.Waterland@Sun.COM 	if (a_zoneName == (char *)NULL) {
689781SMoriah.Waterland@Sun.COM 		echo(gettext("## Processing package information."));
699781SMoriah.Waterland@Sun.COM 	} else {
709781SMoriah.Waterland@Sun.COM 		echo(gettext("## Processing package information in zone <%s>."),
71*9869SCasper.Dik@Sun.COM 		    a_zoneName);
729781SMoriah.Waterland@Sun.COM 	}
739781SMoriah.Waterland@Sun.COM 
749781SMoriah.Waterland@Sun.COM 	/*
759781SMoriah.Waterland@Sun.COM 	 * The following instruction puts the client-relative basedir
769781SMoriah.Waterland@Sun.COM 	 * into the environment iff it's a relocatable package and
779781SMoriah.Waterland@Sun.COM 	 * we're installing to a client. Otherwise, it uses the regular
789781SMoriah.Waterland@Sun.COM 	 * basedir. The only reason for this is so that mappath() upon
799781SMoriah.Waterland@Sun.COM 	 * finding $BASEDIR in a path will properly resolve it to the
809781SMoriah.Waterland@Sun.COM 	 * client-relative path. This way eval_path() can properly
819781SMoriah.Waterland@Sun.COM 	 * construct the server-relative path.
829781SMoriah.Waterland@Sun.COM 	 */
839781SMoriah.Waterland@Sun.COM 	if (is_relocatable() && is_an_inst_root())
849781SMoriah.Waterland@Sun.COM 		putparam("BASEDIR", get_info_basedir());
859781SMoriah.Waterland@Sun.COM 
869781SMoriah.Waterland@Sun.COM 	/*
879781SMoriah.Waterland@Sun.COM 	 * read the pkgmap provided by this package into
889781SMoriah.Waterland@Sun.COM 	 * memory; map parameters specified in the pathname
899781SMoriah.Waterland@Sun.COM 	 * and sort in memory by pathname
909781SMoriah.Waterland@Sun.COM 	 */
919781SMoriah.Waterland@Sun.COM 
929781SMoriah.Waterland@Sun.COM 	vfpRewind(pkgmapVfp);		/* rewind input file */
939781SMoriah.Waterland@Sun.COM 
949781SMoriah.Waterland@Sun.COM 	*extlist = pkgobjmap(pkgmapVfp, 2, NULL);
959781SMoriah.Waterland@Sun.COM 
969781SMoriah.Waterland@Sun.COM 	if (*extlist == NULL) {
979781SMoriah.Waterland@Sun.COM 		progerr(gettext("unable to process pkgmap"));
989781SMoriah.Waterland@Sun.COM 		quit(99);
999781SMoriah.Waterland@Sun.COM 	}
1009781SMoriah.Waterland@Sun.COM 
1019781SMoriah.Waterland@Sun.COM 	/* Make all paths client-relative if necessary. */
1029781SMoriah.Waterland@Sun.COM 	if (is_an_inst_root()) {
1039781SMoriah.Waterland@Sun.COM 		(void) client_refer(*extlist);
1049781SMoriah.Waterland@Sun.COM 	}
1059781SMoriah.Waterland@Sun.COM 
1069781SMoriah.Waterland@Sun.COM 	if (a_zoneName == (char *)NULL) {
1079781SMoriah.Waterland@Sun.COM 		echo(gettext("## Processing system information."));
1089781SMoriah.Waterland@Sun.COM 	} else {
1099781SMoriah.Waterland@Sun.COM 		echo(gettext("## Processing system information in zone <%s>."),
110*9869SCasper.Dik@Sun.COM 		    a_zoneName);
1119781SMoriah.Waterland@Sun.COM 	}
1129781SMoriah.Waterland@Sun.COM 
1139781SMoriah.Waterland@Sun.COM 	/*
1149781SMoriah.Waterland@Sun.COM 	 * calculate the number of parts in this package
1159781SMoriah.Waterland@Sun.COM 	 * by locating the entry with the largest "volno"
1169781SMoriah.Waterland@Sun.COM 	 * associated with it
1179781SMoriah.Waterland@Sun.COM 	 */
1189781SMoriah.Waterland@Sun.COM 	nparts = 0;
1199781SMoriah.Waterland@Sun.COM 	if (is_depend_pkginfo_DB() == B_FALSE) {
1209781SMoriah.Waterland@Sun.COM 		for (i = 0; (*extlist)[i]; i++) {
1219781SMoriah.Waterland@Sun.COM 			n = (*extlist)[i]->cf_ent.volno;
1229781SMoriah.Waterland@Sun.COM 			if (n > nparts)
1239781SMoriah.Waterland@Sun.COM 				nparts = n;
1249781SMoriah.Waterland@Sun.COM 		}
1259781SMoriah.Waterland@Sun.COM 
1269781SMoriah.Waterland@Sun.COM 		vfpTruncate(tmpvfp);
1279781SMoriah.Waterland@Sun.COM 
128*9869SCasper.Dik@Sun.COM 		dbchg = pkgdbmerg(pkgserver, tmpvfp, *extlist);
1299781SMoriah.Waterland@Sun.COM 		if (dbchg < 0) {
1309781SMoriah.Waterland@Sun.COM 			progerr(gettext(db_mrg));
1319781SMoriah.Waterland@Sun.COM 			quit(99);
1329781SMoriah.Waterland@Sun.COM 		}
1339781SMoriah.Waterland@Sun.COM 	}
1349781SMoriah.Waterland@Sun.COM 
1359781SMoriah.Waterland@Sun.COM 	/* Restore the original BASEDIR. */
1369781SMoriah.Waterland@Sun.COM 	if (is_relocatable() && is_an_inst_root())
1379781SMoriah.Waterland@Sun.COM 		putparam("BASEDIR", get_basedir());
1389781SMoriah.Waterland@Sun.COM 
1399781SMoriah.Waterland@Sun.COM 	if (is_an_inst_root()) {
1409781SMoriah.Waterland@Sun.COM 		(void) server_refer(*extlist);
1419781SMoriah.Waterland@Sun.COM 	}
1429781SMoriah.Waterland@Sun.COM 
1439781SMoriah.Waterland@Sun.COM 	return (nparts);
1449781SMoriah.Waterland@Sun.COM }
1459781SMoriah.Waterland@Sun.COM 
1469781SMoriah.Waterland@Sun.COM static int
client_refer(struct cfextra ** ext)1479781SMoriah.Waterland@Sun.COM client_refer(struct cfextra **ext)
1489781SMoriah.Waterland@Sun.COM {
1499781SMoriah.Waterland@Sun.COM 	int count;
1509781SMoriah.Waterland@Sun.COM 
1519781SMoriah.Waterland@Sun.COM 	for (count = 0; ext[count] != (struct cfextra *)NULL; count++) {
1529781SMoriah.Waterland@Sun.COM 		ext[count]->cf_ent.path = ext[count]->client_path;
1539781SMoriah.Waterland@Sun.COM 		ext[count]->cf_ent.ainfo.local = ext[count]->client_local;
1549781SMoriah.Waterland@Sun.COM 	}
1559781SMoriah.Waterland@Sun.COM 
1569781SMoriah.Waterland@Sun.COM 	return (1);
1579781SMoriah.Waterland@Sun.COM }
1589781SMoriah.Waterland@Sun.COM 
1599781SMoriah.Waterland@Sun.COM static int
server_refer(struct cfextra ** ext)1609781SMoriah.Waterland@Sun.COM server_refer(struct cfextra **ext)
1619781SMoriah.Waterland@Sun.COM {
1629781SMoriah.Waterland@Sun.COM 	int count;
1639781SMoriah.Waterland@Sun.COM 
1649781SMoriah.Waterland@Sun.COM 	for (count = 0; ext[count] != (struct cfextra *)NULL; count++) {
1659781SMoriah.Waterland@Sun.COM 		ext[count]->cf_ent.path = ext[count]->server_path;
1669781SMoriah.Waterland@Sun.COM 		ext[count]->cf_ent.ainfo.local = ext[count]->server_local;
1679781SMoriah.Waterland@Sun.COM 	}
1689781SMoriah.Waterland@Sun.COM 
1699781SMoriah.Waterland@Sun.COM 	return (1);
1709781SMoriah.Waterland@Sun.COM }
171