From 09499d994b9c05ad6421194ce7758f84f3346dc6 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 22 May 2013 11:43:40 +0300 Subject: [PATCH] Add and use internal (lockless) function for copying macro contexts - rpmLoadMacros() is a dumb name for what it does: it copies macros from one context to another. The only actual use within rpm is to copy back the cli macros to global context, but make the internal helper more flexible by allowing copying to any context. - rpmLoadMacros() is mostly just a dumb wrapper around copyMacros() to grab locks and guard against copying global context to itself. Adjust rpmInitMacros() to use copyMacros() as it already has a lock on the global table, it just needs a lock on the cli contexts as well. --- rpmio/macro.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/rpmio/macro.c b/rpmio/macro.c index 451cd552c..3dacbb111 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -1440,6 +1440,15 @@ exit: return rc; } +static void copyMacros(rpmMacroContext src, rpmMacroContext dst, int level) +{ + for (int i = 0; i < src->n; i++) { + rpmMacroEntry me = src->tab[i]; + assert(me); + pushMacro(dst, me->name, me->opts, me->body, (level - 1)); + } +} + /* External interfaces */ int expandMacros(void * spec, rpmMacroContext mc, char * sbuf, size_t slen) @@ -1512,11 +1521,9 @@ rpmLoadMacros(rpmMacroContext mc, int level) gmc = rpmmctxAcquire(NULL); mc = rpmmctxAcquire(mc); - for (int i = 0; i < mc->n; i++) { - rpmMacroEntry me = mc->tab[i]; - assert(me); - pushMacro(gmc, me->name, me->opts, me->body, (level - 1)); - } + + copyMacros(mc, gmc, level); + rpmmctxRelease(mc); rpmmctxRelease(gmc); } @@ -1537,6 +1544,7 @@ void rpmInitMacros(rpmMacroContext mc, const char * macrofiles) { ARGV_t pattern, globs = NULL; + rpmMacroContext climc; if (macrofiles == NULL) return; @@ -1562,11 +1570,14 @@ rpmInitMacros(rpmMacroContext mc, const char * macrofiles) } argvFree(files); } - rpmmctxRelease(mc); argvFree(globs); /* Reload cmdline macros */ - rpmLoadMacros(rpmCLIMacroContext, RMIL_CMDLINE); + climc = rpmmctxAcquire(rpmCLIMacroContext); + copyMacros(climc, mc, RMIL_CMDLINE); + rpmmctxRelease(climc); + + rpmmctxRelease(mc); } void