diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2012-09-27 08:54:28 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2012-09-27 08:54:28 +0200 |
commit | 71664616132a47c2b951d72432031283ba040f79 (patch) | |
tree | a947abc04c2a7b7fa5dfd02efdb3b49e6a22593d /plugins/imfile/imfile.c | |
parent | 95e73e3cd2c160be769fecd7a13c6e06579a7847 (diff) | |
download | rsyslog-71664616132a47c2b951d72432031283ba040f79.tar.gz rsyslog-71664616132a47c2b951d72432031283ba040f79.tar.bz2 rsyslog-71664616132a47c2b951d72432031283ba040f79.zip |
imfile: implement support for module parameters via module() stmt
Diffstat (limited to 'plugins/imfile/imfile.c')
-rw-r--r-- | plugins/imfile/imfile.c | 86 |
1 files changed, 77 insertions, 9 deletions
diff --git a/plugins/imfile/imfile.c b/plugins/imfile/imfile.c index 4edd550d..83f94296 100644 --- a/plugins/imfile/imfile.c +++ b/plugins/imfile/imfile.c @@ -64,7 +64,11 @@ DEFobjCurrIf(strm) DEFobjCurrIf(prop) DEFobjCurrIf(ruleset) -#define NUM_MULTISUB 1024 /* max number of submits -- TODO: make configurable */ +static int bLegacyCnfModGlobalsPermitted;/* are legacy module-global config parameters permitted? */ + +#define NUM_MULTISUB 1024 /* default max number of submits */ +#define DFLT_PollInterval 10 + typedef struct fileInfo_s { uchar *pszFileName; uchar *pszTag; @@ -86,7 +90,7 @@ static struct configSettings_s { uchar *pszFileTag; uchar *pszStateFile; uchar *pszBindRuleset; - int iPollInterval; /* number of seconds to sleep when there was no file activity */ + int iPollInterval; int iPersistStateInterval; /* how often if state file to be persisted? (default 0->never) */ int iFacility; /* local0 */ int iSeverity; /* notice, as of rfc 3164 */ @@ -117,7 +121,8 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a /* config variables */ struct modConfData_s { - rsconf_t *pConf; /* our overall config object */ + rsconf_t *pConf; /* our overall config object */ + int iPollInterval; /* number of seconds to sleep when there was no file activity */ instanceConf_t *root, *tail; sbool configSetViaV2Method; }; @@ -130,6 +135,16 @@ static fileInfo_t files[MAX_INPUT_FILES]; static prop_t *pInputName = NULL; /* there is only one global inputName for all messages generated by this input */ +/* module-global parameters */ +static struct cnfparamdescr modpdescr[] = { + { "pollinginterval", eCmdHdlrInt, 0 } +}; +static struct cnfparamblk modpblk = + { CNFPARAMBLK_VERSION, + sizeof(modpdescr)/sizeof(struct cnfparamdescr), + modpdescr + }; + /* input instance parameters */ static struct cnfparamdescr inppdescr[] = { { "file", eCmdHdlrString, CNFPARAM_REQUIRED }, @@ -491,12 +506,14 @@ CODESTARTbeginCnfLoad loadModConf = pModConf; pModConf->pConf = pConf; /* init our settings */ + loadModConf->iPollInterval = DFLT_PollInterval; loadModConf->configSetViaV2Method = 0; + bLegacyCnfModGlobalsPermitted = 1; /* init legacy config vars */ cs.pszFileName = NULL; cs.pszFileTag = NULL; cs.pszStateFile = NULL; - cs.iPollInterval = 10; + cs.iPollInterval = DFLT_PollInterval; cs.iPersistStateInterval = 0; cs.iFacility = 128; cs.iSeverity = 5; @@ -506,13 +523,59 @@ CODESTARTbeginCnfLoad ENDbeginCnfLoad +BEGINsetModCnf + struct cnfparamvals *pvals = NULL; + int i; +CODESTARTsetModCnf + pvals = nvlstGetParams(lst, &modpblk, NULL); + if(pvals == NULL) { + errmsg.LogError(0, RS_RET_MISSING_CNFPARAMS, "imfile: error processing module " + "config parameters [module(...)]"); + ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS); + } + + if(Debug) { + dbgprintf("module (global) param blk for imfile:\n"); + cnfparamsPrint(&modpblk, pvals); + } + + for(i = 0 ; i < modpblk.nParams ; ++i) { + if(!pvals[i].bUsed) + continue; + if(!strcmp(modpblk.descr[i].name, "pollinginterval")) { + if(pvals[i].val.d.n < 1) { + errmsg.LogError(0, RS_RET_MISSING_CNFPARAMS, + "imfile: polling interval cannot be set below 1 - ignored"); + } else { + loadModConf->iPollInterval = (int) pvals[i].val.d.n; + } + } else { + dbgprintf("imfile: program error, non-handled " + "param '%s' in beginCnfLoad\n", modpblk.descr[i].name); + } + } + + /* remove all of our legacy handlers, as they can not used in addition + * the the new-style config method. + */ + bLegacyCnfModGlobalsPermitted = 0; + loadModConf->configSetViaV2Method = 1; + +finalize_it: + if(pvals != NULL) + cnfparamvalsDestruct(pvals, &modpblk); +ENDsetModCnf + + + BEGINendCnfLoad CODESTARTendCnfLoad if(!loadModConf->configSetViaV2Method) { /* persist module-specific settings from legacy config system */ + loadModConf->iPollInterval = cs.iPollInterval; } + dbgprintf("imfile: polling interval is %d\n", loadModConf->iPollInterval); -//finalize_it: loadModConf = NULL; /* done loading */ /* free legacy config vars */ free(cs.pszFileName); @@ -563,6 +626,7 @@ CODESTARTfreeCnf free(inst->pszBindRuleset); free(inst->pszFileName); free(inst->pszTag); + free(inst->pszStateFile); del = inst; inst = inst->next; free(del); @@ -631,7 +695,7 @@ CODESTARTrunInput * other valid scenario. So do not remove. -- rgerhards, 2008-02-14 */ if(glbl.GetGlobalInputTermState() == 0) - srSleep(cs.iPollInterval, 10); + srSleep(runModConf->iPollInterval, 10); } DBGPRINTF("imfile: terminating upon request of rsyslog core\n"); @@ -752,6 +816,7 @@ BEGINqueryEtryPt CODESTARTqueryEtryPt CODEqueryEtryPt_STD_IMOD_QUERIES CODEqueryEtryPt_STD_CONF2_QUERIES +CODEqueryEtryPt_STD_CONF2_setModCnf_QUERIES CODEqueryEtryPt_STD_CONF2_IMOD_QUERIES CODEqueryEtryPt_IsCompatibleWithFeature_IF_OMOD_QUERIES ENDqueryEtryPt @@ -776,7 +841,7 @@ resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unus cs.pszFileTag = NULL; /* set defaults... */ - cs.iPollInterval = 10; + cs.iPollInterval = DFLT_PollInterval; cs.iFacility = 128; /* local0 */ cs.iSeverity = 5; /* notice, as of rfc 3164 */ cs.readMode = 0; @@ -825,8 +890,6 @@ CODEmodInit_QueryRegCFSLineHdlr NULL, &cs.iSeverity, STD_LOADABLE_MODULE_ID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilefacility", 0, eCmdHdlrFacility, NULL, &cs.iFacility, STD_LOADABLE_MODULE_ID)); - CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilepollinterval", 0, eCmdHdlrInt, - NULL, &cs.iPollInterval, STD_LOADABLE_MODULE_ID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilereadmode", 0, eCmdHdlrInt, NULL, &cs.readMode, STD_LOADABLE_MODULE_ID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputfilemaxlinesatonce", 0, eCmdHdlrSize, @@ -838,6 +901,11 @@ CODEmodInit_QueryRegCFSLineHdlr /* that command ads a new file! */ CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputrunfilemonitor", 0, eCmdHdlrGetWord, addInstance, NULL, STD_LOADABLE_MODULE_ID)); + /* module-global config params - will be disabled in configs that are loaded + * via module(...). + */ + CHKiRet(regCfSysLineHdlr2((uchar *)"inputfilepollinterval", 0, eCmdHdlrInt, + NULL, &cs.iPollInterval, STD_LOADABLE_MODULE_ID, &bLegacyCnfModGlobalsPermitted)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID)); ENDmodInit |