diff --git a/src/headerlist.c b/src/headerlist.c index 758e21d..08c68df 100644 --- a/src/headerlist.c +++ b/src/headerlist.c @@ -971,11 +971,7 @@ addToHeaderList(struct configTag *ct, /* process package */ logmsg(LOG_DEBUG, "getting header for %s", filepath); - sem_t rpm_mutex = getRPMMutex(); - - sem_wait(&rpm_mutex); if (getHeader(&ts, filepath, &h)) { - sem_post(&rpm_mutex); errstr = strerror(errno); logmsg(LOG_WARNING, "%s: unable to read header (%s); skipping.",filename, errstr); @@ -998,7 +994,6 @@ addToHeaderList(struct configTag *ct, } memset(newheaderlist, 0, sizeof(struct headerList)); getPackageInfoIntoHeaderList(h, newheaderlist); - sem_post(&rpm_mutex); if (!newheaderlist->sourcename) { logmsg(LOG_WARNING, diff --git a/src/include/rpmfunctions.h b/src/include/rpmfunctions.h index d0e87dd..bcc1e07 100644 --- a/src/include/rpmfunctions.h +++ b/src/include/rpmfunctions.h @@ -33,7 +33,6 @@ #endif #endif -#include #include #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); -sem_t getRPMMutex(); - #endif // RPMFUNCTIONS_H diff --git a/src/rpmfunctions.c b/src/rpmfunctions.c index 8f7c659..f2fcb67 100644 --- a/src/rpmfunctions.c +++ b/src/rpmfunctions.c @@ -28,6 +28,7 @@ # include #endif +#include #include #include #include @@ -35,38 +36,59 @@ #include "functions.h" #include "rpmfunctions.h" -sem_t rpm_mutex; - /* * static int getPackageInfo( * Header h, char **name, char **version, char **release, * 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) { int vercmp = 0; -#if RPM_VERSION_MAJOR >= 5 - struct EVR_s evr1, evr2; + struct EVR_s evr1, evr2; - sem_wait(&rpm_mutex); - rpmEVRparse(cmp1, &evr1); - rpmEVRparse(cmp2, &evr2); - sem_post(&rpm_mutex); + rpmEVRsplit(cmp1, &evr1); + rpmEVRsplit(cmp2, &evr2); - if (strlen(evr1.F[RPMEVR_E]) && strlen(evr2.F[RPMEVR_E])) vercmp=rpmvercmp(evr1.F[RPMEVR_E], evr2.F[RPMEVR_E]); - else if (strlen(evr2.F[RPMEVR_E])) vercmp = -1; - else if (strlen(evr1.F[RPMEVR_E])) vercmp = 1; + if (evr1.e == evr2.e) vercmp = 0; + else if (evr1.e > evr2.e) vercmp = 1; + else vercmp = -1; - if (!vercmp) vercmp=rpmvercmp(evr1.F[RPMEVR_V], evr2.F[RPMEVR_V]); - if (!vercmp && strlen(evr1.F[RPMEVR_R]) && strlen(evr2.F[RPMEVR_R])) vercmp=rpmvercmp(evr1.F[RPMEVR_R], evr2.F[RPMEVR_R]); -#else - vercmp=rpmvercmp(cmp1, cmp2); -#endif + if (vercmp == 0) vercmp = rpmvercmp(evr1.v, evr2.v); + if (vercmp == 0 && evr1.r && evr2.r) vercmp = rpmvercmp(evr1.r, evr2.r); - if ((vercmp == 0) && (flags & RPMSENSE_EQUAL)) return 1; - else if ((vercmp == 1) && (flags & RPMSENSE_LESS)) return 1; - else if ((vercmp == -1) && (flags & RPMSENSE_GREATER)) return 1; + free(evr1.data); + free(evr2.data); - return 0; + if ((vercmp == 0) && (flags & RPMSENSE_EQUAL)) return 1; + else if ((vercmp == 1) && (flags & RPMSENSE_LESS)) return 1; + else if ((vercmp == -1) && (flags & RPMSENSE_GREATER)) return 1; + + return 0; } /* @@ -394,15 +416,10 @@ 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_init(&rpm_mutex, 0, 1); }