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.
This commit is contained in:
Panu Matilainen 2018-01-08 12:30:37 +02:00
parent 9343ecd94c
commit f7aff1193e
1 changed files with 13 additions and 2 deletions

View File

@ -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);