Fix checkVersionWithFlags for rpm 4 and remove semaphore handlings

This commit is contained in:
Silvan Calarco 2020-06-19 14:20:27 +02:00
parent 61352c7c3e
commit 8836c8f87b
3 changed files with 42 additions and 33 deletions

View File

@ -971,11 +971,7 @@ addToHeaderList(struct configTag *ct,
/* process package */ /* process package */
logmsg(LOG_DEBUG, "getting header for %s", filepath); logmsg(LOG_DEBUG, "getting header for %s", filepath);
sem_t rpm_mutex = getRPMMutex();
sem_wait(&rpm_mutex);
if (getHeader(&ts, filepath, &h)) { if (getHeader(&ts, filepath, &h)) {
sem_post(&rpm_mutex);
errstr = strerror(errno); errstr = strerror(errno);
logmsg(LOG_WARNING, logmsg(LOG_WARNING,
"%s: unable to read header (%s); skipping.",filename, errstr); "%s: unable to read header (%s); skipping.",filename, errstr);
@ -998,7 +994,6 @@ addToHeaderList(struct configTag *ct,
} }
memset(newheaderlist, 0, sizeof(struct headerList)); memset(newheaderlist, 0, sizeof(struct headerList));
getPackageInfoIntoHeaderList(h, newheaderlist); getPackageInfoIntoHeaderList(h, newheaderlist);
sem_post(&rpm_mutex);
if (!newheaderlist->sourcename) { if (!newheaderlist->sourcename) {
logmsg(LOG_WARNING, logmsg(LOG_WARNING,

View File

@ -33,7 +33,6 @@
#endif #endif
#endif #endif
#include <semaphore.h>
#include <dirent.h> #include <dirent.h>
#define HEADERS_BUFFER_SIZE 2000000 #define HEADERS_BUFFER_SIZE 2000000
@ -77,6 +76,4 @@ int scanrpmnamecmp(const struct dirent **f1, const struct dirent **f2);
char* printrpmversion(char *s, int bufsize, long epoch, char *version, char *release); char* printrpmversion(char *s, int bufsize, long epoch, char *version, char *release);
sem_t getRPMMutex();
#endif // RPMFUNCTIONS_H #endif // RPMFUNCTIONS_H

View File

@ -28,6 +28,7 @@
# include <strings.h> # include <strings.h>
#endif #endif
#include <stdlib.h>
#include <fcntl.h> #include <fcntl.h>
#include <zlib.h> #include <zlib.h>
#include <libiberty/libiberty.h> #include <libiberty/libiberty.h>
@ -35,32 +36,53 @@
#include "functions.h" #include "functions.h"
#include "rpmfunctions.h" #include "rpmfunctions.h"
sem_t rpm_mutex;
/* /*
* static int getPackageInfo( * static int getPackageInfo(
* Header h, char **name, char **version, char **release, * Header h, char **name, char **version, char **release,
* char **summary); */ * char **summary); */
struct EVR_s {
char *data;
uint32_t e;
char *v;
char *r;
} EVR;
void rpmEVRsplit(const char* ver, struct EVR_s *evr) {
evr->e = 0;
evr->v = NULL;
evr->r = NULL;
evr->data = strdup(ver);
for (int i = 0; i < strlen(ver); i++) {
if (evr->data[i] == ':') {
evr->e = strtoul(ver, NULL, 10);
evr->data[i] = '\0';
evr->v = &evr->data[i+1];
} else if (evr->data[i] == '-') {
evr->data[i] = '\0';
evr->r = &evr->data[i+1];
if (evr->v == NULL) evr->v = evr->data;
}
}
if (evr->v == NULL) evr->v = evr->data;
}
unsigned int checkVersionWithFlags(const char* cmp1, uint_32 flags, const char* cmp2) { unsigned int checkVersionWithFlags(const char* cmp1, uint_32 flags, const char* cmp2) {
int vercmp = 0; int vercmp = 0;
#if RPM_VERSION_MAJOR >= 5
struct EVR_s evr1, evr2; struct EVR_s evr1, evr2;
sem_wait(&rpm_mutex); rpmEVRsplit(cmp1, &evr1);
rpmEVRparse(cmp1, &evr1); rpmEVRsplit(cmp2, &evr2);
rpmEVRparse(cmp2, &evr2);
sem_post(&rpm_mutex);
if (strlen(evr1.F[RPMEVR_E]) && strlen(evr2.F[RPMEVR_E])) vercmp=rpmvercmp(evr1.F[RPMEVR_E], evr2.F[RPMEVR_E]); if (evr1.e == evr2.e) vercmp = 0;
else if (strlen(evr2.F[RPMEVR_E])) vercmp = -1; else if (evr1.e > evr2.e) vercmp = 1;
else if (strlen(evr1.F[RPMEVR_E])) vercmp = 1; else vercmp = -1;
if (!vercmp) vercmp=rpmvercmp(evr1.F[RPMEVR_V], evr2.F[RPMEVR_V]); if (vercmp == 0) vercmp = rpmvercmp(evr1.v, evr2.v);
if (!vercmp && strlen(evr1.F[RPMEVR_R]) && strlen(evr2.F[RPMEVR_R])) vercmp=rpmvercmp(evr1.F[RPMEVR_R], evr2.F[RPMEVR_R]); if (vercmp == 0 && evr1.r && evr2.r) vercmp = rpmvercmp(evr1.r, evr2.r);
#else
vercmp=rpmvercmp(cmp1, cmp2); free(evr1.data);
#endif free(evr2.data);
if ((vercmp == 0) && (flags & RPMSENSE_EQUAL)) return 1; if ((vercmp == 0) && (flags & RPMSENSE_EQUAL)) return 1;
else if ((vercmp == 1) && (flags & RPMSENSE_LESS)) return 1; else if ((vercmp == 1) && (flags & RPMSENSE_LESS)) return 1;
@ -394,15 +416,10 @@ char* printrpmversion(char *s, int bufsize, long epoch, char *version, char *rel
return s; return s;
} }
sem_t getRPMMutex() {
return rpm_mutex;
}
void rpminit() { void rpminit() {
#if RPM_VERSION >= 0x040100 #if RPM_VERSION >= 0x040100
rpmReadConfigFiles(NULL, NULL); rpmReadConfigFiles(NULL, NULL);
// ts = rpmtsCreate(); // ts = rpmtsCreate();
// rpmtsSetVSFlags(ts, (rpmVSFlags_e)-1); // rpmtsSetVSFlags(ts, (rpmVSFlags_e)-1);
#endif #endif
sem_init(&rpm_mutex, 0, 1);
} }