From f7aff1193e7a27b631030f332ecfe87046853903 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Mon, 8 Jan 2018 12:30:37 +0200 Subject: [PATCH] Track and log failures when loading macro files It's much easier for rpm to point out the location of invalid macro definitions than it is for humans to grep all the places a given rpm version might look at. Log the macro file path once per file in case of failures, and additionally return and error if all definitions fail. Based on patch by Pavlina Moravcova Varekova. --- rpmio/macro.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/rpmio/macro.c b/rpmio/macro.c index b89a995c1..390ea903c 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -1575,6 +1575,8 @@ static int loadMacroFile(rpmMacroContext mc, const char * fn) size_t blen = MACROBUFSIZ; char *buf = xmalloc(blen); int rc = -1; + int ndefs = 0; + int nfailed = 0; if (fd == NULL) goto exit; @@ -1589,10 +1591,19 @@ static int loadMacroFile(rpmMacroContext mc, const char * fn) if (c != '%') continue; n++; /* skip % */ - rc = defineMacro(mc, n, RMIL_MACROFILES); + ndefs++; + if (defineMacro(mc, n, RMIL_MACROFILES)) + nfailed++; } + fclose(fd); - rc = fclose(fd); + /* if all definitions fail then return an error, otherwise just warn */ + rc = (nfailed && ndefs == nfailed); + + if (nfailed) { + rpmlog(rc ? RPMLOG_ERR : RPMLOG_WARNING, + _("file %s: %d invalid macro definitions\n"), fn, nfailed); + } exit: _free(buf);