]>
Commit | Line | Data |
---|---|---|
7fe0b58f JB |
1 | --- pcp-3.9.6/configure.ac.orig 2014-05-28 22:05:42.575179206 +0200 |
2 | +++ pcp-3.9.6/configure.ac 2014-05-30 20:21:36.818374363 +0200 | |
5e6551d9 JB |
3 | @@ -2369,8 +2369,8 @@ |
4 | savedLIBS=$LIBS | |
5 | AC_MSG_CHECKING([for rpmlib > 4.4.2]) | |
6 | AC_COMPILE_IFELSE( | |
7 | - [AC_LANG_PROGRAM([[#include <rpm/header.h>]], | |
8 | - [[(void)HEADERGET_EXT;]])], | |
9 | + [AC_LANG_PROGRAM([[#include <rpm/rpmtypes.h>]], | |
10 | + [[(void)RPMSCRIPT_PREIN;]])], | |
11 | [AC_MSG_RESULT([yes]) | |
12 | have_rpmlib=1], | |
13 | [AC_MSG_RESULT([no]) | |
14 | --- pcp-3.9.4/src/pmdas/rpm/GNUmakefile.orig 2014-04-15 11:10:23.000000000 +0200 | |
15 | +++ pcp-3.9.4/src/pmdas/rpm/GNUmakefile 2014-06-01 07:52:17.205709769 +0200 | |
16 | @@ -31,9 +31,9 @@ VERSION_SCRIPT = exports | |
17 | LSRCFILES = Install Remove pmns root help | |
18 | LDIRT = domain.h $(IAM).log $(VERSION_SCRIPT) | |
19 | ||
20 | -LIB_FOR_RPM = -lrpm | |
21 | +LIB_FOR_RPM = -lrpm -lrpmdb -lrpmio | |
22 | LLDLIBS = $(PCP_PMDALIB) $(LIB_FOR_RPM) $(LIB_FOR_PTHREADS) | |
23 | -LCFLAGS = $(INVISIBILITY) | |
24 | +LCFLAGS = $(INVISIBILITY) -I/usr/include/rpm | |
25 | ||
26 | default: build-me | |
27 | ||
28 | --- pcp-3.9.4/src/pmdas/rpm/rpm.c.orig 2014-04-15 11:10:23.000000000 +0200 | |
29 | +++ pcp-3.9.4/src/pmdas/rpm/rpm.c 2014-06-01 07:51:37.589043928 +0200 | |
30 | @@ -17,9 +17,9 @@ | |
31 | #include <sys/stat.h> | |
32 | #include <pthread.h> | |
33 | #include <search.h> | |
34 | +#include <stdarg.h> | |
35 | #include <sys/inotify.h> | |
36 | -#include <rpm/rpmlib.h> | |
37 | -#include <rpm/header.h> | |
38 | +#include <rpm/rpm46compat.h> | |
39 | #include <rpm/rpmts.h> | |
40 | #include <rpm/rpmdb.h> | |
41 | #include <pcp/pmapi.h> | |
42 | @@ -436,7 +436,7 @@ rpm_extract_metadata(const char *name, r | |
43 | m->license = dict_insert(rpm_extract_string(td, h, RPMTAG_LICENSE)); | |
44 | m->packager = dict_insert(rpm_extract_string(td, h, RPMTAG_PACKAGER)); | |
45 | m->release = dict_insert(rpm_extract_string(td, h, RPMTAG_RELEASE)); | |
46 | - m->longsize = rpm_extract_value(td, h, RPMTAG_LONGSIZE); | |
47 | + m->longsize = rpm_extract_value(td, h, RPMTAG_PACKAGESIZE); | |
48 | m->sourcerpm = dict_insert(rpm_extract_string(td, h, RPMTAG_SOURCERPM)); | |
49 | m->summary = dict_insert(rpm_extract_string(td, h, RPMTAG_SUMMARY)); | |
50 | m->url = dict_insert(rpm_extract_string(td, h, RPMTAG_URL)); | |
51 | @@ -444,6 +444,157 @@ rpm_extract_metadata(const char *name, r | |
52 | m->version = dict_insert(rpm_extract_string(td, h, RPMTAG_VERSION)); | |
53 | } | |
54 | ||
55 | +/* from rpm.org */ | |
56 | +static char *rstrscat(char **dest, const char *arg, ...) | |
57 | +{ | |
58 | + va_list ap; | |
59 | + size_t arg_size, dst_size; | |
60 | + const char *s; | |
61 | + char *dst, *p; | |
62 | + | |
63 | + dst = dest ? *dest : NULL; | |
64 | + | |
65 | + if ( arg == NULL ) { | |
66 | + return dst; | |
67 | + } | |
68 | + | |
69 | + va_start(ap, arg); | |
70 | + for (arg_size=0, s=arg; s; s = va_arg(ap, const char *)) | |
71 | + arg_size += strlen(s); | |
72 | + va_end(ap); | |
73 | + | |
74 | + dst_size = dst ? strlen(dst) : 0; | |
75 | + dst = realloc(dst, dst_size+arg_size+1); /* include '\0' */ | |
76 | + p = &dst[dst_size]; | |
77 | + | |
78 | + va_start(ap, arg); | |
79 | + for (s = arg; s; s = va_arg(ap, const char *)) { | |
80 | + size_t size = strlen(s); | |
81 | + memmove(p, s, size); | |
82 | + p += size; | |
83 | + } | |
84 | + va_end(ap); | |
85 | + *p = '\0'; | |
86 | + | |
87 | + if ( dest ) { | |
88 | + *dest = dst; | |
89 | + } | |
90 | + | |
91 | + return dst; | |
92 | +} | |
93 | + | |
94 | +static const char * headerGetString(Header h, int32_t tag) | |
95 | +{ | |
96 | + const char *res = NULL; | |
97 | + struct rpmtd_s td; | |
98 | + | |
99 | + if (headerGet(h, tag, &td, HEADERGET_MINMEM)) { | |
100 | + if (rpmtdCount(&td) == 1) { | |
101 | + res = rpmtdGetString(&td); | |
102 | + } | |
103 | + rpmtdFreeData(&td); | |
104 | + } | |
105 | + return res; | |
106 | +} | |
107 | + | |
108 | +static int rasprintf(char **strp, const char *fmt, ...) | |
109 | +{ | |
110 | + int n; | |
111 | + va_list ap; | |
112 | + char * p = NULL; | |
113 | + | |
114 | + if (strp == NULL) | |
115 | + return -1; | |
116 | + | |
117 | + va_start(ap, fmt); | |
118 | + n = vsnprintf(NULL, 0, fmt, ap); | |
119 | + va_end(ap); | |
120 | + | |
121 | + if (n >= -1) { | |
122 | + size_t nb = n + 1; | |
123 | + p = malloc(nb); | |
124 | + va_start(ap, fmt); | |
125 | + n = vsnprintf(p, nb, fmt, ap); | |
126 | + va_end(ap); | |
127 | + } | |
128 | + *strp = p; | |
129 | + return n; | |
130 | +} | |
131 | + | |
132 | +static uint64_t rpmtdGetNumber(rpmtd td) | |
133 | +{ | |
134 | + uint64_t val = 0; | |
135 | + int ix = (td->ix >= 0 ? td->ix : 0); | |
136 | + | |
137 | + switch (td->type) { | |
138 | + case RPM_INT64_TYPE: | |
139 | + val = *((uint64_t *) td->data + ix); | |
140 | + break; | |
141 | + case RPM_INT32_TYPE: | |
142 | + val = *((uint32_t *) td->data + ix); | |
143 | + break; | |
144 | + case RPM_INT16_TYPE: | |
145 | + val = *((uint16_t *) td->data + ix); | |
146 | + break; | |
147 | + case RPM_INT8_TYPE: | |
148 | + val = *((uint8_t *) td->data + ix); | |
149 | + break; | |
150 | + default: | |
151 | + break; | |
152 | + } | |
153 | + return val; | |
154 | +} | |
155 | + | |
156 | +static char * headerGetNumericAsString(Header h, int32_t tag) | |
157 | +{ | |
158 | + char *res = NULL; | |
159 | + struct rpmtd_s td; | |
160 | + | |
161 | + if (headerGet(h, tag, &td, HEADERGET_EXT)) { | |
162 | + if (rpmtdCount(&td) == 1) { | |
163 | + rasprintf(&res, "%" PRIu64, rpmtdGetNumber(&td)); | |
164 | + } | |
165 | + rpmtdFreeData(&td); | |
166 | + } | |
167 | + return res; | |
168 | +} | |
169 | + | |
170 | +static int headerIsSource(Header h) | |
171 | +{ | |
172 | + return (!headerIsEntry(h, RPMTAG_SOURCERPM)); | |
173 | +} | |
174 | + | |
175 | +char *getNEVRA(Header h) | |
176 | +{ | |
177 | + const char *val = NULL; | |
178 | + char *res = NULL; | |
179 | + | |
180 | + { | |
181 | + val = headerGetString(h, RPMTAG_NAME); | |
182 | + if (val) rstrscat(&res, val, "-", NULL); | |
183 | + } | |
184 | + { | |
185 | + char *e = headerGetNumericAsString(h, RPMTAG_EPOCH); | |
186 | + if (e) rstrscat(&res, e, ":", NULL); | |
187 | + free(e); | |
188 | + } | |
189 | + { | |
190 | + val = headerGetString(h, RPMTAG_VERSION); | |
191 | + if (val) rstrscat(&res, val, "-", NULL); | |
192 | + } | |
193 | + { | |
194 | + val = headerGetString(h, RPMTAG_RELEASE); | |
195 | + if (val) rstrscat(&res, val, NULL); | |
196 | + } | |
197 | + { | |
198 | + val = headerGetString(h, RPMTAG_ARCH); | |
199 | + if (headerIsSource(h) && val == NULL) val = "src"; | |
200 | + if (val) rstrscat(&res, ".", val, NULL); | |
201 | + } | |
202 | + | |
203 | + return res; | |
204 | +} | |
205 | + | |
206 | /* | |
207 | * Refresh the RPM package names and values in the cache. | |
208 | * This is to be only ever invoked from a single thread. | |
209 | @@ -470,7 +621,8 @@ rpm_update_cache(void *ptr) | |
210 | * since the only (?) thing that can fail is memory allocation, which | |
211 | * rpmlib internally maps to an exit(1). | |
212 | */ | |
213 | - td = rpmtdNew(); | |
214 | + td = malloc(sizeof(*td)); | |
215 | + rpmtdReset(td); | |
216 | ts = rpmtsCreate(); | |
217 | ||
218 | if (rpmReadConfigFiles_p == 0) { | |
219 | @@ -483,8 +635,7 @@ rpm_update_cache(void *ptr) | |
220 | /* Iterate through the entire list of RPMs, extract names and values */ | |
221 | mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0); | |
222 | while ((h = rpmdbNextIterator(mi)) != NULL) { | |
223 | - headerGet(h, RPMTAG_NEVRA, td, HEADERGET_EXT | HEADERGET_MINMEM); | |
224 | - const char *name = rpmtdGetString(td); | |
225 | + char *name = getNEVRA(h); | |
226 | metadata meta; | |
227 | package *pp = NULL; | |
228 | int sts, err = 0; | |
229 | @@ -522,10 +673,13 @@ rpm_update_cache(void *ptr) | |
230 | } | |
231 | } | |
232 | pthread_mutex_unlock(&indom_mutex); | |
233 | + free(name); | |
234 | } | |
235 | ||
236 | rpmdbFreeIterator(mi); | |
237 | rpmtsFree(ts); | |
238 | + rpmtdFreeData(td); | |
239 | + free(td); | |
240 | ||
241 | pthread_mutex_lock(&indom_mutex); | |
242 | stop_timing(); |