1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <time.h>
#include <wait.h>
#include <stdlib.h>
#include <unistd.h>
#include <ulimit.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <assert.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
#include <dirent.h>
#include <string.h>
#include <signal.h>
#include <locale.h>
#include <libintl.h>
#include <pkgstrct.h>
#include <pkginfo.h>
#include <pkgdev.h>
#include <pkglocs.h>
#include <pwd.h>
#include <pkglib.h>
#include <libinst.h>
#include <libadm.h>
#include <messages.h>
/*
* *****************************************************************************
* global external (public) functions
* *****************************************************************************
*/
/*
* open package datastream
* Arguments: a_argc - (int) - [RO, *RO]
* - number of arguments available in a_argv
* a_argv - (char **) - [RO, *RO]
* - arguments representing package names to add
* a_spoolDir - (char *) - [RO, *RO]
* - directory to write the package (spool) into
* - if == (char *)NULL then install the packages
* - if != (char *)NULL then write packages into directory
* a_device - (char *) - [RO, *RO]
* - device to read packages from when spooling
* - ignored if a_spoolDir == (char *)NULL
* r_repeat - (int *) - [RO, *RW]
* - set == 0 if no further package names in argc/argv
* - set != 0 IF there are package names in argc/argv
* - if == (int *)NULL - not set
* r_idsName - (char **) - [RW, *RW]
* - set to the name of package input data stream device
* - if == (char *)NULL - no input data stream; that is,
* -- the packages are in a directory and not in a stream
* - if != (char *)NULL - this is the device/file that
* -- is the datastream that contains the packages to add
* a_pkgdev - (struct pkgdev *) - [RO, *RW]
* - pkgdev structure containing package device to open
* Returns: B_TRUE - datastream opened successfully
* B_FALSE - datastream failed to open
*/
boolean_t
open_package_datastream(int a_argc, char **a_argv, char *a_spoolDir,
char *a_device, int *r_repeat, char **r_idsName, char *a_tmpdir,
struct pkgdev *a_pkgdev, int a_optind)
{
int n;
/* entry assertions */
assert(a_argv != (char **)NULL);
assert(r_idsName != (char **)NULL);
assert(a_tmpdir != (char *)NULL);
assert(a_pkgdev != (struct pkgdev *)NULL);
/* entry debug information */
echoDebug(DBG_ODS_ENTRY);
echoDebug(DBG_ODS_ARGS,
a_pkgdev->bdevice ? a_pkgdev->bdevice : "?",
a_pkgdev->cdevice ? a_pkgdev->cdevice : "?",
a_pkgdev->pathname ? a_pkgdev->pathname : "?",
a_argc, a_device ? a_device : "?");
/* reset possible return values to defaults */
*r_idsName = (char *)NULL;
if (r_repeat != (int *)NULL) {
*r_repeat = 0;
}
/*
* Determine how to access the package source "device":
* - if a block device is associated with the source:
* -- make sure the next "volume" is mounted and ready.
* -- input data stream is associated character device
* - if char device but no block device associated with device:
* -- input data stream is associated character device
* - else if a path is associated with device:
* -- input data stream is associated path
*/
if (a_pkgdev->bdevice != (char *)NULL) {
/* package source is block device */
/*
* _getvol verifies that the specified device is accessible and
* that a volume of the appropriate medium has been inserted.
* _getvol is in libadm.h - delivered by ON as part of SUNWcsl
* is somewhat analagous to getvol(1M) - args are:
* - char *device
* - char *label
* - int options
* - char *prompt
* - char *norewind - no rewind device (NULL to use device)
* Returns:
* 0 - okay, label matches
* 1 - device not accessable
* 2 - unknown device (devattr failed)
* 3 - user selected quit
* 4 - label does not match
*/
echoDebug(DBG_ODS_DATASTREAM_BDEV, a_pkgdev->bdevice);
n = _getvol(a_pkgdev->bdevice, NULL, 0L,
MSG_INSERT_VOL, a_pkgdev->norewind);
switch (n) {
case 0: /* volume open, label matches */
if (ds_readbuf(a_pkgdev->cdevice)) {
(*r_idsName) = a_pkgdev->cdevice;
}
break;
case 3: /* user selected quit */
quit(3);
/* NOTREACHED */
case 2: /* unknown device (devattr failed) */
progerr(ERR_UNKNOWN_DEV, a_pkgdev->name);
quit(99);
/* NOTREACHED */
default: /* device not accessable */
progerr(ERR_PKGVOL);
logerr(LOG_GETVOL_RET, n);
quit(99);
/* NOTREACHED */
}
} else if (a_pkgdev->cdevice != (char *)NULL) {
/* package source is character device */
echoDebug(DBG_ODS_DATASTREAM_CDEV, a_pkgdev->cdevice);
(*r_idsName) = a_pkgdev->cdevice;
} else if (a_pkgdev->pathname != (char *)NULL) {
/* package source is path name to file */
echoDebug(DBG_ODS_DATASTREAM_ISFILE, a_pkgdev->pathname);
(*r_idsName) = a_pkgdev->pathname;
} else {
echoDebug(DBG_ODS_DATASTREAM_UNK);
}
/*
* If writing the packages into a spool directory instead of
* installing the packages, invoke pkgtrans to perform the
* conversion and exit.
*/
if (a_spoolDir) {
return (B_TRUE);
}
/* create temp dir for op if input data stream specified */
if (*r_idsName) {
/*
* initialize datastream,
* dirname is set to directory where package is unstreamed
*/
if (setup_temporary_directory(&a_pkgdev->dirname, a_tmpdir,
"dstream") == B_FALSE) {
progerr(ERR_STREAMDIR, strerror(errno));
quit(99);
/* NOTREACHED */
}
}
if (r_repeat != (int *)NULL) {
*r_repeat = (a_optind >= a_argc);
}
/*
* mount source device (e.g. floppy) if no input data stream
* specified, and the package source device is mountable. If
* the pkgmount fails, go back and try to mount the package
* source again. When a package is split up into multiple
* volumes (such as floppies), it might be possible to go back
* and insert a different copy of the required volume/floppy
* if the current one cannot be mounted. Otherwise this could
* have just called quit() if the mount failed...
*/
if (((*r_idsName) == (char *)NULL) && a_pkgdev->mount) {
echoDebug(DBG_ODS_DATASTREAM_MOUNTING, *r_idsName,
a_pkgdev->mount);
a_pkgdev->rdonly++;
n = pkgmount(a_pkgdev, NULL, 0, 0, 0);
if (n != 0) {
/* pkgmount failed */
return (B_FALSE);
}
}
/*
* open and initialize input data stream if specified
*/
if ((*r_idsName) != (char *)NULL) {
echoDebug(DBG_ODS_DATASTREAM_INIT, *r_idsName);
/* use character device to force rewind of datastream */
if ((a_pkgdev->cdevice != (char *)NULL) &&
(a_pkgdev->bdevice == (char *)NULL)) {
n = _getvol(a_pkgdev->name, NULL, 0L, NULL,
a_pkgdev->norewind);
switch (n) {
case 0: /* volume open, label matches */
break;
case 3: /* user selected quit */
quit(3);
/* NOTREACHED */
case 2: /* unknown device (devattr failed) */
progerr(ERR_UNKNOWN_DEV, a_pkgdev->name);
quit(99);
/* NOTREACHED */
default:
progerr(ERR_PKGVOL);
logerr(LOG_GETVOL_RET, n);
quit(99);
/* NOTREACHED */
}
}
if (chdir(a_pkgdev->dirname)) {
progerr(ERR_CHDIR, a_pkgdev->dirname);
quit(99);
/* NOTREACHED */
}
/*
* initialize datastream for subsequent installation;
* read the source device;
* aquire the header data and check it for validity;
* creates subdirectories in package stream directory
* (a_pkgdev->dirname) for each package and retrieves each
* packages pkginfo and pkgmap files
*/
if (ds_init(*r_idsName, &a_argv[a_optind],
a_pkgdev->norewind)) {
progerr(ERR_DSINIT, *r_idsName);
quit(99);
/* NOTREACHED */
}
}
return (B_TRUE);
}
|