xref: /illumos-gate/usr/src/cmd/svr4pkg/pkginstall/sortmap.c (revision 7d1e83948cb684521e72cab96020be241508f449)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29 
30 
31 /*
32  * This module constructs a list of entries from the pkgmap associated
33  * with this package. When finished, this list is sorted in alphabetical
34  * order and an accompanying structure list, mergstat, provides
35  * information about how these new files merge with existing files
36  * already on the system.
37  */
38 
39 #include <stdio.h>
40 #include <string.h>
41 #include <limits.h>
42 #include <stdlib.h>
43 #include <unistd.h>
44 #include <sys/types.h>
45 #include <pkgstrct.h>
46 #include <pkglocs.h>
47 #include <locale.h>
48 #include <libintl.h>
49 #include <install.h>
50 #include <pkglib.h>
51 #include <libadm.h>
52 #include <libinst.h>
53 
54 /* libinst/ocfile.c */
55 extern int	dbchg;
56 
57 static int	client_refer(struct cfextra **ext);
58 static int	server_refer(struct cfextra **ext);
59 
60 int
61 sortmap(struct cfextra ***extlist, VFP_T *pkgmapVfp,
62     PKGserver pkgserver, VFP_T *tmpvfp, char *a_zoneName)
63 {
64 	int	i, n, nparts;
65 	char *db_mrg = "unable to merge package and system information";
66 
67 	if (a_zoneName == (char *)NULL) {
68 		echo(gettext("## Processing package information."));
69 	} else {
70 		echo(gettext("## Processing package information in zone <%s>."),
71 		    a_zoneName);
72 	}
73 
74 	/*
75 	 * The following instruction puts the client-relative basedir
76 	 * into the environment iff it's a relocatable package and
77 	 * we're installing to a client. Otherwise, it uses the regular
78 	 * basedir. The only reason for this is so that mappath() upon
79 	 * finding $BASEDIR in a path will properly resolve it to the
80 	 * client-relative path. This way eval_path() can properly
81 	 * construct the server-relative path.
82 	 */
83 	if (is_relocatable() && is_an_inst_root())
84 		putparam("BASEDIR", get_info_basedir());
85 
86 	/*
87 	 * read the pkgmap provided by this package into
88 	 * memory; map parameters specified in the pathname
89 	 * and sort in memory by pathname
90 	 */
91 
92 	vfpRewind(pkgmapVfp);		/* rewind input file */
93 
94 	*extlist = pkgobjmap(pkgmapVfp, 2, NULL);
95 
96 	if (*extlist == NULL) {
97 		progerr(gettext("unable to process pkgmap"));
98 		quit(99);
99 	}
100 
101 	/* Make all paths client-relative if necessary. */
102 	if (is_an_inst_root()) {
103 		(void) client_refer(*extlist);
104 	}
105 
106 	if (a_zoneName == (char *)NULL) {
107 		echo(gettext("## Processing system information."));
108 	} else {
109 		echo(gettext("## Processing system information in zone <%s>."),
110 		    a_zoneName);
111 	}
112 
113 	/*
114 	 * calculate the number of parts in this package
115 	 * by locating the entry with the largest "volno"
116 	 * associated with it
117 	 */
118 	nparts = 0;
119 	if (is_depend_pkginfo_DB() == B_FALSE) {
120 		for (i = 0; (*extlist)[i]; i++) {
121 			n = (*extlist)[i]->cf_ent.volno;
122 			if (n > nparts)
123 				nparts = n;
124 		}
125 
126 		vfpTruncate(tmpvfp);
127 
128 		dbchg = pkgdbmerg(pkgserver, tmpvfp, *extlist);
129 		if (dbchg < 0) {
130 			progerr(gettext(db_mrg));
131 			quit(99);
132 		}
133 	}
134 
135 	/* Restore the original BASEDIR. */
136 	if (is_relocatable() && is_an_inst_root())
137 		putparam("BASEDIR", get_basedir());
138 
139 	if (is_an_inst_root()) {
140 		(void) server_refer(*extlist);
141 	}
142 
143 	return (nparts);
144 }
145 
146 static int
147 client_refer(struct cfextra **ext)
148 {
149 	int count;
150 
151 	for (count = 0; ext[count] != (struct cfextra *)NULL; count++) {
152 		ext[count]->cf_ent.path = ext[count]->client_path;
153 		ext[count]->cf_ent.ainfo.local = ext[count]->client_local;
154 	}
155 
156 	return (1);
157 }
158 
159 static int
160 server_refer(struct cfextra **ext)
161 {
162 	int count;
163 
164 	for (count = 0; ext[count] != (struct cfextra *)NULL; count++) {
165 		ext[count]->cf_ent.path = ext[count]->server_path;
166 		ext[count]->cf_ent.ainfo.local = ext[count]->server_local;
167 	}
168 
169 	return (1);
170 }
171