From d348558a51402d08310d95cfd6e8a2d6b9fce1b2 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 19 Apr 2011 11:26:37 +0200 Subject: milestone: conf obj interface now utilzes rsconf_t --- runtime/conf.c | 44 ++++++++++++++++++------------------- runtime/conf.h | 18 ++++++++------- runtime/rsconf.h | 6 +++++ runtime/typedefs.h | 1 + template.c | 7 ------ tests/rscript.c | 1 + tests/rt-init.c | 1 + tools/syslogd.c | 64 +++++++++++++++++++++++++++++++++++++++++++----------- 8 files changed, 92 insertions(+), 50 deletions(-) diff --git a/runtime/conf.c b/runtime/conf.c index bfd66e31..9f4015fd 100644 --- a/runtime/conf.c +++ b/runtime/conf.c @@ -12,7 +12,7 @@ * the selector lines (e.g. *.info). That code is scheduled for removal * as part of RainerScript. After this is done, we can change licenses. * - * Copyright 2008 Rainer Gerhards and Adiscon GmbH. + * Copyright 2008-2011 Rainer Gerhards and Adiscon GmbH. * * This file is part of rsyslog. * @@ -77,8 +77,8 @@ #endif /* forward definitions */ -static rsRetVal cfline(uchar *line, rule_t **pfCurr); -static rsRetVal processConfFile(uchar *pConfFile); +static rsRetVal cfline(rsconf_t *conf, uchar *line, rule_t **pfCurr); +static rsRetVal processConfFile(rsconf_t *conf, uchar *pConfFile); /* static data */ @@ -117,7 +117,7 @@ static cstr_t *pDfltProgNameCmp = NULL; * indeed a directory. * rgerhards, 2007-08-01 */ -static rsRetVal doIncludeDirectory(uchar *pDirName) +static rsRetVal doIncludeDirectory(rsconf_t *conf, uchar *pDirName) { DEFiRet; int iEntriesDone = 0; @@ -167,7 +167,7 @@ static rsRetVal doIncludeDirectory(uchar *pDirName) memcpy(szFullFileName + iDirNameLen, res->d_name, iFileNameLen); *(szFullFileName + iDirNameLen + iFileNameLen) = '\0'; dbgprintf("including file '%s'\n", szFullFileName); - processConfFile(szFullFileName); + processConfFile(conf, szFullFileName); /* we deliberately ignore the iRet of processConfFile() - this is because * failure to process one file does not mean all files will fail. By ignoring, * we retry with the next file, which is the best thing we can do. -- rgerhards, 2007-08-01 @@ -196,7 +196,7 @@ finalize_it: * rgerhards, 2007-08-01 */ rsRetVal -doIncludeLine(uchar **pp, __attribute__((unused)) void* pVal) +doIncludeLine(rsconf_t *conf, uchar **pp, __attribute__((unused)) void* pVal) { DEFiRet; char pattern[MAXFNAME]; @@ -234,10 +234,10 @@ doIncludeLine(uchar **pp, __attribute__((unused)) void* pVal) if(S_ISREG(fileInfo.st_mode)) { /* config file */ dbgprintf("requested to include config file '%s'\n", cfgFile); - iRet = processConfFile(cfgFile); + iRet = processConfFile(conf, cfgFile); } else if(S_ISDIR(fileInfo.st_mode)) { /* config directory */ dbgprintf("requested to include directory '%s'\n", cfgFile); - iRet = doIncludeDirectory(cfgFile); + iRet = doIncludeDirectory(conf, cfgFile); } else { /* TODO: shall we handle symlinks or not? */ dbgprintf("warning: unable to process IncludeConfig directive '%s'\n", cfgFile); } @@ -253,7 +253,7 @@ finalize_it: /* process a $ModLoad config line. */ rsRetVal -doModLoad(uchar **pp, __attribute__((unused)) void* pVal) +doModLoad(rsconf_t * conf, uchar **pp, __attribute__((unused)) void* pVal) { DEFiRet; uchar szName[512]; @@ -297,7 +297,7 @@ finalize_it: * generalized. */ rsRetVal -doNameLine(uchar **pp, void* pVal) +doNameLine(rsconf_t *conf, uchar **pp, void* pVal) { DEFiRet; uchar *p; @@ -356,7 +356,7 @@ finalize_it: * 2004-11-17 rgerhards */ rsRetVal -cfsysline(uchar *p) +cfsysline(rsconf_t *conf, uchar *p) { DEFiRet; uchar szCmd[64]; @@ -397,7 +397,7 @@ finalize_it: * started with code from init() by rgerhards on 2007-07-31 */ static rsRetVal -processConfFile(uchar *pConfFile) +processConfFile(rsconf_t *conf, uchar *pConfFile) { int iLnNbr = 0; FILE *cf; @@ -464,7 +464,7 @@ processConfFile(uchar *pConfFile) /* we now have the complete line, and are positioned at the first non-whitespace * character. So let's process it */ - if(cfline(cbuf, &pCurrRule) != RS_RET_OK) { + if(cfline(conf, cbuf, &pCurrRule) != RS_RET_OK) { /* we log a message, but otherwise ignore the error. After all, the next * line can be correct. -- rgerhards, 2007-08-02 */ @@ -960,7 +960,7 @@ dbgprintf("XXX: fiop is %u\n", (unsigned) f->f_filterData.prop.operation); * from the config file ("+/-hostname"). It stores it for further reference. * rgerhards 2005-10-19 */ -static rsRetVal cflineProcessHostSelector(uchar **pline) +static rsRetVal cflineProcessHostSelector(rsconf_t *conf, uchar **pline) { DEFiRet; @@ -1010,7 +1010,7 @@ finalize_it: * from the config file ("!tagname"). It stores it for further reference. * rgerhards 2005-10-18 */ -static rsRetVal cflineProcessTagSelector(uchar **pline) +static rsRetVal cflineProcessTagSelector(rsconf_t *conf, uchar **pline) { DEFiRet; @@ -1160,7 +1160,7 @@ static rsRetVal cflineDoAction(uchar **p, action_t **ppAction) * of the master config file!). */ static rsRetVal -cflineClassic(uchar *p, rule_t **ppRule) +cflineClassic(rsconf_t *conf, uchar *p, rule_t **ppRule) { DEFiRet; action_t *pAction; @@ -1203,7 +1203,7 @@ finalize_it: * rgerhards, 2007-08-01 */ static rsRetVal -cfline(uchar *line, rule_t **pfCurr) +cfline(rsconf_t *conf, uchar *line, rule_t **pfCurr) { DEFiRet; @@ -1214,18 +1214,18 @@ cfline(uchar *line, rule_t **pfCurr) /* check type of line and call respective processing */ switch(*line) { case '!': - iRet = cflineProcessTagSelector(&line); + iRet = cflineProcessTagSelector(conf, &line); break; case '+': case '-': - iRet = cflineProcessHostSelector(&line); + iRet = cflineProcessHostSelector(conf, &line); break; case '$': ++line; /* eat '$' */ - iRet = cfsysline(line); + iRet = cfsysline(conf, line); break; default: - iRet = cflineClassic(line, pfCurr); + iRet = cflineClassic(conf, line, pfCurr); break; } @@ -1237,7 +1237,7 @@ cfline(uchar *line, rule_t **pfCurr) * rgerhards, 2008-07-28 */ static rsRetVal -GetNbrActActions(int *piNbrActions) +GetNbrActActions(rsconf_t *conf, int *piNbrActions) { DEFiRet; assert(piNbrActions != NULL); diff --git a/runtime/conf.h b/runtime/conf.h index bc09d502..3b3d488b 100644 --- a/runtime/conf.h +++ b/runtime/conf.h @@ -33,21 +33,23 @@ extern int bConfStrictScoping; /* force strict scoping during config processing? /* interfaces */ BEGINinterface(conf) /* name must also be changed in ENDinterface macro! */ - rsRetVal (*doNameLine)(uchar **pp, void* pVal); - rsRetVal (*cfsysline)(uchar *p); - rsRetVal (*doModLoad)(uchar **pp, __attribute__((unused)) void* pVal); - rsRetVal (*doIncludeLine)(uchar **pp, __attribute__((unused)) void* pVal); - rsRetVal (*cfline)(uchar *line, rule_t **pfCurr); - rsRetVal (*processConfFile)(uchar *pConfFile); - rsRetVal (*GetNbrActActions)(int *); + rsRetVal (*doNameLine)(rsconf_t *conf, uchar **pp, void* pVal); + rsRetVal (*cfsysline)(rsconf_t *conf, uchar *p); + rsRetVal (*doModLoad)(rsconf_t *conf, uchar **pp, __attribute__((unused)) void* pVal); + rsRetVal (*doIncludeLine)(rsconf_t *conf, uchar **pp, __attribute__((unused)) void* pVal); + rsRetVal (*cfline)(rsconf_t *conf, uchar *line, rule_t **pfCurr); + rsRetVal (*processConfFile)(rsconf_t *conf, uchar *pConfFile); + rsRetVal (*GetNbrActActions)(rsconf_t *conf, int *); /* version 4 -- 2010-07-23 rgerhards */ /* "just" added global variables * FYI: we reconsider repacking as a non-object, as only the core currently * accesses this module. The current object structure complicates things without * any real benefit. */ + /* version 5 -- 2011-04-19 rgerhards */ + /* complete revamp, we now use the rsconf object */ ENDinterface(conf) -#define confCURR_IF_VERSION 4 /* increment whenever you change the interface structure! */ +#define confCURR_IF_VERSION 5 /* increment whenever you change the interface structure! */ /* in Version 3, entry point "ReInitConf()" was removed, as we do not longer need * to support restart-type HUP -- rgerhards, 2009-07-15 */ diff --git a/runtime/rsconf.h b/runtime/rsconf.h index 4a8c143f..e32e3d12 100644 --- a/runtime/rsconf.h +++ b/runtime/rsconf.h @@ -34,12 +34,18 @@ struct templates_s { struct template *lastStatic; /* last static element of the template list */ }; + +struct actions_s { + unsigned nbrActions; /* number of actions */ +}; + /* --- end configuration objects --- */ /* the rsconf object */ struct rsconf_s { BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */ templates_t templates; + actions_t actions; }; diff --git a/runtime/typedefs.h b/runtime/typedefs.h index f38bcdd4..d79612bc 100644 --- a/runtime/typedefs.h +++ b/runtime/typedefs.h @@ -81,6 +81,7 @@ typedef struct strgenList_s strgenList_t; typedef struct statsobj_s statsobj_t; typedef struct nsd_epworkset_s nsd_epworkset_t; typedef struct templates_s templates_t; +typedef struct actions_s actions_t; typedef struct rsconf_s rsconf_t; typedef rsRetVal (*prsf_t)(struct vmstk_s*, int); /* pointer to a RainerScript function */ typedef uint64 qDeqID; /* queue Dequeue order ID. 32 bits is considered dangerously few */ diff --git a/template.c b/template.c index 697a6ad5..93f56cd0 100644 --- a/template.c +++ b/template.c @@ -50,13 +50,6 @@ DEFobjCurrIf(regexp) static int bFirstRegexpErrmsg = 1; /**< did we already do a "can't load regexp" error message? */ #endif -#if 0 - -static struct template *conf->templates.root = NULL; /* the root of the template list */ -static struct template *tplLast = NULL; -static struct template *conf->templates.lastStatic = NULL; -#endif - /* helper to tplToString and strgen's, extends buffer */ #define ALLOC_INC 128 diff --git a/tests/rscript.c b/tests/rscript.c index 6361aec4..5baf74cc 100644 --- a/tests/rscript.c +++ b/tests/rscript.c @@ -33,6 +33,7 @@ #include "ctok.h" #include "expr.h" +rsconf_t *ourConf; MODULE_TYPE_TESTBENCH /* define addtional objects we need for our tests */ DEFobjCurrIf(expr) diff --git a/tests/rt-init.c b/tests/rt-init.c index 2d43943f..d3cf4698 100644 --- a/tests/rt-init.c +++ b/tests/rt-init.c @@ -26,6 +26,7 @@ #include "testbench.h" #include /* must be last, else we get a zlib compile error on some platforms */ +rsconf_t *ourConf; MODULE_TYPE_TESTBENCH BEGINInit diff --git a/tools/syslogd.c b/tools/syslogd.c index d0a6df40..c01fd6ad 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -898,7 +898,7 @@ void legacyOptsHook(void) errno = 0; errmsg.LogError(0, NO_ERRCODE, "Warning: backward compatibility layer added to following " "directive to rsyslog.conf: %s", pThis->line); - conf.cfsysline(pThis->line); + conf.cfsysline(ourConf, pThis->line); } pThis = pThis->next; } @@ -1618,8 +1618,8 @@ init(void) ruleset.ConstructFinalize(pRuleset); /* open the configuration file */ - localRet = conf.processConfFile(ConfFile); - CHKiRet(conf.GetNbrActActions(&iNbrActions)); + localRet = conf.processConfFile(ourConf, ConfFile); + CHKiRet(conf.GetNbrActActions(ourConf, &iNbrActions)); if(localRet != RS_RET_OK) { errmsg.LogError(0, localRet, "CONFIG ERROR: could not interpret master config file '%s'.", ConfFile); @@ -1644,13 +1644,13 @@ init(void) */ char szTTYNameBuf[128]; rule_t *pRule = NULL; /* initialization to NULL is *vitally* important! */ - conf.cfline(UCHAR_CONSTANT("*.ERR\t" _PATH_CONSOLE), &pRule); - conf.cfline(UCHAR_CONSTANT("syslog.*\t" _PATH_CONSOLE), &pRule); - conf.cfline(UCHAR_CONSTANT("*.PANIC\t*"), &pRule); - conf.cfline(UCHAR_CONSTANT("syslog.*\troot"), &pRule); + conf.cfline(ourConf, UCHAR_CONSTANT("*.ERR\t" _PATH_CONSOLE), &pRule); + conf.cfline(ourConf, UCHAR_CONSTANT("syslog.*\t" _PATH_CONSOLE), &pRule); + conf.cfline(ourConf, UCHAR_CONSTANT("*.PANIC\t*"), &pRule); + conf.cfline(ourConf, UCHAR_CONSTANT("syslog.*\troot"), &pRule); if(ttyname_r(0, szTTYNameBuf, sizeof(szTTYNameBuf)) == 0) { snprintf(cbuf,sizeof(cbuf), "*.*\t%s", szTTYNameBuf); - conf.cfline((uchar*)cbuf, &pRule); + conf.cfline(ourConf, (uchar*)cbuf, &pRule); } else { DBGPRINTF("error %d obtaining controlling terminal, not using that emergency rule\n", errno); } @@ -1985,6 +1985,44 @@ mainloop(void) } +/* this method is needed to shuffle the current conf object down to the + * IncludeConfig handler. + */ +static rsRetVal +doNameLine(void *pVal, uchar *pNewVal) +{ + DEFiRet; + iRet = conf.doNameLine(ourConf, pVal, pNewVal); + free(pNewVal); + RETiRet; +} + + +/* this method is needed to shuffle the current conf object down to the + * IncludeConfig handler. + */ +static rsRetVal +doModLoad(void *pVal, uchar *pNewVal) +{ + DEFiRet; + iRet = conf.doModLoad(ourConf, pVal, pNewVal); + free(pNewVal); + RETiRet; +} + + +/* this method is needed to shuffle the current conf object down to the + * IncludeConfig handler. + */ +static rsRetVal +doIncludeLine(void *pVal, uchar *pNewVal) +{ + DEFiRet; + iRet = conf.doIncludeLine(ourConf, pVal, pNewVal); + free(pNewVal); + RETiRet; +} + /* load build-in modules * very first version begun on 2007-07-23 by rgerhards */ @@ -2071,11 +2109,11 @@ static rsRetVal loadBuildInModules(void) CHKiRet(regCfSysLineHdlr((uchar *)"abortonuncleanconfig", 0, eCmdHdlrBinary, NULL, &bAbortOnUncleanConfig, NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"repeatedmsgreduction", 0, eCmdHdlrBinary, NULL, &bReduceRepeatMsgs, NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"actionresumeinterval", 0, eCmdHdlrInt, setActionResumeInterval, NULL, NULL, eConfObjGlobal)); - CHKiRet(regCfSysLineHdlr((uchar *)"template", 0, eCmdHdlrCustomHandler, conf.doNameLine, (void*)DIR_TEMPLATE, NULL, eConfObjGlobal)); - CHKiRet(regCfSysLineHdlr((uchar *)"outchannel", 0, eCmdHdlrCustomHandler, conf.doNameLine, (void*)DIR_OUTCHANNEL, NULL, eConfObjGlobal)); - CHKiRet(regCfSysLineHdlr((uchar *)"allowedsender", 0, eCmdHdlrCustomHandler, conf.doNameLine, (void*)DIR_ALLOWEDSENDER, NULL, eConfObjGlobal)); - CHKiRet(regCfSysLineHdlr((uchar *)"modload", 0, eCmdHdlrCustomHandler, conf.doModLoad, NULL, NULL, eConfObjGlobal)); - CHKiRet(regCfSysLineHdlr((uchar *)"includeconfig", 0, eCmdHdlrCustomHandler, conf.doIncludeLine, NULL, NULL, eConfObjGlobal)); + CHKiRet(regCfSysLineHdlr((uchar *)"template", 0, eCmdHdlrCustomHandler, doNameLine, (void*)DIR_TEMPLATE, NULL, eConfObjGlobal)); + CHKiRet(regCfSysLineHdlr((uchar *)"outchannel", 0, eCmdHdlrCustomHandler, doNameLine, (void*)DIR_OUTCHANNEL, NULL, eConfObjGlobal)); + CHKiRet(regCfSysLineHdlr((uchar *)"allowedsender", 0, eCmdHdlrCustomHandler, doNameLine, (void*)DIR_ALLOWEDSENDER, NULL, eConfObjGlobal)); + CHKiRet(regCfSysLineHdlr((uchar *)"modload", 0, eCmdHdlrCustomHandler, doModLoad, NULL, NULL, eConfObjGlobal)); + CHKiRet(regCfSysLineHdlr((uchar *)"includeconfig", 0, eCmdHdlrCustomHandler, doIncludeLine, NULL, NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"umask", 0, eCmdHdlrFileCreateMode, setUmask, NULL, NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"maxopenfiles", 0, eCmdHdlrInt, setMaxFiles, NULL, NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"debugprinttemplatelist", 0, eCmdHdlrBinary, NULL, &bDebugPrintTemplateList, NULL, eConfObjGlobal)); -- cgit