summaryrefslogtreecommitdiffstats
path: root/runtime/modules.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2012-09-27 16:25:53 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2012-09-27 16:25:53 +0200
commita96e4966677d21e8bda6ed47b2ee72f565478562 (patch)
tree485ddc0c5628cad7dbc13be0760a7a936216a63f /runtime/modules.c
parent4cc23e9dc9e906e18539015081b2e5ad16b29417 (diff)
parent53df5066688c8472a9f7be5c86bbc253378e6572 (diff)
downloadrsyslog-a96e4966677d21e8bda6ed47b2ee72f565478562.tar.gz
rsyslog-a96e4966677d21e8bda6ed47b2ee72f565478562.tar.xz
rsyslog-a96e4966677d21e8bda6ed47b2ee72f565478562.zip
Merge branch 'v6-devel'
Conflicts: ChangeLog action.c grammar/grammar.y runtime/modules.h runtime/rsconf.c
Diffstat (limited to 'runtime/modules.c')
-rw-r--r--runtime/modules.c70
1 files changed, 60 insertions, 10 deletions
diff --git a/runtime/modules.c b/runtime/modules.c
index 8675e414..9f7ff31c 100644
--- a/runtime/modules.c
+++ b/runtime/modules.c
@@ -350,11 +350,13 @@ addModToGlblList(modInfo_t *pThis)
}
-/* Add a module to the config module list for current loadConf and
- * provide its config params to it.
+/* ready module for config processing. this includes checking if the module
+ * is already in the config, so this function may return errors. Returns a
+ * pointer to the last module inthe current config. That pointer needs to
+ * be passed to addModToCnfLst() when it is called later in the process.
*/
rsRetVal
-addModToCnfList(modInfo_t *pThis)
+readyModForCnf(modInfo_t *pThis, cfgmodules_etry_t **ppNew, cfgmodules_etry_t **ppLast)
{
cfgmodules_etry_t *pNew;
cfgmodules_etry_t *pLast;
@@ -362,8 +364,7 @@ addModToCnfList(modInfo_t *pThis)
assert(pThis != NULL);
if(loadConf == NULL) {
- /* we are in an early init state */
- FINALIZE;
+ FINALIZE; /* we are in an early init state */
}
/* check for duplicates and, as a side-activity, identify last node */
@@ -399,6 +400,36 @@ addModToCnfList(modInfo_t *pThis)
CHKiRet(pThis->beginCnfLoad(&pNew->modCnf, loadConf));
}
+ *ppLast = pLast;
+ *ppNew = pNew;
+finalize_it:
+ RETiRet;
+}
+
+
+/* abort the creation of a module entry without adding it to the
+ * module list. Needed to prevent mem leaks.
+ */
+static inline void
+abortCnfUse(cfgmodules_etry_t *pNew)
+{
+ free(pNew);
+}
+
+
+/* Add a module to the config module list for current loadConf.
+ * Requires last pointer obtained by readyModForCnf().
+ */
+rsRetVal
+addModToCnfList(cfgmodules_etry_t *pNew, cfgmodules_etry_t *pLast)
+{
+ DEFiRet;
+ assert(pNew != NULL);
+
+ if(loadConf == NULL) {
+ FINALIZE; /* we are in an early init state */
+ }
+
if(pLast == NULL) {
loadConf->modules.root = pNew;
} else {
@@ -608,6 +639,12 @@ doModInit(rsRetVal (*modInit)(int, int*, rsRetVal(**)(), rsRetVal(*)(), modInfo_
CHKiRet((*pNew->modQueryEtryPt)((uchar*)"willRun", &pNew->mod.im.willRun));
CHKiRet((*pNew->modQueryEtryPt)((uchar*)"afterRun", &pNew->mod.im.afterRun));
pNew->mod.im.bCanRun = 0;
+ localRet = (*pNew->modQueryEtryPt)((uchar*)"newInpInst", &pNew->mod.im.newInpInst);
+ if(localRet == RS_RET_MODULE_ENTRY_POINT_NOT_FOUND) {
+ pNew->mod.om.newActInst = NULL;
+ } else if(localRet != RS_RET_OK) {
+ ABORT_FINALIZE(localRet);
+ }
break;
case eMOD_OUT:
CHKiRet((*pNew->modQueryEtryPt)((uchar*)"freeInstance", &pNew->freeInstance));
@@ -626,7 +663,8 @@ doModInit(rsRetVal (*modInit)(int, int*, rsRetVal(**)(), rsRetVal(*)(), modInfo_
else if(localRet != RS_RET_OK)
ABORT_FINALIZE(localRet);
- localRet = (*pNew->modQueryEtryPt)((uchar*)"endTransaction", &pNew->mod.om.endTransaction);
+ localRet = (*pNew->modQueryEtryPt)((uchar*)"endTransaction",
+ &pNew->mod.om.endTransaction);
if(localRet == RS_RET_MODULE_ENTRY_POINT_NOT_FOUND) {
pNew->mod.om.endTransaction = dummyEndTransaction;
} else if(localRet != RS_RET_OK) {
@@ -965,6 +1003,8 @@ Load(uchar *pModName, sbool bConfLoad, struct nvlst *lst)
int bHasExtension;
void *pModHdlr, *pModInit;
modInfo_t *pModInfo;
+ cfgmodules_etry_t *pNew;
+ cfgmodules_etry_t *pLast;
uchar *pModDirCurr, *pModDirNext;
int iLoadCnt;
struct dlhandle_s *pHandle = NULL;
@@ -999,8 +1039,9 @@ Load(uchar *pModName, sbool bConfLoad, struct nvlst *lst)
if(pModInfo != NULL) {
DBGPRINTF("Module '%s' already loaded\n", pModName);
if(bConfLoad) {
- localRet = addModToCnfList(pModInfo);
+ localRet = readyModForCnf(pModInfo, &pNew, &pLast);
if(pModInfo->setModCnf != NULL && localRet == RS_RET_OK) {
+ addModToCnfList(pNew, pLast);
if(!strncmp((char*)pModName, "builtin:", sizeof("builtin:")-1)) {
if(pModInfo->bSetModCnfCalled) {
errmsg.LogError(0, RS_RET_DUP_PARAM,
@@ -1128,12 +1169,21 @@ Load(uchar *pModName, sbool bConfLoad, struct nvlst *lst)
}
if(bConfLoad) {
- addModToCnfList(pModInfo);
+ readyModForCnf(pModInfo, &pNew, &pLast);
if(pModInfo->setModCnf != NULL) {
- if(lst != NULL)
- pModInfo->setModCnf(lst);
+ if(lst != NULL) {
+ localRet = pModInfo->setModCnf(lst);
+ if(localRet != RS_RET_OK) {
+ errmsg.LogError(0, localRet,
+ "module '%s', failed processing config parameters",
+ pPathBuf);
+ abortCnfUse(pNew);
+ ABORT_FINALIZE(localRet);
+ }
+ }
pModInfo->bSetModCnfCalled = 1;
}
+ addModToCnfList(pNew, pLast);
}
finalize_it: