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.
This commit is contained in:
Panu Matilainen 2013-05-22 11:43:40 +03:00
parent 62d36cce61
commit 09499d994b
1 changed files with 18 additions and 7 deletions

View File

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