From 62d36cce61ed5ca353e4ad5796481f70599f8482 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 22 May 2013 11:27:29 +0300 Subject: [PATCH] Add and use internal (lockless) version of rpmLoadMacroFile() - rpmInitMacros() already grabs the (theoretical) lock on entry so we shouldn't try to grab it again, use the new lockless loadMacroFile() version for the purpose. - rpmLoadMacroFile() is now just a simple lock-wrapper around loadMacroFile() --- rpmio/macro.c | 64 +++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/rpmio/macro.c b/rpmio/macro.c index 1d1cc9085..451cd552c 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -1407,6 +1407,39 @@ static int defineMacro(rpmMacroContext mc, const char * macro, int level) return 0; } +static int loadMacroFile(rpmMacroContext mc, const char * fn) +{ + FILE *fd = fopen(fn, "r"); + size_t blen = MACROBUFSIZ; + char *buf = xmalloc(blen); + int rc = -1; + + if (fd == NULL) + goto exit; + + /* XXX Assume new fangled macro expansion */ + max_macro_depth = 16; + + buf[0] = '\0'; + while(rdcl(buf, blen, fd) != NULL) { + char c, *n; + + n = buf; + SKIPBLANK(n, c); + + if (c != '%') + continue; + n++; /* skip % */ + rc = defineMacro(mc, n, RMIL_MACROFILES); + } + + rc = fclose(fd); + +exit: + _free(buf); + return rc; +} + /* External interfaces */ int expandMacros(void * spec, rpmMacroContext mc, char * sbuf, size_t slen) @@ -1491,37 +1524,12 @@ rpmLoadMacros(rpmMacroContext mc, int level) int rpmLoadMacroFile(rpmMacroContext mc, const char * fn) { - FILE *fd = fopen(fn, "r"); - size_t blen = MACROBUFSIZ; - char *buf = xmalloc(blen); - int rc = -1; - - if (fd == NULL) - goto exit; + int rc; mc = rpmmctxAcquire(mc); - - /* XXX Assume new fangled macro expansion */ - max_macro_depth = 16; - - buf[0] = '\0'; - while(rdcl(buf, blen, fd) != NULL) { - char c, *n; - - n = buf; - SKIPBLANK(n, c); - - if (c != '%') - continue; - n++; /* skip % */ - rc = defineMacro(mc, n, RMIL_MACROFILES); - } + rc = loadMacroFile(mc, fn); rpmmctxRelease(mc); - rc = fclose(fd); - -exit: - _free(buf); return rc; } @@ -1550,7 +1558,7 @@ rpmInitMacros(rpmMacroContext mc, const char * macrofiles) rpmFileHasSuffix(*path, ".rpmorig")) { continue; } - (void) rpmLoadMacroFile(mc, *path); + (void) loadMacroFile(mc, *path); } argvFree(files); }