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:
parent
9343ecd94c
commit
f7aff1193e
|
@ -1575,6 +1575,8 @@ static int loadMacroFile(rpmMacroContext mc, const char * fn)
|
||||||
size_t blen = MACROBUFSIZ;
|
size_t blen = MACROBUFSIZ;
|
||||||
char *buf = xmalloc(blen);
|
char *buf = xmalloc(blen);
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
|
int ndefs = 0;
|
||||||
|
int nfailed = 0;
|
||||||
|
|
||||||
if (fd == NULL)
|
if (fd == NULL)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -1589,10 +1591,19 @@ static int loadMacroFile(rpmMacroContext mc, const char * fn)
|
||||||
if (c != '%')
|
if (c != '%')
|
||||||
continue;
|
continue;
|
||||||
n++; /* skip % */
|
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:
|
exit:
|
||||||
_free(buf);
|
_free(buf);
|
||||||
|
|
Loading…
Reference in New Issue