Commit b14c9271cf48f60b715ff7322a90d2c1a0703004

Authored by Silvan Calarco
1 parent 2bca22fae3
Exists in master

Runtime fixes after rpm 4 migration

Showing 7 changed files with 87 additions and 65 deletions Side-by-side Diff

... ... @@ -44,7 +44,7 @@
44 44 ${LIBIBERTY}
45 45 )
46 46 target_include_directories(distromatic PUBLIC ${RPM_INCLUDE_DIRS})
47   -target_compile_options(distromatic PUBLIC ${RPM_CFLAGS_OTHER})
  47 +target_compile_options(distromatic PUBLIC -g -Wall -std=gnu11 -pedantic ${RPM_CFLAGS_OTHER})
48 48  
49 49 add_executable(distroquery
50 50 distroquery.c
... ... @@ -28,12 +28,10 @@
28 28 # include <strings.h>
29 29 #endif
30 30  
31   -#ifndef BUILDTOOLS_H
32   -# include "buildtools.h"
33   -#endif
34   -#ifndef DISTROMATIC_H
35   -# include "distromatic.h"
36   -#endif
  31 +#include <linux/limits.h>
  32 +
  33 +#include "distromatic.h"
  34 +#include "buildtools.h"
37 35  
38 36 int
39 37 generateBuildInfo(struct configTag *configtag, int arch)
... ... @@ -39,6 +39,8 @@
39 39 # include <strings.h>
40 40 #endif
41 41  
  42 +#include <string.h>
  43 +
42 44 #include "distromatic.h"
43 45 #include "config.h"
44 46 #include "changelog.h"
... ... @@ -137,6 +139,7 @@
137 139 if (oldchangelog) {
138 140 oldchangelog->next = newchangelog;
139 141 }
  142 +
140 143 newchangelog->time = changelogtime[i];
141 144  
142 145 strncpy(changelogname, changelogrelease[i], 255);
... ... @@ -405,7 +405,7 @@
405 405 for (i = 0; i < 20; i++) {
406 406 /* only log the same message once */
407 407 if (!strncmp(newmsg,(char*)&(oldmsg[i]),256)) return;
408   - }
  408 + }
409 409  
410 410 switch (level) {
411 411 case LOG_MARK:
... ... @@ -216,29 +216,28 @@
216 216 hl->arch = headerGetStringEntry(h, RPMTAG_ARCH);
217 217 hl->buildarchs = headerGetStringEntry(h, RPMTAG_BUILDARCHS);
218 218 hl->excludearch = headerGetStringEntry(h, RPMTAG_EXCLUDEARCH);
219   - if (hl->buildarchs) printf("buildarchs: %s %s\n",hl->name,hl->buildarchs);
220   - if (hl->excludearch) printf("excludearch: %s %s\n",hl->name,hl->excludearch);
221 219 hl->description = headerGetStringEntry(h, RPMTAG_DESCRIPTION);
222 220 packager = headerGetStringEntry(h, RPMTAG_PACKAGER);
223 221 if (!packager) {
224 222 logmsg(LOG_WARNING,"missing packager definition in package %s.",hl->name);
225   - hl->packager = NULL;
  223 + hl->packager = NULL;
226 224 } else {
227 225 hl->packager = getPackagerByName(packager,1);
228 226 if (!hl->packager) {
229 227 logmsg(LOG_WARNING,"cannot create '%s' packager for package %s.",packager,hl->name);
  228 + free(packager);
230 229 }
231 230 /* if (! (hl->packager->role && PACKAGER_ROLE_MAINTAINER)) {
232 231 logmsg(LOG_WARNING,"%s is an unmaintained package.",hl->name,hl->packager->name,hl->packager->role);
233 232 }*/
234 233 }
235   - free(packager);
236 234 hl->group = headerGetStringEntry(h, RPMTAG_GROUP);
237 235 hl->license = headerGetStringEntry(h, RPMTAG_LICENSE);
238 236 hl->url = headerGetStringEntry(h, RPMTAG_URL);
239 237 if (!hl->url)
240 238 logmsg(LOG_WARNING,"missing URL definition for package %s.",hl->name);
241 239 hl->buildtime = headerGetUIntEntry(h, RPMTAG_BUILDTIME);
  240 +
242 241 hl->source = headerGetStringArrayEntry(h, RPMTAG_SOURCE, &count);
243 242 hl->patch = headerGetStringArrayEntry(h, RPMTAG_PATCH, &count);
244 243 hl->size = headerGetUIntEntry(h, RPMTAG_SIZE);
245 244  
246 245  
247 246  
... ... @@ -621,19 +620,15 @@
621 620 struct changeLog *changelog;
622 621 Header h;
623 622 char filepath[bufsize + 1];
624   - int n, j, arch, *dirindexes, filenamescount, dirnamescount;
  623 + int n, j, arch, filenamescount, dirnamescount;
625 624 int_16 *fileflags;
626 625 char **basenames, **dirnames, **usernames, **groupnames;
627 626 const char* errstr;
628 627 int requirecount;
629 628 char **requireversion, **requirename;
630   - uint_32 *requireflags;
  629 + uint_32 *requireflags, *dirindexes;
631 630 char warning[PATH_MAX];
632   -#if RPM_VERSION >= 0x050000
633 631 rpmts ts = rpmtsCreate();
634   -#else
635   - rpmts ts = NULL;
636   -#endif
637 632  
638 633 if (altrepository == ct->repository_level) {
639 634 scanpath = ct->repository_source_dir;
640 635  
... ... @@ -666,12 +661,12 @@
666 661 strcpy(&filepath[strlen(scanpath)], namelist[cnt]->d_name);
667 662  
668 663 logmsg(LOG_DEBUG, "getting header for %s", filepath);
669   - if (getHeader(&ts, filepath, &h)) {
  664 +
  665 + if (getHeader(&ts, filepath, &h)) {
670 666 errstr = strerror(errno);
671 667 logmsg(LOG_WARNING,
672 668 "%s: unable to read header (%s); skipping.",namelist[cnt]->d_name, errstr);
673   - } else {
674   -
  669 + } else {
675 670 getPackageFiles(h, &dirindexes, &dirnames, &dirnamescount,
676 671 &basenames, &filenamescount,
677 672 &usernames, &groupnames, &fileflags);
... ... @@ -692,6 +687,7 @@
692 687 newheadersourcelist->firstrebuild = NULL;
693 688 newheadersourcelist->old = NULL;
694 689 newheadersourcelist->id = ++sourceid;
  690 +
695 691 getPackageInfoIntoHeaderSourceList(h, newheadersourcelist);
696 692  
697 693  
698 694  
... ... @@ -813,9 +809,7 @@
813 809 } // for
814 810  
815 811 free(namelist);
816   -#if RPM_VERSION >= 0x050000
817 812 rpmtsFree(ts);
818   -#endif
819 813 return 0;
820 814 }
821 815  
... ... @@ -871,8 +865,7 @@
871 865 char *filename=NULL;
872 866 long i ,j , k, n, altn[ALT_REPS_MAX];
873 867 int altrepository=0, obsoletecount, providecount, requirecount,
874   - filenamecount, dirnamecount,
875   - *dirindex;
  868 + filenamecount, dirnamecount;
876 869 int_16 *fileflags;
877 870 char **obsoletename, **obsoleteversion,
878 871 **providename, **provideversion,
... ... @@ -880,7 +873,7 @@
880 873 **basename, **dirname, **newversion,
881 874 **fileusername, **filegroupname;
882 875 const char* errstr;
883   - uint_32 *requireflags, *obsoleteflags, *provideflags;
  876 + uint_32 *dirindex, *requireflags, *obsoleteflags, *provideflags;
884 877 #if RPM_VERSION >= 0x050000
885 878 rpmts ts = rpmtsCreate();
886 879 #else
... ... @@ -978,7 +971,8 @@
978 971 /* process package */
979 972 logmsg(LOG_DEBUG, "getting header for %s", filepath);
980 973  
981   - sem_t rpm_mutex;
  974 + sem_t rpm_mutex = getRPMMutex();
  975 +
982 976 sem_wait(&rpm_mutex);
983 977 if (getHeader(&ts, filepath, &h)) {
984 978 sem_post(&rpm_mutex);
src/include/rpmfunctions.h
... ... @@ -48,7 +48,7 @@
48 48  
49 49 long long headerGetUIntEntry(Header h, const int tag);
50 50  
51   -void *headerGetUIntArrayEntry(Header h, const int tag, int *count);
  51 +uint_32 *headerGetUIntArrayEntry(Header h, const int tag, int *count);
52 52  
53 53 int getHeader(rpmts *ts, char *headerFile, Header * h);
54 54  
... ... @@ -65,7 +65,7 @@
65 65 char ***obsoleteversion, int *obsoletecount);
66 66  
67 67 int
68   -getPackageFiles(Header h, int **dirindexes,
  68 +getPackageFiles(Header h, uint_32 **dirindexes,
69 69 char ***dirnames, int *dirnamescount,
70 70 char ***basenames, int *filenamescount,
71 71 char ***usernames, char ***groupnames,
... ... @@ -76,6 +76,8 @@
76 76 int scanrpmnamecmp(const struct dirent **f1, const struct dirent **f2);
77 77  
78 78 char* printrpmversion(char *s, int bufsize, long epoch, char *version, char *release);
  79 +
  80 +sem_t getRPMMutex();
79 81  
80 82 #endif // RPMFUNCTIONS_H
... ... @@ -29,14 +29,13 @@
29 29 #endif
30 30  
31 31 #include <fcntl.h>
32   -
33 32 #include <zlib.h>
34 33 #include <libiberty/libiberty.h>
  34 +
35 35 #include "functions.h"
  36 +#include "rpmfunctions.h"
36 37  
37   -#ifndef RPMFUNCTIONS_H
38   -# include "rpmfunctions.h"
39   -#endif
  38 +sem_t rpm_mutex;
40 39  
41 40 /*
42 41 * static int getPackageInfo(
... ... @@ -104,7 +103,6 @@
104 103 if (fd == NULL || Ferror(fd)) {
105 104 return 1;
106 105 }
107   -
108 106 int rc;
109 107  
110 108 #if RPM_VERSION >= 0x040100
... ... @@ -116,7 +114,6 @@
116 114 #endif
117 115 #if RPM_VERSION >= 0x040100
118 116 if (rc != RPMRC_OK && rc != RPMRC_NOTTRUSTED && rc != RPMRC_NOKEY) {
119   -// fprintf(stderr, "Error: Failed reading file %s\n", headerFile);
120 117 #else
121 118 if (rc != 0) {
122 119 #endif
123 120  
124 121  
125 122  
... ... @@ -130,21 +127,19 @@
130 127 char *
131 128 headerGetStringEntry(Header h, const int tag)
132 129 {
133   - const char *st = NULL;
  130 + char *st = NULL;
134 131  
135 132 #if RPM_VERSION_MAJOR >= 0x050000
136 133 HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
137 134  
138 135 he->tag = tag;
139 136 if (headerGet(h, he, 0) && he->t == RPM_STRING_TYPE && he->c == 1)
140   - st = xstrdup(he->p.str);
  137 + st = strdup(he->p.str);
141 138 else
142 139 st = NULL;
143   -
144   -//printf(" headerGetStringEntry tag:%d st:%s\n", he->tag, st);
145 140 he->p.ptr = _free(he->p.ptr);
146 141 #else
147   - st = headerGetString(h, tag);
  142 + st = headerGetAsString(h, tag);
148 143 #endif
149 144 return st;
150 145 }
151 146  
152 147  
... ... @@ -165,15 +160,26 @@
165 160 *count = 0;
166 161 st = NULL;
167 162 }
168   -//unsigned int i;
169   -//for (i=0; i < he->c; i++) {
170   -//fprintf(stderr," headerGetStringArrayEntry tag:%d string %d/%d:%s\n", he->tag, i+1, he->c, st[i]);
171   -//}
172 163 he->p.ptr = _free(he->p.ptr);
173 164 #else
174   - st = headerGetString(h, tag);
  165 + rpmtd td = rpmtdNew();
  166 + int i = 0;
  167 + *count = 0;
  168 + if (headerGet(h, tag, td, HEADERGET_MINMEM) && rpmtdType(td) == RPM_STRING_ARRAY_TYPE && rpmtdCount(td) >= 1) {
  169 + *count = rpmtdCount(td);
  170 + if (*count > 0) {
  171 + st = malloc(sizeof(char*) * *count);
  172 + const char* str;
  173 + rpmtdInit(td);
  174 + while ((str = rpmtdNextString(td))) {
  175 + st[i] = strdup(str);
  176 + i++;
  177 + }
  178 + rpmtdFree(td);
  179 + }
  180 + }
175 181 #endif
176   - return st;
  182 + return st;
177 183 }
178 184  
179 185 long long headerGetUIntEntry(Header h, const int tag) {
... ... @@ -203,9 +209,6 @@
203 209 break;
204 210 }
205 211 }
206   -
207   -//fprintf(stderr," headerGetUIntEntry tag:%d uint %lld\n", he->tag, ret);
208   -
209 212 he->p.ptr = _free(he->p.ptr);
210 213 #else
211 214 ret = headerGetNumber(h, tag);
212 215  
213 216  
... ... @@ -213,16 +216,15 @@
213 216 return ret;
214 217 }
215 218  
216   -void *headerGetUIntArrayEntry(Header h, const int tag, int *count) {
  219 +uint_32 *headerGetUIntArrayEntry(Header h, const int tag, int *count) {
  220 + uint_32 *ret = NULL;
217 221  
218   - void *ret = NULL;
219   -
220 222 #if RPM_VERSION_MAJOR >= 0x050000
221 223 HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
222 224 he->tag = tag;
223 225 if (headerGet(h, he, 0) && he->c >= 1) {
224 226 *count = he->c;
225   - switch (he->t) {
  227 + switch (he->t) {
226 228 case RPM_UINT8_TYPE:
227 229 ret = memndup(he->p.ui8p, *count);
228 230 break;
... ... @@ -231,10 +233,6 @@
231 233 break;
232 234 case RPM_UINT32_TYPE:
233 235 ret = memndup(he->p.ui32p, *count * 4);
234   -//int i;
235   -//for (i=0; i<he->c; i++) {
236   -// printf("%d ",((int_32 *)ret)[i]);
237   -//}
238 236 break;
239 237 case RPM_UINT64_TYPE:
240 238 ret = memndup(he->p.ui64p, *count * 8);
241 239  
... ... @@ -244,14 +242,38 @@
244 242 break;
245 243 }
246 244 }
247   -
248   -/*unsigned int i;
249   -for (i=0; i < he->c; i++) {
250   -fprintf(stderr," headerGetUIntArrayEntry tag:%d value:%ld\n", he->tag, ((rpmuint32_t*)ret)[i]);
251   -}*/
252 245 he->p.ptr = _free(he->p.ptr);
253 246 #else
254   - ret = headerGetNumber(h, tag);
  247 + rpmtd td = rpmtdNew();
  248 + int i = 0;
  249 + if (headerGet(h, tag, td, HEADERGET_MINMEM)) {
  250 + *count = rpmtdCount(td);
  251 + ret = malloc(sizeof(uint_32) * *count);
  252 + rpmtdInit(td);
  253 + while (rpmtdNext(td) >= 0) {
  254 + switch (td->type) {
  255 + case RPM_INT8_TYPE:
  256 + ret[i] = (uint_32)*rpmtdGetChar(td);
  257 + break;
  258 + case RPM_INT16_TYPE:
  259 + ret[i] = (uint_32)*rpmtdGetUint16(td);
  260 + break;
  261 + case RPM_INT32_TYPE:
  262 + ret[i] = (uint_32)*rpmtdGetUint32(td);
  263 + break;
  264 + case RPM_INT64_TYPE:
  265 + fprintf(stderr,"headerGetUIntArrayEntry: uint_64 type converted to uint_32");
  266 + ret[i] = (uint_32)*rpmtdGetUint64(td);
  267 + break;
  268 + default:
  269 + break;
  270 + }
  271 + i++;
  272 + }
  273 + rpmtdFree(td);
  274 + } else {
  275 + *count = 0;
  276 + }
255 277 #endif
256 278 return ret;
257 279 }
... ... @@ -290,7 +312,7 @@
290 312 }
291 313  
292 314 int
293   -getPackageFiles(Header h, int **dirindexes,
  315 +getPackageFiles(Header h, uint_32 **dirindexes,
294 316 char ***dirnames, int *dirnamescount,
295 317 char ***basenames, int *filenamescount,
296 318 char ***usernames, char ***groupnames,
297 319  
... ... @@ -373,13 +395,16 @@
373 395 return s;
374 396 }
375 397  
  398 +sem_t getRPMMutex() {
  399 + return rpm_mutex;
  400 +}
  401 +
376 402 void rpminit() {
377 403 #if RPM_VERSION >= 0x040100
378 404 rpmReadConfigFiles(NULL, NULL);
379 405 // ts = rpmtsCreate();
380 406 // rpmtsSetVSFlags(ts, (rpmVSFlags_e)-1);
381 407 #endif
382   - sem_t rpm_mutex;
383 408 sem_init(&rpm_mutex, 0, 1);
384 409 }