This repository was archived by the owner on Aug 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelmap.c
164 lines (141 loc) · 4.22 KB
/
delmap.c
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
/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pkgstrct.h>
#include <locale.h>
#include <libintl.h>
#include <pkglib.h>
#include <libadm.h>
#include <libinst.h>
extern int dbchg, warnflag, otherstoo;
extern char *pkginst;
#define EPTMALLOC 128
#define ERR_WRENT "write of entry failed, errno=%d"
#define ERR_MEMORY "no memory, errno=%d"
#define ERR_READ_C "bad read of contents file"
#define ERR_READ_DB "bad read of the database"
extern struct cfent **eptlist;
extern int eptnum;
int
delmap(int flag, char *pkginst, PKGserver *pkgserver, VFP_T **tmpfp)
{
struct cfent *ept;
struct pinfo *pinfo;
int n;
char *unknown = "Unknown";
if (!ocfile(pkgserver, tmpfp, 0L) ||
pkgopenfilter(*pkgserver, pkginst) != 0) {
quit(99);
}
/* re-use any memory used to store pathnames */
(void) pathdup(NULL);
if (eptlist != NULL)
free(eptlist);
eptlist = (struct cfent **)calloc(EPTMALLOC,
sizeof (struct cfent *));
if (eptlist == NULL) {
progerr(gettext(ERR_MEMORY), errno);
quit(99);
}
ept = (struct cfent *)calloc(1,
(unsigned)sizeof (struct cfent));
if (!ept) {
progerr(gettext(ERR_MEMORY), errno);
quit(99);
}
eptnum = 0;
while (n = srchcfile(ept, "*", *pkgserver)) {
if (n < 0) {
char *errstr = getErrstr();
progerr(gettext("bad read of contents file"));
progerr(gettext("pathname=%s"),
(ept->path && *ept->path) ? ept->path :
unknown);
progerr(gettext("problem=%s"),
(errstr && *errstr) ? errstr : unknown);
exit(99);
}
pinfo = eptstat(ept, pkginst, (flag ? '@' : '-'));
if (ept->npkgs > 0) {
if (putcvfpfile(ept, *tmpfp)) {
progerr(gettext(ERR_WRENT), errno);
quit(99);
}
} else if (ept->path != NULL) {
(void) vfpSetModified(*tmpfp);
/* add "-<path>" to the file */
vfpPutc(*tmpfp, '-');
vfpPuts(*tmpfp, ept->path);
vfpPutc(*tmpfp, '\n');
}
if (flag || (pinfo == NULL))
continue;
dbchg++;
/*
* If (otherstoo > 0), more than one package has an
* interest in the ept entry in the database. Setting
* ept->ftype = '\0' effectively marks the file as being
* "shared", thus ensuring the ept entry will not
* subsequently be removed. Shared editable files (ftype
* 'e') are a special case: they should be passed to a
* class action script if present. Setting ept->ftype =
* '^' indicates this special case of shared editable
* file, allowing the distinction to be made later.
*/
if (!pinfo->editflag && otherstoo)
ept->ftype = (ept->ftype == 'e') ? '^' : '\0';
if (*pinfo->aclass)
(void) strcpy(ept->pkg_class, pinfo->aclass);
eptlist[eptnum] = ept;
ept->path = pathdup(ept->path);
if (ept->ainfo.local != NULL)
ept->ainfo.local = pathdup(ept->ainfo.local);
ept = (struct cfent *)calloc(1, sizeof (struct cfent));
if ((++eptnum % EPTMALLOC) == 0) {
eptlist = (struct cfent **)realloc(eptlist,
(eptnum+EPTMALLOC)*sizeof (struct cfent *));
if (eptlist == NULL) {
progerr(gettext(ERR_MEMORY), errno);
quit(99);
}
}
}
eptlist[eptnum] = (struct cfent *)NULL;
n = swapcfile(*pkgserver, tmpfp, pkginst, dbchg);
if (n == RESULT_WRN) {
warnflag++;
} else if (n == RESULT_ERR) {
quit(99);
}
return (0);
}