From 46ccc9e77f5e2ee3ded1ca79e973fafdc37e4c0f Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 20 Jun 2012 09:34:31 +0200 Subject: milestone: module() can load module in legacy mode --- runtime/conf.c | 9 +++------ runtime/modules.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- runtime/modules.h | 11 +++++++++-- runtime/obj.c | 2 +- runtime/rsconf.c | 3 +++ 5 files changed, 65 insertions(+), 12 deletions(-) (limited to 'runtime') diff --git a/runtime/conf.c b/runtime/conf.c index eec04df8..488d1b86 100644 --- a/runtime/conf.c +++ b/runtime/conf.c @@ -116,18 +116,15 @@ doModLoad(uchar **pp, __attribute__((unused)) void* pVal) skipWhiteSpace(pp); /* skip over any whitespace */ /* this below is a quick and dirty hack to provide compatibility with the - * $ModLoad MySQL forward compatibility statement. TODO: clean this up - * For the time being, it is clean enough, it just needs to be done - * differently when we have a full design for loadable plug-ins. For the - * time being, we just mangle the names a bit. - * rgerhards, 2007-08-14 + * $ModLoad MySQL forward compatibility statement. This needs to be supported + * for legacy format. */ if(!strcmp((char*) szName, "MySQL")) pModName = (uchar*) "ommysql.so"; else pModName = szName; - CHKiRet(module.Load(pModName, 1)); + CHKiRet(module.Load(pModName, 1, NULL)); finalize_it: RETiRet; diff --git a/runtime/modules.c b/runtime/modules.c index dac3bd95..4ab5b206 100644 --- a/runtime/modules.c +++ b/runtime/modules.c @@ -11,7 +11,7 @@ * * File begun on 2007-07-22 by RGerhards * - * Copyright 2007-2011 Rainer Gerhards and Adiscon GmbH. + * Copyright 2007-2012 Rainer Gerhards and Adiscon GmbH. * * This file is part of the rsyslog runtime library. * @@ -75,6 +75,18 @@ static struct dlhandle_s *pHandles = NULL; static uchar *pModDir; /* directory where loadable modules are found */ +/* tables for interfacing with the v6 config system */ +/* action (instance) parameters */ +static struct cnfparamdescr actpdescr[] = { + { "load", eCmdHdlrGetWord, 1 } +}; +static struct cnfparamblk pblk = + { CNFPARAMBLK_VERSION, + sizeof(actpdescr)/sizeof(struct cnfparamdescr), + actpdescr + }; + + /* we provide a set of dummy functions for modules that do not support the * some interfaces. * On the commit feature: As the modules do not support it, they commit each message they @@ -931,9 +943,10 @@ findModule(uchar *pModName, int iModNameLen, modInfo_t **pMod) * the system loads a module for internal reasons, this is not directly tied to a * configuration. We could also think if it would be useful to add only certain types * of modules, but the current implementation at least looks simpler. + * Note: pvals = NULL means legacy config system */ static rsRetVal -Load(uchar *pModName, sbool bConfLoad) +Load(uchar *pModName, sbool bConfLoad, struct cnfparamvals *pvals) { DEFiRet; @@ -954,7 +967,7 @@ Load(uchar *pModName, sbool bConfLoad) size_t lenPathBuf = sizeof(pathBuf); assert(pModName != NULL); - dbgprintf("Requested to load module '%s'\n", pModName); + DBGPRINTF("Requested to load module '%s'\n", pModName); iModNameLen = strlen((char*)pModName); /* overhead for a full path is potentially 1 byte for a slash, @@ -1093,6 +1106,39 @@ finalize_it: } +/* the v6+ way of loading modules: process a "module(...)" directive. + * rgerhards, 2012-06-20 + */ +rsRetVal +modulesProcessCnf(struct cnfobj *o) +{ + struct cnfparamvals *pvals; + uchar *cnfModName = NULL; + int typeIdx; + DEFiRet; + + pvals = nvlstGetParams(o->nvlst, &pblk, NULL); + if(pvals == NULL) { + ABORT_FINALIZE(RS_RET_ERR); + } + DBGPRINTF("modulesProcessCnf params:\n"); + cnfparamsPrint(&pblk, pvals); + typeIdx = cnfparamGetIdx(&pblk, "load"); + if(pvals[typeIdx].bUsed == 0) { + errmsg.LogError(0, RS_RET_CONF_RQRD_PARAM_MISSING, "module type missing"); + ABORT_FINALIZE(RS_RET_CONF_RQRD_PARAM_MISSING); + } + + cnfModName = (uchar*)es_str2cstr(pvals[typeIdx].val.d.estr, NULL); + iRet = Load(cnfModName, 1, pvals); + +finalize_it: + free(cnfModName); + cnfparamvalsDestruct(pvals, &pblk); + RETiRet; +} + + /* set the default module load directory. A NULL value may be provided, in * which case any previous value is deleted but no new one set. The caller-provided * string is duplicated. If it needs to be freed, that's the caller's duty. diff --git a/runtime/modules.h b/runtime/modules.h index 6c5a2cba..5a293352 100644 --- a/runtime/modules.h +++ b/runtime/modules.h @@ -171,19 +171,26 @@ BEGINinterface(module) /* name must also be changed in ENDinterface macro! */ void (*PrintList)(void); rsRetVal (*UnloadAndDestructAll)(eModLinkType_t modLinkTypesToUnload); rsRetVal (*doModInit)(rsRetVal (*modInit)(), uchar *name, void *pModHdlr, modInfo_t **pNew); - rsRetVal (*Load)(uchar *name, sbool bConfLoad); + rsRetVal (*Load)(uchar *name, sbool bConfLoad, struct cnfparamvals *pvals); rsRetVal (*SetModDir)(uchar *name); modInfo_t *(*FindWithCnfName)(rsconf_t *cnf, uchar *name, eModType_t rqtdType); /* added v3, 2011-07-19 */ ENDinterface(module) -#define moduleCURR_IF_VERSION 3 /* increment whenever you change the interface structure! */ +#define moduleCURR_IF_VERSION 4 /* increment whenever you change the interface structure! */ /* Changes: * v2 * - added param bCondLoad to Load call - 2011-04-27 * - removed GetNxtType, added GetNxtCnfType - 2011-04-27 + * v3 (see above) + * v4 + * - added thrid parameter to Load() - 2012-06-20 */ /* prototypes */ PROTOTYPEObj(module); +/* in v6, we go back to in-core static link for core objects, at least those + * that are not called from plugins. + */ +rsRetVal modulesProcessCnf(struct cnfobj *o); /* TODO: remove "dirty" calls! */ rsRetVal addModToCnfList(modInfo_t *pThis); diff --git a/runtime/obj.c b/runtime/obj.c index b2739c58..99621124 100644 --- a/runtime/obj.c +++ b/runtime/obj.c @@ -1151,7 +1151,7 @@ UseObj(char *srcFile, uchar *pObjName, uchar *pObjFile, interface_t *pIf) if(pObjFile == NULL) { FINALIZE; /* no chance, we have lost... */ } else { - CHKiRet(module.Load(pObjFile, 0)); + CHKiRet(module.Load(pObjFile, 0, NULL)); /* NOW, we must find it or we have a problem... */ CHKiRet(FindObjInfo(pStr, &pObjInfo)); } diff --git a/runtime/rsconf.c b/runtime/rsconf.c index c1af7d22..ea0eaa0d 100644 --- a/runtime/rsconf.c +++ b/runtime/rsconf.c @@ -368,6 +368,9 @@ void cnfDoObj(struct cnfobj *o) case CNFOBJ_GLOBAL: glblProcessCnf(o); break; + case CNFOBJ_MODULE: + modulesProcessCnf(o); + break; case CNFOBJ_ACTION: actionProcessCnf(o); break; -- cgit