1*9781SMoriah.Waterland@Sun.COM /*
2*9781SMoriah.Waterland@Sun.COM * CDDL HEADER START
3*9781SMoriah.Waterland@Sun.COM *
4*9781SMoriah.Waterland@Sun.COM * The contents of this file are subject to the terms of the
5*9781SMoriah.Waterland@Sun.COM * Common Development and Distribution License (the "License").
6*9781SMoriah.Waterland@Sun.COM * You may not use this file except in compliance with the License.
7*9781SMoriah.Waterland@Sun.COM *
8*9781SMoriah.Waterland@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*9781SMoriah.Waterland@Sun.COM * or http://www.opensolaris.org/os/licensing.
10*9781SMoriah.Waterland@Sun.COM * See the License for the specific language governing permissions
11*9781SMoriah.Waterland@Sun.COM * and limitations under the License.
12*9781SMoriah.Waterland@Sun.COM *
13*9781SMoriah.Waterland@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
14*9781SMoriah.Waterland@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*9781SMoriah.Waterland@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
16*9781SMoriah.Waterland@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
17*9781SMoriah.Waterland@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
18*9781SMoriah.Waterland@Sun.COM *
19*9781SMoriah.Waterland@Sun.COM * CDDL HEADER END
20*9781SMoriah.Waterland@Sun.COM */
21*9781SMoriah.Waterland@Sun.COM
22*9781SMoriah.Waterland@Sun.COM /*
23*9781SMoriah.Waterland@Sun.COM * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24*9781SMoriah.Waterland@Sun.COM * Use is subject to license terms.
25*9781SMoriah.Waterland@Sun.COM */
26*9781SMoriah.Waterland@Sun.COM
27*9781SMoriah.Waterland@Sun.COM
28*9781SMoriah.Waterland@Sun.COM #include <stdio.h>
29*9781SMoriah.Waterland@Sun.COM #include <stdlib.h>
30*9781SMoriah.Waterland@Sun.COM #include <string.h>
31*9781SMoriah.Waterland@Sun.COM #include <sys/types.h>
32*9781SMoriah.Waterland@Sun.COM #include <sys/wait.h>
33*9781SMoriah.Waterland@Sun.COM #include <sys/stat.h>
34*9781SMoriah.Waterland@Sun.COM #include <fcntl.h>
35*9781SMoriah.Waterland@Sun.COM #include <pkgstrct.h>
36*9781SMoriah.Waterland@Sun.COM #include <unistd.h>
37*9781SMoriah.Waterland@Sun.COM #include <pkglib.h>
38*9781SMoriah.Waterland@Sun.COM #include <libintl.h>
39*9781SMoriah.Waterland@Sun.COM #include "libadm.h"
40*9781SMoriah.Waterland@Sun.COM #include "libinst.h"
41*9781SMoriah.Waterland@Sun.COM #include "dryrun.h"
42*9781SMoriah.Waterland@Sun.COM
43*9781SMoriah.Waterland@Sun.COM #define HDR_FSUSAGE "#name remote_name writeable bfree bused ifree iused"
44*9781SMoriah.Waterland@Sun.COM
45*9781SMoriah.Waterland@Sun.COM #define ERR_NOCREAT "cannot create %s."
46*9781SMoriah.Waterland@Sun.COM #define ERR_NOOPEN "cannot open %s."
47*9781SMoriah.Waterland@Sun.COM #define ERR_NOWRITE "cannot write to %s."
48*9781SMoriah.Waterland@Sun.COM #define ERR_NOREAD "cannot read from %s."
49*9781SMoriah.Waterland@Sun.COM #define ERR_FSFAIL "cannot construct filesystem table entry."
50*9781SMoriah.Waterland@Sun.COM #define ERR_BADTYPE "cannot record %s dryrun from %s continuation file."
51*9781SMoriah.Waterland@Sun.COM #define ERR_NOCONT "cannot install from continue file due to error " \
52*9781SMoriah.Waterland@Sun.COM "stacking."
53*9781SMoriah.Waterland@Sun.COM
54*9781SMoriah.Waterland@Sun.COM #define ISUMASC_SUFFIX ".isum.asc"
55*9781SMoriah.Waterland@Sun.COM #define FSASC_SUFFIX ".fs.asc"
56*9781SMoriah.Waterland@Sun.COM #define IPOASC_SUFFIX ".ipo.asc"
57*9781SMoriah.Waterland@Sun.COM #define IBIN_SUFFIX ".inst.bin"
58*9781SMoriah.Waterland@Sun.COM
59*9781SMoriah.Waterland@Sun.COM #define MALCOUNT 5 /* package entries to allocate in a block */
60*9781SMoriah.Waterland@Sun.COM #define PKGNAMESIZE 32 /* package entries to allocate in a block */
61*9781SMoriah.Waterland@Sun.COM
62*9781SMoriah.Waterland@Sun.COM extern struct cfextra **extlist;
63*9781SMoriah.Waterland@Sun.COM extern char *pkginst;
64*9781SMoriah.Waterland@Sun.COM
65*9781SMoriah.Waterland@Sun.COM static struct cfextra **extptr;
66*9781SMoriah.Waterland@Sun.COM static int dryrun_mode = 0;
67*9781SMoriah.Waterland@Sun.COM static int continue_mode = 0;
68*9781SMoriah.Waterland@Sun.COM static int this_exitcode = 0;
69*9781SMoriah.Waterland@Sun.COM
70*9781SMoriah.Waterland@Sun.COM /* The dryrun and continuation filenames */
71*9781SMoriah.Waterland@Sun.COM static char *dryrun_sumasc;
72*9781SMoriah.Waterland@Sun.COM static char *dryrun_fsasc;
73*9781SMoriah.Waterland@Sun.COM static char *dryrun_poasc;
74*9781SMoriah.Waterland@Sun.COM static char *dryrun_bin;
75*9781SMoriah.Waterland@Sun.COM static char *continue_bin;
76*9781SMoriah.Waterland@Sun.COM
77*9781SMoriah.Waterland@Sun.COM /* These tell us if the actual files are initialized yet. */
78*9781SMoriah.Waterland@Sun.COM static int dryrun_initialized = 0;
79*9781SMoriah.Waterland@Sun.COM static int continue_initialized = 0;
80*9781SMoriah.Waterland@Sun.COM
81*9781SMoriah.Waterland@Sun.COM static int this_type; /* type of transaction from main.c */
82*9781SMoriah.Waterland@Sun.COM
83*9781SMoriah.Waterland@Sun.COM static int pkg_handle = -1;
84*9781SMoriah.Waterland@Sun.COM static int tot_pkgs;
85*9781SMoriah.Waterland@Sun.COM
86*9781SMoriah.Waterland@Sun.COM /* Their associated file pointers */
87*9781SMoriah.Waterland@Sun.COM static FILE *fp_dra;
88*9781SMoriah.Waterland@Sun.COM static int fd_drb;
89*9781SMoriah.Waterland@Sun.COM static int fd_cnb;
90*9781SMoriah.Waterland@Sun.COM
91*9781SMoriah.Waterland@Sun.COM struct dr_pkg_entry {
92*9781SMoriah.Waterland@Sun.COM char pkginst[PKGNAMESIZE + 2];
93*9781SMoriah.Waterland@Sun.COM struct dr_pkg_entry *next;
94*9781SMoriah.Waterland@Sun.COM };
95*9781SMoriah.Waterland@Sun.COM
96*9781SMoriah.Waterland@Sun.COM static struct drinfo {
97*9781SMoriah.Waterland@Sun.COM unsigned partial_set:1; /* 1 if a partial installation was detected. */
98*9781SMoriah.Waterland@Sun.COM unsigned partial:1; /* 1 if a partial installation was detected. */
99*9781SMoriah.Waterland@Sun.COM unsigned runlevel_set:1;
100*9781SMoriah.Waterland@Sun.COM unsigned runlevel:1; /* 1 if runlevel test returned an error. */
101*9781SMoriah.Waterland@Sun.COM unsigned pkgfiles_set:1;
102*9781SMoriah.Waterland@Sun.COM unsigned pkgfiles:1;
103*9781SMoriah.Waterland@Sun.COM unsigned depend_set:1;
104*9781SMoriah.Waterland@Sun.COM unsigned depend:1;
105*9781SMoriah.Waterland@Sun.COM unsigned space_set:1;
106*9781SMoriah.Waterland@Sun.COM unsigned space:1;
107*9781SMoriah.Waterland@Sun.COM unsigned conflict_set:1;
108*9781SMoriah.Waterland@Sun.COM unsigned conflict:1;
109*9781SMoriah.Waterland@Sun.COM unsigned setuid_set:1;
110*9781SMoriah.Waterland@Sun.COM unsigned setuid:1;
111*9781SMoriah.Waterland@Sun.COM unsigned priv_set:1;
112*9781SMoriah.Waterland@Sun.COM unsigned priv:1;
113*9781SMoriah.Waterland@Sun.COM unsigned pkgdirs_set:1;
114*9781SMoriah.Waterland@Sun.COM unsigned pkgdirs:1;
115*9781SMoriah.Waterland@Sun.COM unsigned reqexit_set:1;
116*9781SMoriah.Waterland@Sun.COM unsigned checkexit_set:1;
117*9781SMoriah.Waterland@Sun.COM
118*9781SMoriah.Waterland@Sun.COM int type; /* type of operation */
119*9781SMoriah.Waterland@Sun.COM int reqexit; /* request script exit code */
120*9781SMoriah.Waterland@Sun.COM int checkexit; /* checkinstall script exit code */
121*9781SMoriah.Waterland@Sun.COM int exitcode; /* overall program exit code. */
122*9781SMoriah.Waterland@Sun.COM
123*9781SMoriah.Waterland@Sun.COM struct dr_pkg_entry *packages; /* pointer to the list of packages */
124*9781SMoriah.Waterland@Sun.COM
125*9781SMoriah.Waterland@Sun.COM int total_ext_recs; /* total extlist entries */
126*9781SMoriah.Waterland@Sun.COM int total_fs_recs; /* total fs_tab entries */
127*9781SMoriah.Waterland@Sun.COM int total_pkgs; /* total number of dryrun packages */
128*9781SMoriah.Waterland@Sun.COM int do_not_continue; /* error stacking is likely */
129*9781SMoriah.Waterland@Sun.COM } dr_info;
130*9781SMoriah.Waterland@Sun.COM
131*9781SMoriah.Waterland@Sun.COM static char *exitmsg; /* the last meaningful message printed */
132*9781SMoriah.Waterland@Sun.COM
133*9781SMoriah.Waterland@Sun.COM /*
134*9781SMoriah.Waterland@Sun.COM * In the event that live continue (continue from a dryrun source only)
135*9781SMoriah.Waterland@Sun.COM * becomes a feature, it will be necessary to keep track of those events such
136*9781SMoriah.Waterland@Sun.COM * as multiply edited files and files dependent upon multiple class action
137*9781SMoriah.Waterland@Sun.COM * scripts that will lead to "tolerance stacking". Calling this function
138*9781SMoriah.Waterland@Sun.COM * states that we've lost the level of precision necessary for a live
139*9781SMoriah.Waterland@Sun.COM * continue.
140*9781SMoriah.Waterland@Sun.COM */
141*9781SMoriah.Waterland@Sun.COM void
set_continue_not_ok(void)142*9781SMoriah.Waterland@Sun.COM set_continue_not_ok(void)
143*9781SMoriah.Waterland@Sun.COM {
144*9781SMoriah.Waterland@Sun.COM dr_info.do_not_continue = 1;
145*9781SMoriah.Waterland@Sun.COM }
146*9781SMoriah.Waterland@Sun.COM
147*9781SMoriah.Waterland@Sun.COM int
continue_is_ok(void)148*9781SMoriah.Waterland@Sun.COM continue_is_ok(void)
149*9781SMoriah.Waterland@Sun.COM {
150*9781SMoriah.Waterland@Sun.COM return (!dr_info.do_not_continue);
151*9781SMoriah.Waterland@Sun.COM }
152*9781SMoriah.Waterland@Sun.COM
153*9781SMoriah.Waterland@Sun.COM static void
wr_OK(FILE * fp,char * parameter,int set,int value)154*9781SMoriah.Waterland@Sun.COM wr_OK(FILE *fp, char *parameter, int set, int value)
155*9781SMoriah.Waterland@Sun.COM {
156*9781SMoriah.Waterland@Sun.COM (void) fprintf(fp, "%s=%s\n", parameter,
157*9781SMoriah.Waterland@Sun.COM (set ? (value ? "OK" : "NOT_OK") : "NOT_TESTED"));
158*9781SMoriah.Waterland@Sun.COM }
159*9781SMoriah.Waterland@Sun.COM
160*9781SMoriah.Waterland@Sun.COM static void
add_pkg_to_list(char * pkgname)161*9781SMoriah.Waterland@Sun.COM add_pkg_to_list(char *pkgname)
162*9781SMoriah.Waterland@Sun.COM {
163*9781SMoriah.Waterland@Sun.COM struct dr_pkg_entry **pkg_entry;
164*9781SMoriah.Waterland@Sun.COM
165*9781SMoriah.Waterland@Sun.COM if (pkg_handle == -1) {
166*9781SMoriah.Waterland@Sun.COM if ((pkg_handle = bl_create(MALCOUNT,
167*9781SMoriah.Waterland@Sun.COM sizeof (struct dr_pkg_entry), "package dryrun")) == -1)
168*9781SMoriah.Waterland@Sun.COM return;
169*9781SMoriah.Waterland@Sun.COM }
170*9781SMoriah.Waterland@Sun.COM
171*9781SMoriah.Waterland@Sun.COM pkg_entry = &(dr_info.packages);
172*9781SMoriah.Waterland@Sun.COM
173*9781SMoriah.Waterland@Sun.COM while (*pkg_entry != NULL)
174*9781SMoriah.Waterland@Sun.COM pkg_entry = &((*pkg_entry)->next);
175*9781SMoriah.Waterland@Sun.COM
176*9781SMoriah.Waterland@Sun.COM /* LINTED pointer cast may result in improper alignment */
177*9781SMoriah.Waterland@Sun.COM *pkg_entry = (struct dr_pkg_entry *)bl_next_avail(pkg_handle);
178*9781SMoriah.Waterland@Sun.COM dr_info.total_pkgs++;
179*9781SMoriah.Waterland@Sun.COM
180*9781SMoriah.Waterland@Sun.COM (void) snprintf((*pkg_entry)->pkginst, PKGNAMESIZE, "%s%s",
181*9781SMoriah.Waterland@Sun.COM (pkgname ? pkgname : ""), ((this_exitcode == 0) ? "" : "-"));
182*9781SMoriah.Waterland@Sun.COM }
183*9781SMoriah.Waterland@Sun.COM
184*9781SMoriah.Waterland@Sun.COM static void
write_pkglist_ascii(void)185*9781SMoriah.Waterland@Sun.COM write_pkglist_ascii(void)
186*9781SMoriah.Waterland@Sun.COM {
187*9781SMoriah.Waterland@Sun.COM struct dr_pkg_entry *pkg_entry;
188*9781SMoriah.Waterland@Sun.COM
189*9781SMoriah.Waterland@Sun.COM (void) fprintf(fp_dra, "PKG_LIST=\"");
190*9781SMoriah.Waterland@Sun.COM
191*9781SMoriah.Waterland@Sun.COM pkg_entry = dr_info.packages;
192*9781SMoriah.Waterland@Sun.COM while (pkg_entry) {
193*9781SMoriah.Waterland@Sun.COM (void) fprintf(fp_dra, " %s", pkg_entry->pkginst);
194*9781SMoriah.Waterland@Sun.COM pkg_entry = pkg_entry->next;
195*9781SMoriah.Waterland@Sun.COM }
196*9781SMoriah.Waterland@Sun.COM
197*9781SMoriah.Waterland@Sun.COM (void) fprintf(fp_dra, "\"\n");
198*9781SMoriah.Waterland@Sun.COM }
199*9781SMoriah.Waterland@Sun.COM
200*9781SMoriah.Waterland@Sun.COM static int
write_string(int fd,char * string)201*9781SMoriah.Waterland@Sun.COM write_string(int fd, char *string)
202*9781SMoriah.Waterland@Sun.COM {
203*9781SMoriah.Waterland@Sun.COM int string_size;
204*9781SMoriah.Waterland@Sun.COM
205*9781SMoriah.Waterland@Sun.COM if (string)
206*9781SMoriah.Waterland@Sun.COM string_size = strlen(string) + 1;
207*9781SMoriah.Waterland@Sun.COM else
208*9781SMoriah.Waterland@Sun.COM string_size = 0;
209*9781SMoriah.Waterland@Sun.COM
210*9781SMoriah.Waterland@Sun.COM if (write(fd, &string_size, sizeof (string_size)) == -1) {
211*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOWRITE), dryrun_bin);
212*9781SMoriah.Waterland@Sun.COM return (0);
213*9781SMoriah.Waterland@Sun.COM }
214*9781SMoriah.Waterland@Sun.COM
215*9781SMoriah.Waterland@Sun.COM if (string_size > 0) {
216*9781SMoriah.Waterland@Sun.COM if (write(fd, string, string_size) == -1) {
217*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOWRITE), dryrun_bin);
218*9781SMoriah.Waterland@Sun.COM return (0);
219*9781SMoriah.Waterland@Sun.COM }
220*9781SMoriah.Waterland@Sun.COM }
221*9781SMoriah.Waterland@Sun.COM
222*9781SMoriah.Waterland@Sun.COM return (1);
223*9781SMoriah.Waterland@Sun.COM }
224*9781SMoriah.Waterland@Sun.COM
225*9781SMoriah.Waterland@Sun.COM static char *
read_string(int fd,char * buffer)226*9781SMoriah.Waterland@Sun.COM read_string(int fd, char *buffer)
227*9781SMoriah.Waterland@Sun.COM {
228*9781SMoriah.Waterland@Sun.COM size_t string_size;
229*9781SMoriah.Waterland@Sun.COM
230*9781SMoriah.Waterland@Sun.COM if (read(fd, &(string_size), sizeof (string_size)) == -1) {
231*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOREAD), continue_bin);
232*9781SMoriah.Waterland@Sun.COM return (NULL);
233*9781SMoriah.Waterland@Sun.COM }
234*9781SMoriah.Waterland@Sun.COM
235*9781SMoriah.Waterland@Sun.COM if (string_size != 0) {
236*9781SMoriah.Waterland@Sun.COM if (read(fd, buffer, string_size) == -1) {
237*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOREAD), continue_bin);
238*9781SMoriah.Waterland@Sun.COM return (NULL);
239*9781SMoriah.Waterland@Sun.COM }
240*9781SMoriah.Waterland@Sun.COM } else {
241*9781SMoriah.Waterland@Sun.COM return (NULL);
242*9781SMoriah.Waterland@Sun.COM }
243*9781SMoriah.Waterland@Sun.COM
244*9781SMoriah.Waterland@Sun.COM return (buffer);
245*9781SMoriah.Waterland@Sun.COM }
246*9781SMoriah.Waterland@Sun.COM
247*9781SMoriah.Waterland@Sun.COM static void
write_dryrun_ascii()248*9781SMoriah.Waterland@Sun.COM write_dryrun_ascii()
249*9781SMoriah.Waterland@Sun.COM {
250*9781SMoriah.Waterland@Sun.COM int n;
251*9781SMoriah.Waterland@Sun.COM char *fs_mntpt, *src_name;
252*9781SMoriah.Waterland@Sun.COM
253*9781SMoriah.Waterland@Sun.COM if ((fp_dra = fopen(dryrun_sumasc, "wb")) == NULL) {
254*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOOPEN), dryrun_sumasc);
255*9781SMoriah.Waterland@Sun.COM return;
256*9781SMoriah.Waterland@Sun.COM }
257*9781SMoriah.Waterland@Sun.COM
258*9781SMoriah.Waterland@Sun.COM (void) fprintf(fp_dra, "DR_TYPE=%s\n", (dr_info.type == REMOVE_TYPE ?
259*9781SMoriah.Waterland@Sun.COM "REMOVE" : "INSTALL"));
260*9781SMoriah.Waterland@Sun.COM
261*9781SMoriah.Waterland@Sun.COM (void) fprintf(fp_dra, "PKG_INSTALL_ROOT=%s\n", (((get_inst_root()) &&
262*9781SMoriah.Waterland@Sun.COM (strcmp(get_inst_root(), "/") != 0)) ?
263*9781SMoriah.Waterland@Sun.COM get_inst_root() : ""));
264*9781SMoriah.Waterland@Sun.COM
265*9781SMoriah.Waterland@Sun.COM write_pkglist_ascii();
266*9781SMoriah.Waterland@Sun.COM
267*9781SMoriah.Waterland@Sun.COM wr_OK(fp_dra, "CONTINUE", 1, !(dr_info.do_not_continue));
268*9781SMoriah.Waterland@Sun.COM
269*9781SMoriah.Waterland@Sun.COM wr_OK(fp_dra, "PARTIAL", dr_info.partial_set, dr_info.partial);
270*9781SMoriah.Waterland@Sun.COM
271*9781SMoriah.Waterland@Sun.COM wr_OK(fp_dra, "RUNLEVEL", dr_info.runlevel_set, dr_info.runlevel);
272*9781SMoriah.Waterland@Sun.COM
273*9781SMoriah.Waterland@Sun.COM (void) fprintf(fp_dra, "REQUESTEXITCODE=%d\n", dr_info.reqexit);
274*9781SMoriah.Waterland@Sun.COM
275*9781SMoriah.Waterland@Sun.COM (void) fprintf(fp_dra, "CHECKINSTALLEXITCODE=%d\n", dr_info.checkexit);
276*9781SMoriah.Waterland@Sun.COM
277*9781SMoriah.Waterland@Sun.COM wr_OK(fp_dra, "PKGFILES", dr_info.pkgfiles_set, dr_info.pkgfiles);
278*9781SMoriah.Waterland@Sun.COM
279*9781SMoriah.Waterland@Sun.COM wr_OK(fp_dra, "DEPEND", dr_info.depend_set, dr_info.depend);
280*9781SMoriah.Waterland@Sun.COM
281*9781SMoriah.Waterland@Sun.COM wr_OK(fp_dra, "SPACE", dr_info.space_set, dr_info.space);
282*9781SMoriah.Waterland@Sun.COM
283*9781SMoriah.Waterland@Sun.COM wr_OK(fp_dra, "CONFLICT", dr_info.conflict_set, dr_info.conflict);
284*9781SMoriah.Waterland@Sun.COM
285*9781SMoriah.Waterland@Sun.COM wr_OK(fp_dra, "SETUID", dr_info.setuid_set, dr_info.setuid);
286*9781SMoriah.Waterland@Sun.COM
287*9781SMoriah.Waterland@Sun.COM wr_OK(fp_dra, "PRIV", dr_info.priv_set, dr_info.priv);
288*9781SMoriah.Waterland@Sun.COM
289*9781SMoriah.Waterland@Sun.COM wr_OK(fp_dra, "PKGDIRS", dr_info.pkgdirs_set, dr_info.pkgdirs);
290*9781SMoriah.Waterland@Sun.COM
291*9781SMoriah.Waterland@Sun.COM (void) fprintf(fp_dra, "EXITCODE=%d\n", dr_info.exitcode);
292*9781SMoriah.Waterland@Sun.COM
293*9781SMoriah.Waterland@Sun.COM (void) fprintf(fp_dra, "ERRORMSG=%s\n", (exitmsg ? exitmsg : "NONE"));
294*9781SMoriah.Waterland@Sun.COM
295*9781SMoriah.Waterland@Sun.COM (void) fclose(fp_dra);
296*9781SMoriah.Waterland@Sun.COM
297*9781SMoriah.Waterland@Sun.COM if ((fp_dra = fopen(dryrun_fsasc, "wb")) == NULL) {
298*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOOPEN), dryrun_fsasc);
299*9781SMoriah.Waterland@Sun.COM return;
300*9781SMoriah.Waterland@Sun.COM }
301*9781SMoriah.Waterland@Sun.COM
302*9781SMoriah.Waterland@Sun.COM (void) fprintf(fp_dra, "%s\nFSUSAGE=\\\n\"\\\n", HDR_FSUSAGE);
303*9781SMoriah.Waterland@Sun.COM
304*9781SMoriah.Waterland@Sun.COM for (n = 0; fs_mntpt = get_fs_name_n(n); n++) {
305*9781SMoriah.Waterland@Sun.COM int bfree, bused;
306*9781SMoriah.Waterland@Sun.COM bfree = get_blk_free_n(n);
307*9781SMoriah.Waterland@Sun.COM bused = get_blk_used_n(n);
308*9781SMoriah.Waterland@Sun.COM
309*9781SMoriah.Waterland@Sun.COM if (bfree || bused) {
310*9781SMoriah.Waterland@Sun.COM (void) fprintf(fp_dra, "%s %s %s %d %d %lu %lu \\\n",
311*9781SMoriah.Waterland@Sun.COM fs_mntpt,
312*9781SMoriah.Waterland@Sun.COM ((src_name = get_source_name_n(n)) ?
313*9781SMoriah.Waterland@Sun.COM src_name : "none?"),
314*9781SMoriah.Waterland@Sun.COM (is_fs_writeable_n(n) ? "TRUE" : "FALSE"),
315*9781SMoriah.Waterland@Sun.COM bfree,
316*9781SMoriah.Waterland@Sun.COM bused,
317*9781SMoriah.Waterland@Sun.COM get_inode_free_n(n),
318*9781SMoriah.Waterland@Sun.COM get_inode_used_n(n));
319*9781SMoriah.Waterland@Sun.COM }
320*9781SMoriah.Waterland@Sun.COM }
321*9781SMoriah.Waterland@Sun.COM
322*9781SMoriah.Waterland@Sun.COM dr_info.total_fs_recs = n;
323*9781SMoriah.Waterland@Sun.COM
324*9781SMoriah.Waterland@Sun.COM (void) fprintf(fp_dra, "\"\n");
325*9781SMoriah.Waterland@Sun.COM
326*9781SMoriah.Waterland@Sun.COM (void) fclose(fp_dra);
327*9781SMoriah.Waterland@Sun.COM
328*9781SMoriah.Waterland@Sun.COM if ((fp_dra = fopen(dryrun_poasc, "wb")) == NULL) {
329*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOOPEN), dryrun_poasc);
330*9781SMoriah.Waterland@Sun.COM return;
331*9781SMoriah.Waterland@Sun.COM }
332*9781SMoriah.Waterland@Sun.COM
333*9781SMoriah.Waterland@Sun.COM dr_info.total_ext_recs = 0;
334*9781SMoriah.Waterland@Sun.COM
335*9781SMoriah.Waterland@Sun.COM (void) fprintf(fp_dra, "WOULD_INSTALL=\\\n\"\\\n");
336*9781SMoriah.Waterland@Sun.COM
337*9781SMoriah.Waterland@Sun.COM for (n = 0; extptr && extptr[n]; n++) {
338*9781SMoriah.Waterland@Sun.COM /*
339*9781SMoriah.Waterland@Sun.COM * Write it out if it's a successful change or it is from the
340*9781SMoriah.Waterland@Sun.COM * prior dryrun file (meaning it was a change back then).
341*9781SMoriah.Waterland@Sun.COM */
342*9781SMoriah.Waterland@Sun.COM if ((this_exitcode == 0 &&
343*9781SMoriah.Waterland@Sun.COM (extptr[n]->mstat.contchg || extptr[n]->mstat.attrchg)) ||
344*9781SMoriah.Waterland@Sun.COM extptr[n]->mstat.preloaded) {
345*9781SMoriah.Waterland@Sun.COM (void) fprintf(fp_dra, "%c %s \\\n",
346*9781SMoriah.Waterland@Sun.COM extptr[n]->cf_ent.ftype,
347*9781SMoriah.Waterland@Sun.COM extptr[n]->client_path);
348*9781SMoriah.Waterland@Sun.COM
349*9781SMoriah.Waterland@Sun.COM /* Count it, if it's going into the dryrun file. */
350*9781SMoriah.Waterland@Sun.COM if (extptr[n]->cf_ent.ftype != 'i')
351*9781SMoriah.Waterland@Sun.COM dr_info.total_ext_recs++;
352*9781SMoriah.Waterland@Sun.COM }
353*9781SMoriah.Waterland@Sun.COM }
354*9781SMoriah.Waterland@Sun.COM
355*9781SMoriah.Waterland@Sun.COM (void) fprintf(fp_dra, "\"\n");
356*9781SMoriah.Waterland@Sun.COM
357*9781SMoriah.Waterland@Sun.COM (void) fclose(fp_dra);
358*9781SMoriah.Waterland@Sun.COM }
359*9781SMoriah.Waterland@Sun.COM
360*9781SMoriah.Waterland@Sun.COM /*
361*9781SMoriah.Waterland@Sun.COM * This writes out a dryrun file.
362*9781SMoriah.Waterland@Sun.COM */
363*9781SMoriah.Waterland@Sun.COM static void
write_dryrun_bin()364*9781SMoriah.Waterland@Sun.COM write_dryrun_bin()
365*9781SMoriah.Waterland@Sun.COM {
366*9781SMoriah.Waterland@Sun.COM struct fstable *fs_entry;
367*9781SMoriah.Waterland@Sun.COM struct pinfo *pkginfo;
368*9781SMoriah.Waterland@Sun.COM struct dr_pkg_entry *pkg_entry;
369*9781SMoriah.Waterland@Sun.COM int n;
370*9781SMoriah.Waterland@Sun.COM int fsentry_size = sizeof (struct fstable);
371*9781SMoriah.Waterland@Sun.COM int extentry_size = sizeof (struct cfextra);
372*9781SMoriah.Waterland@Sun.COM int pinfoentry_size = sizeof (struct pinfo);
373*9781SMoriah.Waterland@Sun.COM
374*9781SMoriah.Waterland@Sun.COM if ((fd_drb = open(dryrun_bin,
375*9781SMoriah.Waterland@Sun.COM O_RDWR | O_APPEND | O_TRUNC)) == -1) {
376*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOOPEN), dryrun_bin);
377*9781SMoriah.Waterland@Sun.COM return;
378*9781SMoriah.Waterland@Sun.COM }
379*9781SMoriah.Waterland@Sun.COM
380*9781SMoriah.Waterland@Sun.COM /* Write the dryrun info table. */
381*9781SMoriah.Waterland@Sun.COM if (write(fd_drb, &dr_info, sizeof (struct drinfo)) == -1) {
382*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOWRITE), dryrun_bin);
383*9781SMoriah.Waterland@Sun.COM return;
384*9781SMoriah.Waterland@Sun.COM }
385*9781SMoriah.Waterland@Sun.COM
386*9781SMoriah.Waterland@Sun.COM /* Write out the package instance list. */
387*9781SMoriah.Waterland@Sun.COM pkg_entry = dr_info.packages;
388*9781SMoriah.Waterland@Sun.COM while (pkg_entry) {
389*9781SMoriah.Waterland@Sun.COM if (write(fd_drb, pkg_entry->pkginst, PKGNAMESIZE) == -1) {
390*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOWRITE), dryrun_bin);
391*9781SMoriah.Waterland@Sun.COM return;
392*9781SMoriah.Waterland@Sun.COM }
393*9781SMoriah.Waterland@Sun.COM pkg_entry = pkg_entry->next;
394*9781SMoriah.Waterland@Sun.COM }
395*9781SMoriah.Waterland@Sun.COM
396*9781SMoriah.Waterland@Sun.COM /* Write out the fstable records. */
397*9781SMoriah.Waterland@Sun.COM for (n = 0; n < dr_info.total_fs_recs; n++) {
398*9781SMoriah.Waterland@Sun.COM fs_entry = get_fs_entry(n);
399*9781SMoriah.Waterland@Sun.COM
400*9781SMoriah.Waterland@Sun.COM if (write(fd_drb, fs_entry, fsentry_size) == -1) {
401*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOWRITE), dryrun_bin);
402*9781SMoriah.Waterland@Sun.COM return;
403*9781SMoriah.Waterland@Sun.COM }
404*9781SMoriah.Waterland@Sun.COM
405*9781SMoriah.Waterland@Sun.COM if (!write_string(fd_drb, fs_entry->name))
406*9781SMoriah.Waterland@Sun.COM return;
407*9781SMoriah.Waterland@Sun.COM
408*9781SMoriah.Waterland@Sun.COM if (!write_string(fd_drb, fs_entry->fstype))
409*9781SMoriah.Waterland@Sun.COM return;
410*9781SMoriah.Waterland@Sun.COM
411*9781SMoriah.Waterland@Sun.COM if (!write_string(fd_drb, fs_entry->remote_name))
412*9781SMoriah.Waterland@Sun.COM return;
413*9781SMoriah.Waterland@Sun.COM }
414*9781SMoriah.Waterland@Sun.COM
415*9781SMoriah.Waterland@Sun.COM /* Write out the package objects and their attributes. */
416*9781SMoriah.Waterland@Sun.COM for (n = 0; extptr && extptr[n]; n++) {
417*9781SMoriah.Waterland@Sun.COM /* Don't save metafiles. */
418*9781SMoriah.Waterland@Sun.COM if (extptr[n]->cf_ent.ftype == 'i')
419*9781SMoriah.Waterland@Sun.COM continue;
420*9781SMoriah.Waterland@Sun.COM
421*9781SMoriah.Waterland@Sun.COM /*
422*9781SMoriah.Waterland@Sun.COM * If it's a new package object (not left over from the
423*9781SMoriah.Waterland@Sun.COM * continuation file) and it indicates no changes to the
424*9781SMoriah.Waterland@Sun.COM * system, skip it. Only files that will change the system
425*9781SMoriah.Waterland@Sun.COM * are stored.
426*9781SMoriah.Waterland@Sun.COM */
427*9781SMoriah.Waterland@Sun.COM if (extptr[n]->mstat.preloaded == 0 &&
428*9781SMoriah.Waterland@Sun.COM !(this_exitcode == 0 &&
429*9781SMoriah.Waterland@Sun.COM (extptr[n]->mstat.contchg || extptr[n]->mstat.attrchg)))
430*9781SMoriah.Waterland@Sun.COM continue;
431*9781SMoriah.Waterland@Sun.COM
432*9781SMoriah.Waterland@Sun.COM if (write(fd_drb, extptr[n], extentry_size) == -1) {
433*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOWRITE), dryrun_bin);
434*9781SMoriah.Waterland@Sun.COM return;
435*9781SMoriah.Waterland@Sun.COM }
436*9781SMoriah.Waterland@Sun.COM
437*9781SMoriah.Waterland@Sun.COM if (!write_string(fd_drb, extptr[n]->cf_ent.path))
438*9781SMoriah.Waterland@Sun.COM return;
439*9781SMoriah.Waterland@Sun.COM
440*9781SMoriah.Waterland@Sun.COM if (!write_string(fd_drb, extptr[n]->cf_ent.ainfo.local))
441*9781SMoriah.Waterland@Sun.COM return;
442*9781SMoriah.Waterland@Sun.COM
443*9781SMoriah.Waterland@Sun.COM extptr[n]->cf_ent.pinfo = eptstat(&(extptr[n]->cf_ent),
444*9781SMoriah.Waterland@Sun.COM pkginst, CONFIRM_CONT);
445*9781SMoriah.Waterland@Sun.COM
446*9781SMoriah.Waterland@Sun.COM /*
447*9781SMoriah.Waterland@Sun.COM * Now all of the entries about the various packages that own
448*9781SMoriah.Waterland@Sun.COM * this entry.
449*9781SMoriah.Waterland@Sun.COM */
450*9781SMoriah.Waterland@Sun.COM pkginfo = extptr[n]->cf_ent.pinfo;
451*9781SMoriah.Waterland@Sun.COM
452*9781SMoriah.Waterland@Sun.COM do {
453*9781SMoriah.Waterland@Sun.COM if (write(fd_drb, pkginfo,
454*9781SMoriah.Waterland@Sun.COM pinfoentry_size) == -1) {
455*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOWRITE), dryrun_bin);
456*9781SMoriah.Waterland@Sun.COM return;
457*9781SMoriah.Waterland@Sun.COM }
458*9781SMoriah.Waterland@Sun.COM pkginfo = pkginfo->next; /* May be several */
459*9781SMoriah.Waterland@Sun.COM } while (pkginfo);
460*9781SMoriah.Waterland@Sun.COM }
461*9781SMoriah.Waterland@Sun.COM
462*9781SMoriah.Waterland@Sun.COM (void) close(fd_drb);
463*9781SMoriah.Waterland@Sun.COM }
464*9781SMoriah.Waterland@Sun.COM
465*9781SMoriah.Waterland@Sun.COM static void
init_drinfo(void)466*9781SMoriah.Waterland@Sun.COM init_drinfo(void) {
467*9781SMoriah.Waterland@Sun.COM
468*9781SMoriah.Waterland@Sun.COM if (dr_info.partial != 0)
469*9781SMoriah.Waterland@Sun.COM dr_info.partial_set = 0;
470*9781SMoriah.Waterland@Sun.COM
471*9781SMoriah.Waterland@Sun.COM if (dr_info.runlevel != 0)
472*9781SMoriah.Waterland@Sun.COM dr_info.runlevel_set = 0;
473*9781SMoriah.Waterland@Sun.COM
474*9781SMoriah.Waterland@Sun.COM if (dr_info.pkgfiles != 0)
475*9781SMoriah.Waterland@Sun.COM dr_info.pkgfiles_set = 0;
476*9781SMoriah.Waterland@Sun.COM
477*9781SMoriah.Waterland@Sun.COM if (dr_info.depend != 0)
478*9781SMoriah.Waterland@Sun.COM dr_info.depend_set = 0;
479*9781SMoriah.Waterland@Sun.COM
480*9781SMoriah.Waterland@Sun.COM if (dr_info.space != 0)
481*9781SMoriah.Waterland@Sun.COM dr_info.space_set = 0;
482*9781SMoriah.Waterland@Sun.COM
483*9781SMoriah.Waterland@Sun.COM if (dr_info.conflict != 0)
484*9781SMoriah.Waterland@Sun.COM dr_info.conflict_set = 0;
485*9781SMoriah.Waterland@Sun.COM
486*9781SMoriah.Waterland@Sun.COM if (dr_info.setuid != 0)
487*9781SMoriah.Waterland@Sun.COM dr_info.setuid_set = 0;
488*9781SMoriah.Waterland@Sun.COM
489*9781SMoriah.Waterland@Sun.COM if (dr_info.priv != 0)
490*9781SMoriah.Waterland@Sun.COM dr_info.priv_set = 0;
491*9781SMoriah.Waterland@Sun.COM
492*9781SMoriah.Waterland@Sun.COM if (dr_info.pkgdirs != 0)
493*9781SMoriah.Waterland@Sun.COM dr_info.pkgdirs_set = 0;
494*9781SMoriah.Waterland@Sun.COM
495*9781SMoriah.Waterland@Sun.COM if (dr_info.reqexit == 0)
496*9781SMoriah.Waterland@Sun.COM dr_info.reqexit_set = 0;
497*9781SMoriah.Waterland@Sun.COM
498*9781SMoriah.Waterland@Sun.COM if (dr_info.checkexit == 0)
499*9781SMoriah.Waterland@Sun.COM dr_info.checkexit_set = 0;
500*9781SMoriah.Waterland@Sun.COM
501*9781SMoriah.Waterland@Sun.COM dr_info.packages = NULL;
502*9781SMoriah.Waterland@Sun.COM tot_pkgs = dr_info.total_pkgs;
503*9781SMoriah.Waterland@Sun.COM dr_info.total_pkgs = 0;
504*9781SMoriah.Waterland@Sun.COM }
505*9781SMoriah.Waterland@Sun.COM
506*9781SMoriah.Waterland@Sun.COM /*
507*9781SMoriah.Waterland@Sun.COM * This function reads in the various continuation file data in order to seed
508*9781SMoriah.Waterland@Sun.COM * the internal data structures.
509*9781SMoriah.Waterland@Sun.COM */
510*9781SMoriah.Waterland@Sun.COM static boolean_t
read_continue_bin(void)511*9781SMoriah.Waterland@Sun.COM read_continue_bin(void)
512*9781SMoriah.Waterland@Sun.COM {
513*9781SMoriah.Waterland@Sun.COM int n;
514*9781SMoriah.Waterland@Sun.COM int fsentry_size = sizeof (struct fstable);
515*9781SMoriah.Waterland@Sun.COM int extentry_size = sizeof (struct cfextra);
516*9781SMoriah.Waterland@Sun.COM int pinfoentry_size = sizeof (struct pinfo);
517*9781SMoriah.Waterland@Sun.COM
518*9781SMoriah.Waterland@Sun.COM pkgobjinit();
519*9781SMoriah.Waterland@Sun.COM if (!init_pkgobjspace())
520*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
521*9781SMoriah.Waterland@Sun.COM
522*9781SMoriah.Waterland@Sun.COM if ((fd_cnb = open(continue_bin, O_RDONLY)) == -1) {
523*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOOPEN), continue_bin);
524*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
525*9781SMoriah.Waterland@Sun.COM }
526*9781SMoriah.Waterland@Sun.COM
527*9781SMoriah.Waterland@Sun.COM /* Read the dryrun info structure. */
528*9781SMoriah.Waterland@Sun.COM if (read(fd_cnb, &dr_info, sizeof (struct drinfo)) == -1) {
529*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOREAD), continue_bin);
530*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
531*9781SMoriah.Waterland@Sun.COM }
532*9781SMoriah.Waterland@Sun.COM
533*9781SMoriah.Waterland@Sun.COM init_drinfo();
534*9781SMoriah.Waterland@Sun.COM
535*9781SMoriah.Waterland@Sun.COM if (this_type != dr_info.type) {
536*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_BADTYPE),
537*9781SMoriah.Waterland@Sun.COM (this_type == REMOVE_TYPE) ?
538*9781SMoriah.Waterland@Sun.COM "a remove" : "an install",
539*9781SMoriah.Waterland@Sun.COM (dr_info.type == REMOVE_TYPE) ?
540*9781SMoriah.Waterland@Sun.COM "a remove" : "an install");
541*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
542*9781SMoriah.Waterland@Sun.COM }
543*9781SMoriah.Waterland@Sun.COM
544*9781SMoriah.Waterland@Sun.COM /* Read in the dryrun package records. */
545*9781SMoriah.Waterland@Sun.COM for (n = 0; n < tot_pkgs; n++) {
546*9781SMoriah.Waterland@Sun.COM char pkg_name[PKGNAMESIZE];
547*9781SMoriah.Waterland@Sun.COM
548*9781SMoriah.Waterland@Sun.COM if (read(fd_cnb, &pkg_name, PKGNAMESIZE) == -1) {
549*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOREAD), continue_bin);
550*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
551*9781SMoriah.Waterland@Sun.COM }
552*9781SMoriah.Waterland@Sun.COM
553*9781SMoriah.Waterland@Sun.COM add_pkg_to_list(pkg_name);
554*9781SMoriah.Waterland@Sun.COM }
555*9781SMoriah.Waterland@Sun.COM
556*9781SMoriah.Waterland@Sun.COM /* Read in the fstable records. */
557*9781SMoriah.Waterland@Sun.COM for (n = 0; n < dr_info.total_fs_recs; n++) {
558*9781SMoriah.Waterland@Sun.COM struct fstable fs_entry;
559*9781SMoriah.Waterland@Sun.COM char name[PATH_MAX], remote_name[PATH_MAX];
560*9781SMoriah.Waterland@Sun.COM char fstype[200];
561*9781SMoriah.Waterland@Sun.COM
562*9781SMoriah.Waterland@Sun.COM if (read(fd_cnb, &fs_entry, fsentry_size) == -1) {
563*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOREAD), continue_bin);
564*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
565*9781SMoriah.Waterland@Sun.COM }
566*9781SMoriah.Waterland@Sun.COM
567*9781SMoriah.Waterland@Sun.COM if (read_string(fd_cnb, &name[0]) == NULL)
568*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
569*9781SMoriah.Waterland@Sun.COM
570*9781SMoriah.Waterland@Sun.COM if (read_string(fd_cnb, &fstype[0]) == NULL)
571*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
572*9781SMoriah.Waterland@Sun.COM
573*9781SMoriah.Waterland@Sun.COM if (read_string(fd_cnb, &remote_name[0]) == NULL)
574*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
575*9781SMoriah.Waterland@Sun.COM
576*9781SMoriah.Waterland@Sun.COM if (load_fsentry(&fs_entry, name, fstype, remote_name)) {
577*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_FSFAIL));
578*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
579*9781SMoriah.Waterland@Sun.COM }
580*9781SMoriah.Waterland@Sun.COM }
581*9781SMoriah.Waterland@Sun.COM
582*9781SMoriah.Waterland@Sun.COM /* Read in the package objects and their attributes. */
583*9781SMoriah.Waterland@Sun.COM for (n = 0; n < dr_info.total_ext_recs; n++) {
584*9781SMoriah.Waterland@Sun.COM struct cfextra ext_entry;
585*9781SMoriah.Waterland@Sun.COM struct pinfo pinfo_area, *pinfo_ptr;
586*9781SMoriah.Waterland@Sun.COM char path[PATH_MAX], local[PATH_MAX], *local_ptr;
587*9781SMoriah.Waterland@Sun.COM
588*9781SMoriah.Waterland@Sun.COM if (read(fd_cnb, &ext_entry, extentry_size) == -1) {
589*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOREAD), continue_bin);
590*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
591*9781SMoriah.Waterland@Sun.COM }
592*9781SMoriah.Waterland@Sun.COM
593*9781SMoriah.Waterland@Sun.COM /*
594*9781SMoriah.Waterland@Sun.COM * If the previous dryrun replaced a directory with a
595*9781SMoriah.Waterland@Sun.COM * non-directory and we're going into *another* dryrun, we're
596*9781SMoriah.Waterland@Sun.COM * stacking errors and continuation should not be permitted.
597*9781SMoriah.Waterland@Sun.COM */
598*9781SMoriah.Waterland@Sun.COM if (ext_entry.mstat.dir2nondir && dryrun_mode)
599*9781SMoriah.Waterland@Sun.COM dr_info.do_not_continue = 1;
600*9781SMoriah.Waterland@Sun.COM
601*9781SMoriah.Waterland@Sun.COM /*
602*9781SMoriah.Waterland@Sun.COM * Since we just read this from a continuation file; it is,
603*9781SMoriah.Waterland@Sun.COM * by definition, preloaded.
604*9781SMoriah.Waterland@Sun.COM */
605*9781SMoriah.Waterland@Sun.COM ext_entry.mstat.preloaded = 1;
606*9781SMoriah.Waterland@Sun.COM
607*9781SMoriah.Waterland@Sun.COM if (read_string(fd_cnb, &path[0]) == NULL)
608*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
609*9781SMoriah.Waterland@Sun.COM
610*9781SMoriah.Waterland@Sun.COM local_ptr = read_string(fd_cnb, &local[0]);
611*9781SMoriah.Waterland@Sun.COM
612*9781SMoriah.Waterland@Sun.COM ext_entry.cf_ent.pinfo = NULL;
613*9781SMoriah.Waterland@Sun.COM
614*9781SMoriah.Waterland@Sun.COM /*
615*9781SMoriah.Waterland@Sun.COM * Now all of the entries about the various packages that own
616*9781SMoriah.Waterland@Sun.COM * this entry.
617*9781SMoriah.Waterland@Sun.COM */
618*9781SMoriah.Waterland@Sun.COM do {
619*9781SMoriah.Waterland@Sun.COM if (read(fd_cnb, &pinfo_area, pinfoentry_size) == -1) {
620*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOREAD), continue_bin);
621*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
622*9781SMoriah.Waterland@Sun.COM
623*9781SMoriah.Waterland@Sun.COM }
624*9781SMoriah.Waterland@Sun.COM
625*9781SMoriah.Waterland@Sun.COM pinfo_ptr = eptstat(&(ext_entry.cf_ent),
626*9781SMoriah.Waterland@Sun.COM pinfo_area.pkg, CONFIRM_CONT);
627*9781SMoriah.Waterland@Sun.COM
628*9781SMoriah.Waterland@Sun.COM if (pinfo_ptr->next) {
629*9781SMoriah.Waterland@Sun.COM pinfo_ptr = pinfo_ptr->next;
630*9781SMoriah.Waterland@Sun.COM } else {
631*9781SMoriah.Waterland@Sun.COM pinfo_ptr = NULL;
632*9781SMoriah.Waterland@Sun.COM }
633*9781SMoriah.Waterland@Sun.COM
634*9781SMoriah.Waterland@Sun.COM } while (pinfo_ptr);
635*9781SMoriah.Waterland@Sun.COM
636*9781SMoriah.Waterland@Sun.COM seed_pkgobjmap(&ext_entry, path, local_ptr);
637*9781SMoriah.Waterland@Sun.COM }
638*9781SMoriah.Waterland@Sun.COM
639*9781SMoriah.Waterland@Sun.COM (void) close(fd_cnb);
640*9781SMoriah.Waterland@Sun.COM
641*9781SMoriah.Waterland@Sun.COM /*
642*9781SMoriah.Waterland@Sun.COM * Return as reading is done, so pkginstall doesn't
643*9781SMoriah.Waterland@Sun.COM * read the same info from the system.
644*9781SMoriah.Waterland@Sun.COM */
645*9781SMoriah.Waterland@Sun.COM
646*9781SMoriah.Waterland@Sun.COM return (B_TRUE);
647*9781SMoriah.Waterland@Sun.COM }
648*9781SMoriah.Waterland@Sun.COM
649*9781SMoriah.Waterland@Sun.COM int
in_dryrun_mode(void)650*9781SMoriah.Waterland@Sun.COM in_dryrun_mode(void)
651*9781SMoriah.Waterland@Sun.COM {
652*9781SMoriah.Waterland@Sun.COM return (dryrun_mode);
653*9781SMoriah.Waterland@Sun.COM }
654*9781SMoriah.Waterland@Sun.COM
655*9781SMoriah.Waterland@Sun.COM void
set_dryrun_mode(void)656*9781SMoriah.Waterland@Sun.COM set_dryrun_mode(void)
657*9781SMoriah.Waterland@Sun.COM {
658*9781SMoriah.Waterland@Sun.COM dryrun_mode = 1;
659*9781SMoriah.Waterland@Sun.COM }
660*9781SMoriah.Waterland@Sun.COM
661*9781SMoriah.Waterland@Sun.COM int
in_continue_mode(void)662*9781SMoriah.Waterland@Sun.COM in_continue_mode(void)
663*9781SMoriah.Waterland@Sun.COM {
664*9781SMoriah.Waterland@Sun.COM return (continue_mode);
665*9781SMoriah.Waterland@Sun.COM }
666*9781SMoriah.Waterland@Sun.COM
667*9781SMoriah.Waterland@Sun.COM void
set_continue_mode(void)668*9781SMoriah.Waterland@Sun.COM set_continue_mode(void)
669*9781SMoriah.Waterland@Sun.COM {
670*9781SMoriah.Waterland@Sun.COM continue_mode = 1;
671*9781SMoriah.Waterland@Sun.COM }
672*9781SMoriah.Waterland@Sun.COM
673*9781SMoriah.Waterland@Sun.COM /*
674*9781SMoriah.Waterland@Sun.COM * Initialize a dryrun file by assigning it a name and creating it
675*9781SMoriah.Waterland@Sun.COM * empty.
676*9781SMoriah.Waterland@Sun.COM */
677*9781SMoriah.Waterland@Sun.COM static int
init_drfile(char ** targ_ptr,char * path)678*9781SMoriah.Waterland@Sun.COM init_drfile(char **targ_ptr, char *path)
679*9781SMoriah.Waterland@Sun.COM {
680*9781SMoriah.Waterland@Sun.COM int n;
681*9781SMoriah.Waterland@Sun.COM char *targ_file;
682*9781SMoriah.Waterland@Sun.COM
683*9781SMoriah.Waterland@Sun.COM *targ_ptr = strdup(path);
684*9781SMoriah.Waterland@Sun.COM targ_file = *targ_ptr;
685*9781SMoriah.Waterland@Sun.COM
686*9781SMoriah.Waterland@Sun.COM if (access(targ_file, W_OK) == 0) {
687*9781SMoriah.Waterland@Sun.COM (void) unlink(targ_file);
688*9781SMoriah.Waterland@Sun.COM }
689*9781SMoriah.Waterland@Sun.COM
690*9781SMoriah.Waterland@Sun.COM n = open(targ_file, O_WRONLY|O_CREAT|O_TRUNC|O_EXCL, 0644);
691*9781SMoriah.Waterland@Sun.COM if (n < 0) {
692*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOCREAT), targ_file);
693*9781SMoriah.Waterland@Sun.COM return (0);
694*9781SMoriah.Waterland@Sun.COM } else {
695*9781SMoriah.Waterland@Sun.COM (void) close(n);
696*9781SMoriah.Waterland@Sun.COM }
697*9781SMoriah.Waterland@Sun.COM
698*9781SMoriah.Waterland@Sun.COM return (1);
699*9781SMoriah.Waterland@Sun.COM }
700*9781SMoriah.Waterland@Sun.COM
701*9781SMoriah.Waterland@Sun.COM /*
702*9781SMoriah.Waterland@Sun.COM * Initialize all required dryrun files and see that the target directory is
703*9781SMoriah.Waterland@Sun.COM * present. If all goes well, we're in dryrun mode. If it doesn't, we're not.
704*9781SMoriah.Waterland@Sun.COM */
705*9781SMoriah.Waterland@Sun.COM void
init_dryrunfile(char * dr_dir)706*9781SMoriah.Waterland@Sun.COM init_dryrunfile(char *dr_dir)
707*9781SMoriah.Waterland@Sun.COM {
708*9781SMoriah.Waterland@Sun.COM char temp_path[PATH_MAX];
709*9781SMoriah.Waterland@Sun.COM char *dot_pos = (temp_path+strlen(dr_dir)+7);
710*9781SMoriah.Waterland@Sun.COM
711*9781SMoriah.Waterland@Sun.COM /* First create or confirm the directory. */
712*9781SMoriah.Waterland@Sun.COM if (isdir(dr_dir) != 0) {
713*9781SMoriah.Waterland@Sun.COM (void) mkpath(dr_dir);
714*9781SMoriah.Waterland@Sun.COM }
715*9781SMoriah.Waterland@Sun.COM
716*9781SMoriah.Waterland@Sun.COM (void) snprintf(temp_path, sizeof (temp_path), "%s/dryrun", dr_dir);
717*9781SMoriah.Waterland@Sun.COM
718*9781SMoriah.Waterland@Sun.COM (void) strcpy(dot_pos, ISUMASC_SUFFIX);
719*9781SMoriah.Waterland@Sun.COM
720*9781SMoriah.Waterland@Sun.COM if (!init_drfile(&dryrun_sumasc, temp_path))
721*9781SMoriah.Waterland@Sun.COM return;
722*9781SMoriah.Waterland@Sun.COM
723*9781SMoriah.Waterland@Sun.COM (void) strcpy(dot_pos, FSASC_SUFFIX);
724*9781SMoriah.Waterland@Sun.COM
725*9781SMoriah.Waterland@Sun.COM if (!init_drfile(&dryrun_fsasc, temp_path))
726*9781SMoriah.Waterland@Sun.COM return;
727*9781SMoriah.Waterland@Sun.COM
728*9781SMoriah.Waterland@Sun.COM (void) strcpy(dot_pos, IPOASC_SUFFIX);
729*9781SMoriah.Waterland@Sun.COM
730*9781SMoriah.Waterland@Sun.COM if (!init_drfile(&dryrun_poasc, temp_path))
731*9781SMoriah.Waterland@Sun.COM return;
732*9781SMoriah.Waterland@Sun.COM
733*9781SMoriah.Waterland@Sun.COM (void) strcpy(dot_pos, IBIN_SUFFIX);
734*9781SMoriah.Waterland@Sun.COM
735*9781SMoriah.Waterland@Sun.COM if (!init_drfile(&dryrun_bin, temp_path))
736*9781SMoriah.Waterland@Sun.COM return;
737*9781SMoriah.Waterland@Sun.COM
738*9781SMoriah.Waterland@Sun.COM dryrun_initialized = 1;
739*9781SMoriah.Waterland@Sun.COM }
740*9781SMoriah.Waterland@Sun.COM
741*9781SMoriah.Waterland@Sun.COM void
init_contfile(char * cn_dir)742*9781SMoriah.Waterland@Sun.COM init_contfile(char *cn_dir)
743*9781SMoriah.Waterland@Sun.COM {
744*9781SMoriah.Waterland@Sun.COM char temp_path[PATH_MAX];
745*9781SMoriah.Waterland@Sun.COM
746*9781SMoriah.Waterland@Sun.COM /* First confirm the directory. */
747*9781SMoriah.Waterland@Sun.COM if (isdir(cn_dir) != 0)
748*9781SMoriah.Waterland@Sun.COM return; /* no continuation directory */
749*9781SMoriah.Waterland@Sun.COM
750*9781SMoriah.Waterland@Sun.COM (void) snprintf(temp_path, sizeof (temp_path),
751*9781SMoriah.Waterland@Sun.COM "%s/dryrun%s", cn_dir, IBIN_SUFFIX);
752*9781SMoriah.Waterland@Sun.COM continue_bin = strdup(temp_path);
753*9781SMoriah.Waterland@Sun.COM
754*9781SMoriah.Waterland@Sun.COM if (access(continue_bin, W_OK) != 0) {
755*9781SMoriah.Waterland@Sun.COM free(continue_bin);
756*9781SMoriah.Waterland@Sun.COM return;
757*9781SMoriah.Waterland@Sun.COM }
758*9781SMoriah.Waterland@Sun.COM
759*9781SMoriah.Waterland@Sun.COM continue_initialized = 1;
760*9781SMoriah.Waterland@Sun.COM }
761*9781SMoriah.Waterland@Sun.COM
762*9781SMoriah.Waterland@Sun.COM void
set_dr_exitmsg(char * value)763*9781SMoriah.Waterland@Sun.COM set_dr_exitmsg(char *value)
764*9781SMoriah.Waterland@Sun.COM {
765*9781SMoriah.Waterland@Sun.COM exitmsg = value;
766*9781SMoriah.Waterland@Sun.COM }
767*9781SMoriah.Waterland@Sun.COM
768*9781SMoriah.Waterland@Sun.COM void
set_dr_info(int type,int value)769*9781SMoriah.Waterland@Sun.COM set_dr_info(int type, int value)
770*9781SMoriah.Waterland@Sun.COM {
771*9781SMoriah.Waterland@Sun.COM switch (type) {
772*9781SMoriah.Waterland@Sun.COM case PARTIAL:
773*9781SMoriah.Waterland@Sun.COM if (dr_info.partial_set == 0) {
774*9781SMoriah.Waterland@Sun.COM dr_info.partial_set = 1;
775*9781SMoriah.Waterland@Sun.COM dr_info.partial = (value ? 1 : 0);
776*9781SMoriah.Waterland@Sun.COM }
777*9781SMoriah.Waterland@Sun.COM break;
778*9781SMoriah.Waterland@Sun.COM
779*9781SMoriah.Waterland@Sun.COM case RUNLEVEL:
780*9781SMoriah.Waterland@Sun.COM if (dr_info.runlevel_set == 0) {
781*9781SMoriah.Waterland@Sun.COM dr_info.runlevel_set = 1;
782*9781SMoriah.Waterland@Sun.COM dr_info.runlevel = (value ? 1 : 0);
783*9781SMoriah.Waterland@Sun.COM }
784*9781SMoriah.Waterland@Sun.COM break;
785*9781SMoriah.Waterland@Sun.COM
786*9781SMoriah.Waterland@Sun.COM case PKGFILES:
787*9781SMoriah.Waterland@Sun.COM if (dr_info.pkgfiles_set == 0) {
788*9781SMoriah.Waterland@Sun.COM dr_info.pkgfiles_set = 1;
789*9781SMoriah.Waterland@Sun.COM dr_info.pkgfiles = (value ? 1 : 0);
790*9781SMoriah.Waterland@Sun.COM }
791*9781SMoriah.Waterland@Sun.COM break;
792*9781SMoriah.Waterland@Sun.COM
793*9781SMoriah.Waterland@Sun.COM case DEPEND:
794*9781SMoriah.Waterland@Sun.COM if (dr_info.depend_set == 0) {
795*9781SMoriah.Waterland@Sun.COM dr_info.depend_set = 1;
796*9781SMoriah.Waterland@Sun.COM dr_info.depend = (value ? 1 : 0);
797*9781SMoriah.Waterland@Sun.COM }
798*9781SMoriah.Waterland@Sun.COM break;
799*9781SMoriah.Waterland@Sun.COM
800*9781SMoriah.Waterland@Sun.COM case SPACE:
801*9781SMoriah.Waterland@Sun.COM if (dr_info.space_set == 0) {
802*9781SMoriah.Waterland@Sun.COM dr_info.space_set = 1;
803*9781SMoriah.Waterland@Sun.COM dr_info.space = (value ? 1 : 0);
804*9781SMoriah.Waterland@Sun.COM }
805*9781SMoriah.Waterland@Sun.COM break;
806*9781SMoriah.Waterland@Sun.COM
807*9781SMoriah.Waterland@Sun.COM case CONFLICT:
808*9781SMoriah.Waterland@Sun.COM if (dr_info.conflict_set == 0) {
809*9781SMoriah.Waterland@Sun.COM dr_info.conflict_set = 1;
810*9781SMoriah.Waterland@Sun.COM dr_info.conflict = (value ? 1 : 0);
811*9781SMoriah.Waterland@Sun.COM }
812*9781SMoriah.Waterland@Sun.COM break;
813*9781SMoriah.Waterland@Sun.COM
814*9781SMoriah.Waterland@Sun.COM case SETUID:
815*9781SMoriah.Waterland@Sun.COM if (dr_info.setuid_set == 0) {
816*9781SMoriah.Waterland@Sun.COM dr_info.setuid_set = 1;
817*9781SMoriah.Waterland@Sun.COM dr_info.setuid = (value ? 1 : 0);
818*9781SMoriah.Waterland@Sun.COM }
819*9781SMoriah.Waterland@Sun.COM break;
820*9781SMoriah.Waterland@Sun.COM
821*9781SMoriah.Waterland@Sun.COM case PRIV:
822*9781SMoriah.Waterland@Sun.COM if (dr_info.priv_set == 0) {
823*9781SMoriah.Waterland@Sun.COM dr_info.priv_set = 1;
824*9781SMoriah.Waterland@Sun.COM dr_info.priv = (value ? 1 : 0);
825*9781SMoriah.Waterland@Sun.COM }
826*9781SMoriah.Waterland@Sun.COM
827*9781SMoriah.Waterland@Sun.COM break;
828*9781SMoriah.Waterland@Sun.COM
829*9781SMoriah.Waterland@Sun.COM case PKGDIRS:
830*9781SMoriah.Waterland@Sun.COM if (dr_info.pkgdirs_set == 0) {
831*9781SMoriah.Waterland@Sun.COM dr_info.pkgdirs_set = 1;
832*9781SMoriah.Waterland@Sun.COM dr_info.pkgdirs = (value ? 1 : 0);
833*9781SMoriah.Waterland@Sun.COM }
834*9781SMoriah.Waterland@Sun.COM
835*9781SMoriah.Waterland@Sun.COM break;
836*9781SMoriah.Waterland@Sun.COM
837*9781SMoriah.Waterland@Sun.COM case REQUESTEXITCODE:
838*9781SMoriah.Waterland@Sun.COM if (dr_info.reqexit_set == 0) {
839*9781SMoriah.Waterland@Sun.COM dr_info.reqexit_set = 1;
840*9781SMoriah.Waterland@Sun.COM dr_info.reqexit = value;
841*9781SMoriah.Waterland@Sun.COM }
842*9781SMoriah.Waterland@Sun.COM
843*9781SMoriah.Waterland@Sun.COM break;
844*9781SMoriah.Waterland@Sun.COM
845*9781SMoriah.Waterland@Sun.COM case CHECKEXITCODE:
846*9781SMoriah.Waterland@Sun.COM if (dr_info.checkexit_set == 0) {
847*9781SMoriah.Waterland@Sun.COM dr_info.checkexit_set = 1;
848*9781SMoriah.Waterland@Sun.COM dr_info.checkexit = value;
849*9781SMoriah.Waterland@Sun.COM }
850*9781SMoriah.Waterland@Sun.COM
851*9781SMoriah.Waterland@Sun.COM break;
852*9781SMoriah.Waterland@Sun.COM
853*9781SMoriah.Waterland@Sun.COM case EXITCODE:
854*9781SMoriah.Waterland@Sun.COM if (dr_info.exitcode == 0) {
855*9781SMoriah.Waterland@Sun.COM dr_info.exitcode = value;
856*9781SMoriah.Waterland@Sun.COM }
857*9781SMoriah.Waterland@Sun.COM
858*9781SMoriah.Waterland@Sun.COM this_exitcode = value;
859*9781SMoriah.Waterland@Sun.COM
860*9781SMoriah.Waterland@Sun.COM break;
861*9781SMoriah.Waterland@Sun.COM
862*9781SMoriah.Waterland@Sun.COM /* default to install if the value is kookie. */
863*9781SMoriah.Waterland@Sun.COM case DR_TYPE:
864*9781SMoriah.Waterland@Sun.COM if (value == REMOVE_TYPE)
865*9781SMoriah.Waterland@Sun.COM this_type = REMOVE_TYPE;
866*9781SMoriah.Waterland@Sun.COM else
867*9781SMoriah.Waterland@Sun.COM this_type = INSTALL_TYPE;
868*9781SMoriah.Waterland@Sun.COM
869*9781SMoriah.Waterland@Sun.COM break;
870*9781SMoriah.Waterland@Sun.COM }
871*9781SMoriah.Waterland@Sun.COM }
872*9781SMoriah.Waterland@Sun.COM
873*9781SMoriah.Waterland@Sun.COM void
write_dryrun_file(struct cfextra ** extlist)874*9781SMoriah.Waterland@Sun.COM write_dryrun_file(struct cfextra **extlist)
875*9781SMoriah.Waterland@Sun.COM {
876*9781SMoriah.Waterland@Sun.COM extptr = extlist;
877*9781SMoriah.Waterland@Sun.COM
878*9781SMoriah.Waterland@Sun.COM if (dryrun_initialized) {
879*9781SMoriah.Waterland@Sun.COM dr_info.type = this_type;
880*9781SMoriah.Waterland@Sun.COM
881*9781SMoriah.Waterland@Sun.COM add_pkg_to_list(pkginst);
882*9781SMoriah.Waterland@Sun.COM write_dryrun_ascii();
883*9781SMoriah.Waterland@Sun.COM write_dryrun_bin();
884*9781SMoriah.Waterland@Sun.COM
885*9781SMoriah.Waterland@Sun.COM if (dryrun_mode) {
886*9781SMoriah.Waterland@Sun.COM free(dryrun_sumasc);
887*9781SMoriah.Waterland@Sun.COM free(dryrun_fsasc);
888*9781SMoriah.Waterland@Sun.COM free(dryrun_poasc);
889*9781SMoriah.Waterland@Sun.COM free(dryrun_bin);
890*9781SMoriah.Waterland@Sun.COM }
891*9781SMoriah.Waterland@Sun.COM }
892*9781SMoriah.Waterland@Sun.COM }
893*9781SMoriah.Waterland@Sun.COM
894*9781SMoriah.Waterland@Sun.COM /*
895*9781SMoriah.Waterland@Sun.COM * Name: read_continuation
896*9781SMoriah.Waterland@Sun.COM * Description: If continuation is initialised, reads the
897*9781SMoriah.Waterland@Sun.COM * continuation binary file. The path for the
898*9781SMoriah.Waterland@Sun.COM * same is freed, if set, as this is the last
899*9781SMoriah.Waterland@Sun.COM * chance to do so.
900*9781SMoriah.Waterland@Sun.COM * Sets: Error condition, through the pointer passed
901*9781SMoriah.Waterland@Sun.COM * if read failed.
902*9781SMoriah.Waterland@Sun.COM * Returns: B_TRUE - if the continuation binary file
903*9781SMoriah.Waterland@Sun.COM * from previous dryrun is read successfully.
904*9781SMoriah.Waterland@Sun.COM * B_FALSE - if either continuation is not initialised
905*9781SMoriah.Waterland@Sun.COM * or read was not successful.
906*9781SMoriah.Waterland@Sun.COM */
907*9781SMoriah.Waterland@Sun.COM boolean_t
read_continuation(int * error)908*9781SMoriah.Waterland@Sun.COM read_continuation(int *error)
909*9781SMoriah.Waterland@Sun.COM {
910*9781SMoriah.Waterland@Sun.COM boolean_t ret = B_FALSE;
911*9781SMoriah.Waterland@Sun.COM *error = 0;
912*9781SMoriah.Waterland@Sun.COM if (continue_initialized) {
913*9781SMoriah.Waterland@Sun.COM if (!read_continue_bin()) {
914*9781SMoriah.Waterland@Sun.COM continue_mode = 0;
915*9781SMoriah.Waterland@Sun.COM free(continue_bin);
916*9781SMoriah.Waterland@Sun.COM *error = -1;
917*9781SMoriah.Waterland@Sun.COM return (ret);
918*9781SMoriah.Waterland@Sun.COM }
919*9781SMoriah.Waterland@Sun.COM
920*9781SMoriah.Waterland@Sun.COM if (continue_mode) {
921*9781SMoriah.Waterland@Sun.COM free(continue_bin);
922*9781SMoriah.Waterland@Sun.COM }
923*9781SMoriah.Waterland@Sun.COM ret = B_TRUE;
924*9781SMoriah.Waterland@Sun.COM }
925*9781SMoriah.Waterland@Sun.COM return (ret);
926*9781SMoriah.Waterland@Sun.COM }
927