Runtime fixes after rpm 4 migration

This commit is contained in:
Silvan Calarco 2020-06-19 10:03:30 +02:00
parent 2bca22fae3
commit b14c9271cf
7 changed files with 88 additions and 66 deletions

View File

@ -44,7 +44,7 @@ target_link_libraries(distromatic
${LIBIBERTY}
)
target_include_directories(distromatic PUBLIC ${RPM_INCLUDE_DIRS})
target_compile_options(distromatic PUBLIC ${RPM_CFLAGS_OTHER})
target_compile_options(distromatic PUBLIC -g -Wall -std=gnu11 -pedantic ${RPM_CFLAGS_OTHER})
add_executable(distroquery
distroquery.c

View File

@ -28,12 +28,10 @@
# include <strings.h>
#endif
#ifndef BUILDTOOLS_H
# include "buildtools.h"
#endif
#ifndef DISTROMATIC_H
# include "distromatic.h"
#endif
#include <linux/limits.h>
#include "distromatic.h"
#include "buildtools.h"
int
generateBuildInfo(struct configTag *configtag, int arch)

View File

@ -39,6 +39,8 @@
# include <strings.h>
#endif
#include <string.h>
#include "distromatic.h"
#include "config.h"
#include "changelog.h"
@ -137,6 +139,7 @@ getPackageChangelog(Header h, struct headerSourceList* headersource)
if (oldchangelog) {
oldchangelog->next = newchangelog;
}
newchangelog->time = changelogtime[i];
strncpy(changelogname, changelogrelease[i], 255);

View File

@ -405,7 +405,7 @@ void logmsg(int level, const char *msg, ...) {
for (i = 0; i < 20; i++) {
/* only log the same message once */
if (!strncmp(newmsg,(char*)&(oldmsg[i]),256)) return;
}
}
switch (level) {
case LOG_MARK:

View File

@ -216,29 +216,28 @@ getPackageInfoIntoHeaderSourceList(Header h, struct headerSourceList *hl)
hl->arch = headerGetStringEntry(h, RPMTAG_ARCH);
hl->buildarchs = headerGetStringEntry(h, RPMTAG_BUILDARCHS);
hl->excludearch = headerGetStringEntry(h, RPMTAG_EXCLUDEARCH);
if (hl->buildarchs) printf("buildarchs: %s %s\n",hl->name,hl->buildarchs);
if (hl->excludearch) printf("excludearch: %s %s\n",hl->name,hl->excludearch);
hl->description = headerGetStringEntry(h, RPMTAG_DESCRIPTION);
packager = headerGetStringEntry(h, RPMTAG_PACKAGER);
if (!packager) {
logmsg(LOG_WARNING,"missing packager definition in package %s.",hl->name);
hl->packager = NULL;
hl->packager = NULL;
} else {
hl->packager = getPackagerByName(packager,1);
if (!hl->packager) {
logmsg(LOG_WARNING,"cannot create '%s' packager for package %s.",packager,hl->name);
free(packager);
}
/* if (! (hl->packager->role && PACKAGER_ROLE_MAINTAINER)) {
logmsg(LOG_WARNING,"%s is an unmaintained package.",hl->name,hl->packager->name,hl->packager->role);
}*/
}
free(packager);
hl->group = headerGetStringEntry(h, RPMTAG_GROUP);
hl->license = headerGetStringEntry(h, RPMTAG_LICENSE);
hl->url = headerGetStringEntry(h, RPMTAG_URL);
if (!hl->url)
logmsg(LOG_WARNING,"missing URL definition for package %s.",hl->name);
hl->buildtime = headerGetUIntEntry(h, RPMTAG_BUILDTIME);
hl->source = headerGetStringArrayEntry(h, RPMTAG_SOURCE, &count);
hl->patch = headerGetStringArrayEntry(h, RPMTAG_PATCH, &count);
hl->size = headerGetUIntEntry(h, RPMTAG_SIZE);
@ -621,19 +620,15 @@ addToSourceHeaderList(struct headerSourceList **headersourcelist, struct configT
struct changeLog *changelog;
Header h;
char filepath[bufsize + 1];
int n, j, arch, *dirindexes, filenamescount, dirnamescount;
int n, j, arch, filenamescount, dirnamescount;
int_16 *fileflags;
char **basenames, **dirnames, **usernames, **groupnames;
const char* errstr;
int requirecount;
char **requireversion, **requirename;
uint_32 *requireflags;
uint_32 *requireflags, *dirindexes;
char warning[PATH_MAX];
#if RPM_VERSION >= 0x050000
rpmts ts = rpmtsCreate();
#else
rpmts ts = NULL;
#endif
if (altrepository == ct->repository_level) {
scanpath = ct->repository_source_dir;
@ -666,12 +661,12 @@ addToSourceHeaderList(struct headerSourceList **headersourcelist, struct configT
strcpy(&filepath[strlen(scanpath)], namelist[cnt]->d_name);
logmsg(LOG_DEBUG, "getting header for %s", filepath);
if (getHeader(&ts, filepath, &h)) {
if (getHeader(&ts, filepath, &h)) {
errstr = strerror(errno);
logmsg(LOG_WARNING,
"%s: unable to read header (%s); skipping.",namelist[cnt]->d_name, errstr);
} else {
} else {
getPackageFiles(h, &dirindexes, &dirnames, &dirnamescount,
&basenames, &filenamescount,
&usernames, &groupnames, &fileflags);
@ -692,6 +687,7 @@ addToSourceHeaderList(struct headerSourceList **headersourcelist, struct configT
newheadersourcelist->firstrebuild = NULL;
newheadersourcelist->old = NULL;
newheadersourcelist->id = ++sourceid;
getPackageInfoIntoHeaderSourceList(h, newheadersourcelist);
@ -813,9 +809,7 @@ addToSourceHeaderList(struct headerSourceList **headersourcelist, struct configT
} // for
free(namelist);
#if RPM_VERSION >= 0x050000
rpmtsFree(ts);
#endif
return 0;
}
@ -871,8 +865,7 @@ addToHeaderList(struct configTag *ct,
char *filename=NULL;
long i ,j , k, n, altn[ALT_REPS_MAX];
int altrepository=0, obsoletecount, providecount, requirecount,
filenamecount, dirnamecount,
*dirindex;
filenamecount, dirnamecount;
int_16 *fileflags;
char **obsoletename, **obsoleteversion,
**providename, **provideversion,
@ -880,7 +873,7 @@ addToHeaderList(struct configTag *ct,
**basename, **dirname, **newversion,
**fileusername, **filegroupname;
const char* errstr;
uint_32 *requireflags, *obsoleteflags, *provideflags;
uint_32 *dirindex, *requireflags, *obsoleteflags, *provideflags;
#if RPM_VERSION >= 0x050000
rpmts ts = rpmtsCreate();
#else
@ -978,7 +971,8 @@ addToHeaderList(struct configTag *ct,
/* process package */
logmsg(LOG_DEBUG, "getting header for %s", filepath);
sem_t rpm_mutex;
sem_t rpm_mutex = getRPMMutex();
sem_wait(&rpm_mutex);
if (getHeader(&ts, filepath, &h)) {
sem_post(&rpm_mutex);

View File

@ -48,7 +48,7 @@ char **headerGetStringArrayEntry(Header h, const int tag, int* count);
long long headerGetUIntEntry(Header h, const int tag);
void *headerGetUIntArrayEntry(Header h, const int tag, int *count);
uint_32 *headerGetUIntArrayEntry(Header h, const int tag, int *count);
int getHeader(rpmts *ts, char *headerFile, Header * h);
@ -65,7 +65,7 @@ int getPackageObsoletes(
char ***obsoleteversion, int *obsoletecount);
int
getPackageFiles(Header h, int **dirindexes,
getPackageFiles(Header h, uint_32 **dirindexes,
char ***dirnames, int *dirnamescount,
char ***basenames, int *filenamescount,
char ***usernames, char ***groupnames,
@ -77,4 +77,6 @@ int scanrpmnamecmp(const struct dirent **f1, const struct dirent **f2);
char* printrpmversion(char *s, int bufsize, long epoch, char *version, char *release);
sem_t getRPMMutex();
#endif // RPMFUNCTIONS_H

View File

@ -29,14 +29,13 @@
#endif
#include <fcntl.h>
#include <zlib.h>
#include <libiberty/libiberty.h>
#include "functions.h"
#ifndef RPMFUNCTIONS_H
# include "rpmfunctions.h"
#endif
#include "functions.h"
#include "rpmfunctions.h"
sem_t rpm_mutex;
/*
* static int getPackageInfo(
@ -104,7 +103,6 @@ getHeader(rpmts* ts, char *headerFile, Header * h)
if (fd == NULL || Ferror(fd)) {
return 1;
}
int rc;
#if RPM_VERSION >= 0x040100
@ -116,7 +114,6 @@ getHeader(rpmts* ts, char *headerFile, Header * h)
#endif
#if RPM_VERSION >= 0x040100
if (rc != RPMRC_OK && rc != RPMRC_NOTTRUSTED && rc != RPMRC_NOKEY) {
// fprintf(stderr, "Error: Failed reading file %s\n", headerFile);
#else
if (rc != 0) {
#endif
@ -130,21 +127,19 @@ getHeader(rpmts* ts, char *headerFile, Header * h)
char *
headerGetStringEntry(Header h, const int tag)
{
const char *st = NULL;
char *st = NULL;
#if RPM_VERSION_MAJOR >= 0x050000
HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
he->tag = tag;
if (headerGet(h, he, 0) && he->t == RPM_STRING_TYPE && he->c == 1)
st = xstrdup(he->p.str);
st = strdup(he->p.str);
else
st = NULL;
//printf(" headerGetStringEntry tag:%d st:%s\n", he->tag, st);
he->p.ptr = _free(he->p.ptr);
#else
st = headerGetString(h, tag);
st = headerGetAsString(h, tag);
#endif
return st;
}
@ -165,15 +160,26 @@ headerGetStringArrayEntry(Header h, const int tag, int* count)
*count = 0;
st = NULL;
}
//unsigned int i;
//for (i=0; i < he->c; i++) {
//fprintf(stderr," headerGetStringArrayEntry tag:%d string %d/%d:%s\n", he->tag, i+1, he->c, st[i]);
//}
he->p.ptr = _free(he->p.ptr);
#else
st = headerGetString(h, tag);
rpmtd td = rpmtdNew();
int i = 0;
*count = 0;
if (headerGet(h, tag, td, HEADERGET_MINMEM) && rpmtdType(td) == RPM_STRING_ARRAY_TYPE && rpmtdCount(td) >= 1) {
*count = rpmtdCount(td);
if (*count > 0) {
st = malloc(sizeof(char*) * *count);
const char* str;
rpmtdInit(td);
while ((str = rpmtdNextString(td))) {
st[i] = strdup(str);
i++;
}
rpmtdFree(td);
}
}
#endif
return st;
return st;
}
long long headerGetUIntEntry(Header h, const int tag) {
@ -203,9 +209,6 @@ long long headerGetUIntEntry(Header h, const int tag) {
break;
}
}
//fprintf(stderr," headerGetUIntEntry tag:%d uint %lld\n", he->tag, ret);
he->p.ptr = _free(he->p.ptr);
#else
ret = headerGetNumber(h, tag);
@ -213,16 +216,15 @@ long long headerGetUIntEntry(Header h, const int tag) {
return ret;
}
void *headerGetUIntArrayEntry(Header h, const int tag, int *count) {
void *ret = NULL;
uint_32 *headerGetUIntArrayEntry(Header h, const int tag, int *count) {
uint_32 *ret = NULL;
#if RPM_VERSION_MAJOR >= 0x050000
HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
he->tag = tag;
if (headerGet(h, he, 0) && he->c >= 1) {
*count = he->c;
switch (he->t) {
switch (he->t) {
case RPM_UINT8_TYPE:
ret = memndup(he->p.ui8p, *count);
break;
@ -231,10 +233,6 @@ void *headerGetUIntArrayEntry(Header h, const int tag, int *count) {
break;
case RPM_UINT32_TYPE:
ret = memndup(he->p.ui32p, *count * 4);
//int i;
//for (i=0; i<he->c; i++) {
// printf("%d ",((int_32 *)ret)[i]);
//}
break;
case RPM_UINT64_TYPE:
ret = memndup(he->p.ui64p, *count * 8);
@ -244,14 +242,38 @@ void *headerGetUIntArrayEntry(Header h, const int tag, int *count) {
break;
}
}
/*unsigned int i;
for (i=0; i < he->c; i++) {
fprintf(stderr," headerGetUIntArrayEntry tag:%d value:%ld\n", he->tag, ((rpmuint32_t*)ret)[i]);
}*/
he->p.ptr = _free(he->p.ptr);
#else
ret = headerGetNumber(h, tag);
rpmtd td = rpmtdNew();
int i = 0;
if (headerGet(h, tag, td, HEADERGET_MINMEM)) {
*count = rpmtdCount(td);
ret = malloc(sizeof(uint_32) * *count);
rpmtdInit(td);
while (rpmtdNext(td) >= 0) {
switch (td->type) {
case RPM_INT8_TYPE:
ret[i] = (uint_32)*rpmtdGetChar(td);
break;
case RPM_INT16_TYPE:
ret[i] = (uint_32)*rpmtdGetUint16(td);
break;
case RPM_INT32_TYPE:
ret[i] = (uint_32)*rpmtdGetUint32(td);
break;
case RPM_INT64_TYPE:
fprintf(stderr,"headerGetUIntArrayEntry: uint_64 type converted to uint_32");
ret[i] = (uint_32)*rpmtdGetUint64(td);
break;
default:
break;
}
i++;
}
rpmtdFree(td);
} else {
*count = 0;
}
#endif
return ret;
}
@ -290,7 +312,7 @@ getPackageObsoletes(Header h, char ***obsoletename, uint_32 **obsoleteflags,
}
int
getPackageFiles(Header h, int **dirindexes,
getPackageFiles(Header h, uint_32 **dirindexes,
char ***dirnames, int *dirnamescount,
char ***basenames, int *filenamescount,
char ***usernames, char ***groupnames,
@ -373,12 +395,15 @@ char* printrpmversion(char *s, int bufsize, long epoch, char *version, char *rel
return s;
}
sem_t getRPMMutex() {
return rpm_mutex;
}
void rpminit() {
#if RPM_VERSION >= 0x040100
rpmReadConfigFiles(NULL, NULL);
// ts = rpmtsCreate();
// rpmtsSetVSFlags(ts, (rpmVSFlags_e)-1);
#endif
sem_t rpm_mutex;
sem_init(&rpm_mutex, 0, 1);
}