From 39af94aa1d9bcc021c8090ce8047d8bae8737963 Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Tue, 16 Feb 2021 20:24:29 +0100 Subject: [PATCH] Fixes for recent and old bugs --- src/CMakeLists.txt | 4 ++-- src/distromatic.c | 20 ++++++++++++-------- src/functions.c | 2 +- src/headerlist.c | 43 ++++++++++++++++++++++++++++++++----------- src/reports.c | 36 ------------------------------------ 5 files changed, 47 insertions(+), 58 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 159d4ad..41feb4b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,8 +61,8 @@ target_include_directories(distromatic PUBLIC # # NOTE: -fno-toplevel-reorder required to prevent Sqlite3 weird problems # -target_compile_options(distromatic PUBLIC -O2 -fno-toplevel-reorder -g -Wall -std=gnu11 -pedantic ${RPM_CFLAGS_OTHER}) - +target_compile_options(distromatic PUBLIC -O2 -g -Wall -std=gnu11 -pedantic ${RPM_CFLAGS_OTHER}) +# -fno-toplevel-reorder add_executable(distroquery distroquery.c functions.c diff --git a/src/distromatic.c b/src/distromatic.c index f24fd6c..19219cd 100644 --- a/src/distromatic.c +++ b/src/distromatic.c @@ -944,6 +944,7 @@ main(int argc, char *argv[]) int i = 0,hasbuilds[ARCHS_MAX],ptharg[ARCHS_MAX]; int parallel = 0; + int current_archs = 0; pthread_t pth[ARCHS_MAX]; char warning[8096]; @@ -1123,13 +1124,13 @@ main(int argc, char *argv[]) } if (passed_arch) { - configtag->arch[0] = malloc(sizeof passed_arch); - if (!configtag->arch[0]) { - fprintf(stderr, "The system is out of memory\n"); - exit(1); - } - strcpy(configtag->arch[0], passed_arch); - configtag->arch[1] = NULL; + configtag->arch[0] = malloc(sizeof passed_arch); + if (!configtag->arch[0]) { + fprintf(stderr, "The system is out of memory\n"); + exit(1); + } + strcpy(configtag->arch[0], passed_arch); + configtag->arch[1] = NULL; } rpminit(); @@ -1190,7 +1191,10 @@ main(int argc, char *argv[]) pthread_join(pth[i], NULL); } - if (!passed_arch) { // can't do missing builds and ports check in single arch mode + for (i = 0; i < ARCHS_MAX && configtag->arch[i]; i++) + current_archs++; + + if (current_archs > 1) { // can't do missing builds and ports check in single arch mode if (!quietmode) fprintf(stdout, "Checking for SRPMS with no builds and missing ports...\n"); else diff --git a/src/functions.c b/src/functions.c index 05bd673..0e1b1ff 100644 --- a/src/functions.c +++ b/src/functions.c @@ -480,7 +480,7 @@ void logmsg(int level, const char *msg, ...) { break; } if ((level == LOG_WARNING) || (level == LOG_ERROR)) { - strncpy(oldmsg[curroldmsg++],newmsg,PATH_MAX); + strncpy(oldmsg[curroldmsg++],newmsg,256); if (curroldmsg >= 20) curroldmsg = 0; } } diff --git a/src/headerlist.c b/src/headerlist.c index 839e2bd..943d8e5 100644 --- a/src/headerlist.c +++ b/src/headerlist.c @@ -664,8 +664,8 @@ struct repoData* getRepodata(char *repodata_url, char *arch) { ret = lr_handle_perform(h, r, &tmp_err); if (!ret) { - logmsg(LOG_ERROR, "cannot get repodata: %d: %s\n", - tmp_err->code, tmp_err->message); + logmsg(LOG_ERROR, "cannot get repodata from %s: %d: %s\n", + urls[0], tmp_err->code, tmp_err->message); g_error_free(tmp_err); lr_result_free(r); lr_handle_free(h); @@ -1001,17 +1001,26 @@ int addToSourceHeaderList(struct configTag *ct, int mode, int altrepository) { if (altrepository == ct->repository_level) { scanpath = ct->repository_source_dir; - if (ct->repodata_url) repodata = getRepodata(ct->repodata_url, NULL); + if (ct->repodata_url) { + repodata = getRepodata(ct->repodata_url, NULL); + if (!repodata) return 1; + } logmsg(LOG_DEBUG,"Scanning source packages in repository %s...", ct->tag); } else if (altrepository == -1) { // non-incremental mode scanpath = ct->repository_source_dir; altrepository = 0; - if (ct->repodata_url) repodata = getRepodata(ct->repodata_url, NULL); + if (ct->repodata_url) { + repodata = getRepodata(ct->repodata_url, NULL); + if (!repodata) return 1; + } logmsg(LOG_DEBUG,"Scanning source packages in repository %s...", ct->tag); } else { scanpath = ct->repository[altrepository]->repository_source_dir; - if (ct->repodata_url) repodata = getRepodata(ct->repository[altrepository]->repodata_url, NULL); + if (ct->repodata_url) { + repodata = getRepodata(ct->repository[altrepository]->repodata_url, NULL); + if (!repodata) return 1; + } logmsg(LOG_DEBUG,"Scanning source packages in repository %s...", ct->repository[altrepository]->tag); } if (repodata) { @@ -1412,18 +1421,28 @@ char* advanceXMLPackageNode(char* prevname, xmlNode **primary_node, if (ct->repository[0]) { snprintf(scanpath,bufsize,"%sRPMS.%s/",ct->repository[0]->repository_dir,ct->arch[arch]); scantag = ct->repository[0]->tag; - if (ct->repository[0]->repodata_url) repodata[0] = getRepodata( - ct->repository[0]->repodata_url, ct->arch[arch]); + if (ct->repository[0]->repodata_url) { + repodata[0] = getRepodata(ct->repository[0]->repodata_url, + ct->arch[arch]); + if (!repodata[0]) return 1; + } for (i = 1; i <= ct->repository_level; i++) { if (ct->repository[i]) { altscanpath[i-1] = malloc(bufsize); snprintf(altscanpath[i-1], bufsize, "%sRPMS.%s/",ct->repository[i]->repository_dir,ct->arch[arch]); altscantag[i-1] = ct->repository[i]->tag; if (ct->repository[i]->repodata_url) { - if (!repodata[0]) logmsg(LOG_ERROR, - "repodata_url must be defined in main and parent repositories; aborting."); + if (!repodata[0]) { + logmsg(LOG_ERROR, + "repodata_url must be defined in main and parent repositories; aborting."); + return 1; + } repodata[i] = getRepodata( ct->repository[i]->repodata_url, ct->arch[arch]); + if (!repodata[i]) { + cleanRepodata(repodata[0]); + return 1; + } } alt_reps_num++; } else { @@ -1438,8 +1457,10 @@ char* advanceXMLPackageNode(char* prevname, xmlNode **primary_node, } else { snprintf(scanpath,bufsize,"%sRPMS.%s/",ct->repository_dir,ct->arch[arch]); scantag = ct->tag; - if (ct->repodata_url) repodata[0] = getRepodata(ct->repodata_url, - ct->arch[arch]); + if (ct->repodata_url) { + repodata[0] = getRepodata(ct->repodata_url, ct->arch[arch]); + if (!repodata[0]) return 1; + } } currheaderlist = ct->headerlist[arch]; diff --git a/src/reports.c b/src/reports.c index 83c45be..ad117cd 100644 --- a/src/reports.c +++ b/src/reports.c @@ -679,42 +679,6 @@ generateStats(struct configTag *configtag,int arch) fclose(htmlout); } - /* create Smart Package Manager channel file */ - snprintf(outfile, PATH_MAX, "%s%s-%s.smart", - configtag->html_dir, - configtag->configdefaults->distribution_name, - configtag->tag); - - if ((htmlout = fopen(outfile, "w")) == NULL) { - perror(outfile); - return 1; - } else { - /* remove final slashes from download_prefix as required by apt */ - strcpy(buffer, configtag->download_dir); - - i=strlen(buffer); - while ((i > 0) && (buffer[i-1] == '/' )) { - buffer[i-1]='\0'; - i--; - } - - fprintf(htmlout, "#\n# %s %s channel configuration for Smart Package Manager\n#\n\n", - configtag->configdefaults->distribution_name, - configtag->tag); - fprintf(htmlout, "[%s]\ntype = apt-rpm\n", - configtag->tag); - fprintf(htmlout, "name = %s\n", - configtag->description); - fprintf(htmlout, "baseurl = http://%s%s\n", - configtag->configdefaults->url_address, buffer); - fprintf(htmlout, "components ="); - for (i = 0; i < ARCHS_MAX; i++) { - if (configtag->arch[i]) fprintf(htmlout," %s", configtag->arch[i]); - } - fprintf(htmlout, "\n"); - fclose(htmlout); - } - /* create Changelog page */ struct tm tmdate; tmdate.tm_min = 0;