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 1993 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 #include <stdio.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <string.h>
35 #include <limits.h>
36 #include <stdlib.h>
37 #include <unistd.h>
38 #include <pkglocs.h>
39 #include <locale.h>
40 #include <libintl.h>
41 #include <pkglib.h>
42 #include "libadm.h"
43
44 extern char *pkgname, pkgloc[];
45 extern int warnflag;
46
47 #define ERR_RMLINK "unable to remove options file <%s>"
48 #define ERR_SYMLINK "unable to create symbloic link from <%s> to <%s>"
49 #define ERR_PREDEPEND "unable to create predepend file <%s>"
50
51 void
predepend(char * oldpkg)52 predepend(char *oldpkg)
53 {
54 FILE *fp;
55 char path[PATH_MAX];
56 char spath[PATH_MAX];
57 struct stat statbuf;
58
59 oldpkg = strtok(oldpkg, " \t\n");
60 if (oldpkg == NULL)
61 return;
62
63 (void) sprintf(path, "%s/predepend", pkgloc);
64 if ((fp = fopen(path, "w")) == NULL) {
65 progerr(gettext(ERR_PREDEPEND), path);
66 warnflag++;
67 return;
68 }
69 (void) fprintf(fp, "%s\n", pkgname);
70 (void) fclose(fp);
71
72 do {
73 (void) sprintf(spath, "%s/%s.name", get_PKGOLD(), oldpkg);
74 if (lstat(spath, &statbuf) == 0) {
75 /* options file already exists */
76 if (statbuf.st_mode & S_IFLNK) {
77 /* remove current link */
78 if (unlink(spath)) {
79 progerr(gettext(ERR_RMLINK), spath);
80 warnflag++;
81 }
82 }
83 }
84 if (symlink(path, spath)) {
85 progerr(gettext(ERR_SYMLINK), path, spath);
86 warnflag++;
87 }
88 } while (oldpkg = strtok(NULL, " \t\n"));
89 }
90