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.
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.
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]
23 * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
37 #include <sys/types.h>
51 * internal global variables
54 static struct pkginfo info
;
57 static char *alist
[NVERS
];
58 static char *rmpkginst
;
59 static char *vlist
[NVERS
];
60 static char file
[128];
61 static char name
[128];
62 static char rmpkg
[PKGSIZ
+1];
63 static char wabbrev
[128];
65 static int errflg
= 0;
72 * IMPORTANT NOTE: THE SIZE OF 'abbrev' IS HARD CODED INTO THE CHARACTER
73 * ARRAY SSCANF_FORMAT -- YOU MUST UPDATE BOTH VALUES AT THE SAME TIME!!
76 static char abbrev
[128+1];
77 static char *SSCANF_FORMAT
= "%c %128s %[^\n]";
80 * forward declarations
83 static void ckrdeps(boolean_t a_preinstallCheck
);
84 static void ckpreq(FILE *fp
, char *dname
, boolean_t a_preinstallCheck
);
85 static void deponme(char *pkginst
, char *pkgname
,
86 boolean_t a_preinstallCheck
);
87 static void prereq(char *pkginst
, char *pkgname
,
88 boolean_t a_preinstallCheck
);
89 static void incompat(char *pkginst
, char *pkgname
,
90 boolean_t a_preinstallCheck
);
91 static int getaline(FILE *fp
);
94 * *****************************************************************************
95 * global external (public) functions
96 * *****************************************************************************
100 dockdeps(char *a_depfile
, int a_removeFlag
, boolean_t a_preinstallCheck
)
107 /* check removal dependencies */
108 rmpkginst
= a_depfile
;
109 (void) strncpy(rmpkg
, rmpkginst
, PKGSIZ
);
110 (void) strtok(rmpkg
, ".");
111 (void) snprintf(file
, sizeof (file
),
112 "%s/%s/%s", pkgdir
, rmpkginst
, DEPEND_FILE
);
113 if ((fp
= fopen(file
, "r")) == NULL
)
116 if ((fp
= fopen(a_depfile
, "r")) == NULL
) {
117 progerr(ERR_CANNOT_OPEN_DEPEND_FILE
, a_depfile
,
123 while (getaline(fp
)) {
140 progerr(ERR_UNKNOWN_DEPENDENCY
, type
);
144 /* check to see if any versions listed are installed */
145 pkgexist
= pkgokay
= 0;
147 if (strchr(abbrev
, '.')) {
148 progerr(ERR_PKGABRV
, abbrev
);
150 (void) snprintf(wabbrev
, sizeof (wabbrev
), "%s.*", abbrev
);
153 inst
= fpkginst(wabbrev
, alist
[i
], vlist
[i
]);
154 if (inst
&& (pkginfo(&info
, inst
, NULL
, NULL
) == 0)) {
156 if (info
.status
== PI_INSTALLED
)
159 } while (++i
< nlist
);
160 (void) fpkginst(NULL
); /* force closing/rewind of files */
168 incompat(abbrev
, info
.name
, a_preinstallCheck
);
172 prereq(abbrev
, name
, a_preinstallCheck
);
176 deponme(abbrev
, info
.name
, a_preinstallCheck
);
183 ckrdeps(a_preinstallCheck
);
198 return ((is_update
) ? 1 : 0);
202 * *****************************************************************************
203 * static internal (private) functions
204 * *****************************************************************************
208 incompat(char *pkginst
, char *pkgname
, boolean_t a_preinstallCheck
)
216 if (a_preinstallCheck
== B_TRUE
) {
217 (void) fprintf(stdout
, "incompat=%s\n", pkginst
);
222 (void) snprintf(buf
, sizeof (buf
), ERR_INCOMP_VERS
, pkginst
, pkgname
);
223 puttext(stderr
, buf
, 4, 0);
224 (void) putc('\n', stderr
);
228 prereq(char *pkginst
, char *pkgname
, boolean_t a_preinstallCheck
)
239 if (a_preinstallCheck
== B_TRUE
) {
241 (void) fprintf(stdout
,
242 "prerequisite-incomplete=%s\n", pkginst
);
244 (void) fprintf(stdout
,
245 "prerequisite-installed=%s\n", pkginst
);
252 (void) snprintf(buf
, sizeof (buf
), ERR_PRENCI
, pkginst
,
254 puttext(stderr
, buf
, 4, 0);
255 (void) putc('\n', stderr
);
257 (void) snprintf(buf
, sizeof (buf
), ERR_PREREQ
, pkginst
,
260 (void) strcat(buf
, ERR_VALINST
);
262 puttext(stderr
, buf
, 4, 0);
263 (void) putc('\n', stderr
);
264 for (i
= 0; i
< nlist
; i
++) {
267 (void) printf("(%s) ", alist
[i
]);
269 (void) printf("%s", vlist
[i
]);
276 deponme(char *pkginst
, char *pkgname
, boolean_t a_preinstallCheck
)
285 if (a_preinstallCheck
== B_TRUE
) {
286 if (!pkgname
|| !pkgname
[0]) {
287 (void) snprintf(buf
, sizeof (buf
),
288 "dependonme=%s", pkginst
);
290 (void) snprintf(buf
, sizeof (buf
),
291 "dependsonme=%s:%s", pkginst
, pkgname
);
293 (void) fprintf(stdout
, "%s\n", buf
);
298 if (!pkgname
|| !pkgname
[0]) {
299 (void) snprintf(buf
, sizeof (buf
), ERR_DEPONME
, pkginst
);
301 (void) snprintf(buf
, sizeof (buf
), ERR_DEPNAM
, pkginst
,
304 puttext(stderr
, buf
, 4, 0);
305 (void) putc('\n', stderr
);
311 register int i
, c
, found
;
312 char *pt
, *new, line
[LSIZE
];
314 abbrev
[0] = name
[0] = type
= '\0';
316 for (i
= 0; i
< nlist
; i
++) {
326 alist
[0] = vlist
[0] = NULL
;
330 while ((c
= getc(fp
)) != EOF
) {
331 (void) ungetc(c
, fp
);
332 if ((found
>= 0) && !isspace(c
))
335 if (!fgets(line
, LSIZE
, fp
))
338 for (pt
= line
; isspace(*pt
); /* void */)
340 if (!*pt
|| (*pt
== '#'))
344 /* begin new definition */
345 /* LINTED variable format specifier to sscanf(): */
346 (void) sscanf(line
, SSCANF_FORMAT
, &type
, abbrev
, name
);
354 /* architecture is specified */
355 if (new = strchr(pt
, ')'))
358 return (-1); /* bad specification */
359 alist
[found
] = qstrdup(pt
+1);
365 vlist
[found
] = qstrdup(pt
);
366 if (pt
= strchr(vlist
[found
], '\n'))
372 return ((found
>= 0) ? 1 : 0);
376 ckrdeps(boolean_t a_preinstallCheck
)
381 char depfile
[PATH_MAX
+1];
383 if ((dirfp
= opendir(pkgdir
)) == NULL
)
386 while ((drp
= readdir(dirfp
)) != NULL
) {
387 if (drp
->d_name
[0] == '.')
390 if (strcmp(drp
->d_name
, rmpkginst
) == 0)
391 continue; /* others don't include me */
392 (void) snprintf(depfile
, sizeof (depfile
),
393 "%s/%s/%s", pkgdir
, drp
->d_name
, DEPEND_FILE
);
394 if ((fp
= fopen(depfile
, "r")) == NULL
)
397 ckpreq(fp
, drp
->d_name
, a_preinstallCheck
);
399 (void) closedir(dirfp
);
403 ckpreq(FILE *fp
, char *dname
, boolean_t a_preinstallCheck
)
408 while (getaline(fp
)) {
412 if (strcmp(abbrev
, rmpkg
))
415 /* see if package is installed */
417 if (strchr(abbrev
, '.') == 0) {
418 (void) strcat(abbrev
, ".*");
423 if (inst
= fpkginst(abbrev
, alist
[i
], vlist
[i
])) {
424 if (strcmp(inst
, rmpkginst
) == 0) {
425 deponme(dname
, "", a_preinstallCheck
);
427 (void) fpkginst(NULL
);
431 } while (++i
< nlist
);
432 (void) fpkginst(NULL
);