From 28e750eebd8ccb5655bdc18693b3b7c9d9ad826b Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 19 Apr 2011 14:58:31 +0200 Subject: step: slowly migrating config settings... ;) --- runtime/cfsysline.c | 10 +++++++ runtime/rsconf.c | 35 +++++++++++++++++++++++- runtime/rsconf.h | 38 ++++++++++++++++++++++++-- runtime/rsyslog.h | 1 + runtime/typedefs.h | 5 +++- tools/syslogd.c | 79 +++++++++++++++++------------------------------------ 6 files changed, 110 insertions(+), 58 deletions(-) diff --git a/runtime/cfsysline.c b/runtime/cfsysline.c index 97b35bb2..2475c270 100644 --- a/runtime/cfsysline.c +++ b/runtime/cfsysline.c @@ -586,6 +586,13 @@ doFacility(uchar **pp, rsRetVal (*pSetHdlr)(void*, int), void *pVal) } +static rsRetVal +doGoneAway(uchar **pp, rsRetVal (*pSetHdlr)(void*, int), void *pVal) +{ + errmsg.LogError(0, RS_RET_CMD_GONE_AWAY, "config directive is no longer supported -- ignored"); + return RS_RET_CMD_GONE_AWAY; +} + /* Implements the severity syntax. * rgerhards, 2008-02-14 */ @@ -717,6 +724,9 @@ static rsRetVal cslchCallHdlr(cslCmdHdlr_t *pThis, uchar **ppConfLine) case eCmdHdlrGetWord: pHdlr = doGetWord; break; + case eCmdHdlrGoneAway: + pHdlr = doGoneAway; + break; default: iRet = RS_RET_NOT_IMPLEMENTED; goto finalize_it; diff --git a/runtime/rsconf.c b/runtime/rsconf.c index 27d89fb6..d68420bf 100644 --- a/runtime/rsconf.c +++ b/runtime/rsconf.c @@ -2,7 +2,7 @@ * * Module begun 2011-04-19 by Rainer Gerhards * - * Copyright 2007, 2008 Rainer Gerhards and Adiscon GmbH. + * Copyright 2011 by Rainer Gerhards and Adiscon GmbH. * * This file is part of the rsyslog runtime library. * @@ -33,15 +33,24 @@ #include "obj.h" #include "srUtils.h" #include "ruleset.h" +#include "modules.h" #include "rsconf.h" +#include "cfsysline.h" /* static data */ DEFobjStaticHelpers +DEFobjCurrIf(ruleset) +DEFobjCurrIf(module) /* Standard-Constructor */ BEGINobjConstruct(rsconf) /* be sure to specify the object type also in END macro! */ + pThis->globals.bDebugPrintTemplateList = 1; + pThis->globals.bDebugPrintModuleList = 1; + pThis->globals.bDebugPrintCfSysLineHandlerList = 1; + pThis->globals.bLogStatusMsgs = DFLT_bLogStatusMsgs; + pThis->globals.bErrMsgToStderr = 1; pThis->templates.root = NULL; pThis->templates.last = NULL; pThis->templates.lastStatic = NULL; @@ -71,6 +80,26 @@ ENDobjDestruct(rsconf) /* DebugPrint support for the rsconf object */ BEGINobjDebugPrint(rsconf) /* be sure to specify the object type also in END and CODESTART macros! */ + dbgprintf("configuration object %p\n", pThis); + dbgprintf("Global Settings:\n"); + dbgprintf(" bDebugPrintTemplateList.............: %d\n", + pThis->globals.bDebugPrintTemplateList); + dbgprintf(" bDebugPrintModuleList : %d\n", + pThis->globals.bDebugPrintModuleList); + dbgprintf(" bDebugPrintCfSysLineHandlerList.....: %d\n", + pThis->globals.bDebugPrintCfSysLineHandlerList); + dbgprintf(" bLogStatusMsgs : %d\n", + pThis->globals.bLogStatusMsgs); + dbgprintf(" bErrMsgToStderr.....................: %d\n", + pThis->globals.bErrMsgToStderr); + ruleset.DebugPrintAll(pThis); + DBGPRINTF("\n"); + if(pThis->globals.bDebugPrintTemplateList) + tplPrintList(pThis); + if(pThis->globals.bDebugPrintModuleList) + module.PrintList(); + if(pThis->globals.bDebugPrintCfSysLineHandlerList) + dbgPrintCfSysLineHandlers(); CODESTARTobjDebugPrint(rsconf) ENDobjDebugPrint(rsconf) @@ -102,6 +131,8 @@ ENDobjQueryInterface(rsconf) */ BEGINObjClassInit(rsconf, 1, OBJ_IS_CORE_MODULE) /* class, version */ /* request objects we use */ + CHKiRet(objUse(ruleset, CORE_COMPONENT)); + CHKiRet(objUse(module, CORE_COMPONENT)); /* now set our own handlers */ OBJSetMethodHandler(objMethod_DEBUGPRINT, rsconfDebugPrint); @@ -112,6 +143,8 @@ ENDObjClassInit(rsconf) /* De-initialize the rsconf class. */ BEGINObjClassExit(rsconf, OBJ_IS_CORE_MODULE) /* class, version */ + objRelease(ruleset, CORE_COMPONENT); + objRelease(module, CORE_COMPONENT); ENDObjClassExit(rsconf) /* vi:set ai: diff --git a/runtime/rsconf.h b/runtime/rsconf.h index 32488d08..68325852 100644 --- a/runtime/rsconf.h +++ b/runtime/rsconf.h @@ -27,9 +27,32 @@ /* --- configuration objects (the plan is to have ALL upper layers in this file) --- */ -/* the following structure is a container for all known templates - * inside a specific configuration. -- rgerhards 2011-04-19 +/* globals are data items that are really global, and can be set only + * once (at least in theory, because the legacy system permits them to + * be re-set as often as the user likes). */ +struct globals_s { + int bDebugPrintTemplateList; + int bDebugPrintModuleList; + int bDebugPrintCfSysLineHandlerList; + int bLogStatusMsgs; /* log rsyslog start/stop/HUP messages? */ + int bErrMsgToStderr; /* print error messages to stderr (in addition to everything else)? */ +}; + +/* (global) defaults are global in the sense that they are accessible + * to all code, but they can change value and other objects (like + * actions) actually copy the value a global had at the time the action + * was defined. In that sense, a global default is just that, a default, + * wich can (and will) be changed in the course of config file + * processing. Once the config file has been processed, defaults + * can be dropped. The current code does not do this for simplicity. + * That is not a problem, because the defaults do not take up much memory. + * At a later stage, we may think about dropping them. -- rgerhards, 2011-04-19 + */ +struct defaults_s { +}; + + struct templates_s { struct template *root; /* the root of the template list */ struct template *last; /* points to the last element of the template list */ @@ -56,9 +79,17 @@ struct rulesets_s { /* the rsconf object */ struct rsconf_s { BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */ + globals_t globals; + defaults_t defaults; templates_t templates; actions_t actions; rulesets_t rulesets; + /* note: rulesets include the complete output part: + * - rules + * - filter (as part of the action) + * - actions + * Of course, we need to debate if we shall change that some time... + */ }; @@ -75,4 +106,7 @@ ENDinterface(rsconf) /* prototypes */ PROTOTYPEObj(rsconf); +/* some defaults (to be removed?) */ +#define DFLT_bLogStatusMsgs 1 + #endif /* #ifndef INCLUDED_RSCONF_H */ diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h index 78841410..fcc0d626 100644 --- a/runtime/rsyslog.h +++ b/runtime/rsyslog.h @@ -354,6 +354,7 @@ enum rsRetVal_ /** return value. All methods return this if not specified oth RS_RET_ERR_LIBEE_INIT = -2201, /**< cannot obtain libee ctx */ RS_RET_ERR_LIBLOGNORM_INIT = -2202,/**< cannot obtain liblognorm ctx */ RS_RET_ERR_LIBLOGNORM_SAMPDB_LOAD = -2203,/**< liblognorm sampledb load failed */ + RS_RET_CMD_GONE_AWAY = -2204,/**< config directive existed, but no longer supported */ /* RainerScript error messages (range 1000.. 1999) */ RS_RET_SYSVAR_NOT_FOUND = 1001, /**< system variable could not be found (maybe misspelled) */ diff --git a/runtime/typedefs.h b/runtime/typedefs.h index 11cc467d..e46f509b 100644 --- a/runtime/typedefs.h +++ b/runtime/typedefs.h @@ -82,6 +82,8 @@ typedef struct statsobj_s statsobj_t; typedef struct nsd_epworkset_s nsd_epworkset_t; typedef struct templates_s templates_t; typedef struct rulesets_s rulesets_t; +typedef struct globals_s globals_t; +typedef struct defaults_s defaults_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 */ @@ -150,7 +152,8 @@ typedef enum cslCmdHdlrType { eCmdHdlrGetChar, eCmdHdlrFacility, eCmdHdlrSeverity, - eCmdHdlrGetWord + eCmdHdlrGetWord, + eCmdHdlrGoneAway /* statment existed, but is no longer supported */ } ecslCmdHdrlType; diff --git a/tools/syslogd.c b/tools/syslogd.c index 72fb04d5..e0e5868b 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -238,12 +238,6 @@ legacyOptsLL_t *pLegacyOptsLL = NULL; int iCompatibilityMode = 0; /* version we should be compatible with; 0 means sysklogd. It is the default, so if no -c option is given, we make ourselvs as compatible to sysklogd as possible. */ -#define DFLT_bLogStatusMsgs 1 -static int bLogStatusMsgs = DFLT_bLogStatusMsgs; /* log rsyslog start/stop/HUP messages? */ -static int bDebugPrintTemplateList = 1;/* output template list in debug mode? */ -static int bDebugPrintCfSysLineHandlerList = 1;/* output cfsyslinehandler list in debug mode? */ -static int bDebugPrintModuleList = 1;/* output module list in debug mode? */ -static int bErrMsgToStderr = 1; /* print error messages to stderr (in addition to everything else)? */ int bReduceRepeatMsgs; /* reduce repeated message - 0 - no, 1 - yes */ int bAbortOnUncleanConfig = 0; /* abort run (rather than starting with partial config) if there was any issue in conf */ /* end global config file state variables */ @@ -292,10 +286,10 @@ static int iMainMsgQueueDeqtWinToHr = 25; /* hour begin of time frame when que */ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal) { - bLogStatusMsgs = DFLT_bLogStatusMsgs; - bDebugPrintTemplateList = 1; - bDebugPrintCfSysLineHandlerList = 1; - bDebugPrintModuleList = 1; + ourConf->globals.bLogStatusMsgs = DFLT_bLogStatusMsgs; + ourConf->globals.bDebugPrintTemplateList = 1; + ourConf->globals.bDebugPrintCfSysLineHandlerList = 1; + ourConf->globals.bDebugPrintModuleList = 1; bReduceRepeatMsgs = 0; bAbortOnUncleanConfig = 0; free(pszMainMsgQFName); @@ -569,7 +563,7 @@ logmsgInternal(int iErr, int pri, uchar *msg, int flags) * permits us to process unmodified config files which otherwise contain a * supressor statement. */ - if(((Debug == DEBUG_FULL || NoFork) && bErrMsgToStderr) || iConfigVerify) { + if(((Debug == DEBUG_FULL || NoFork) && ourConf->globals.bErrMsgToStderr) || iConfigVerify) { if(LOG_PRI(pri) == LOG_ERR) fprintf(stderr, "rsyslogd: %s\n", msg); } @@ -1064,7 +1058,7 @@ die(int sig) thrdTerminateAll(); /* and THEN send the termination log message (see long comment above) */ - if(sig && bLogStatusMsgs) { + if(sig && ourConf->globals.bLogStatusMsgs) { (void) snprintf(buf, sizeof(buf) / sizeof(char), " [origin software=\"rsyslogd\" " "swVersion=\"" VERSION \ "\" x-pid=\"%d\" x-info=\"http://www.rsyslog.com\"]" " exiting on signal %d.", @@ -1439,17 +1433,10 @@ finalize_it: */ static void dbgPrintInitInfo(void) { - ruleset.DebugPrintAll(ourConf); - DBGPRINTF("\n"); - if(bDebugPrintTemplateList) - tplPrintList(ourConf); - if(bDebugPrintModuleList) - module.PrintList(); + dbgprintf("The following is the old-style, to-be-replaced, current config dump at the end " + " of the config load process ;)\n"); ochPrintList(); - if(bDebugPrintCfSysLineHandlerList) - dbgPrintCfSysLineHandlers(); - DBGPRINTF("Messages with malicious PTR DNS Records are %sdropped.\n", glbl.GetDropMalPTRMsgs() ? "" : "not "); @@ -1621,6 +1608,9 @@ init(void) localRet = conf.processConfFile(ourConf, ConfFile); CHKiRet(conf.GetNbrActActions(ourConf, &iNbrActions)); + dbgprintf("rsyslog finished loading initial config %p\n", ourConf); + rsconf.DebugPrint(ourConf); + if(localRet != RS_RET_OK) { errmsg.LogError(0, localRet, "CONFIG ERROR: could not interpret master config file '%s'.", ConfFile); bHadConfigErr = 1; @@ -1736,7 +1726,7 @@ init(void) /* we now generate the startup message. It now includes everything to * identify this instance. -- rgerhards, 2005-08-17 */ - if(bLogStatusMsgs) { + if(ourConf->globals.bLogStatusMsgs) { snprintf(bufStartUpMsg, sizeof(bufStartUpMsg)/sizeof(char), " [origin software=\"rsyslogd\" " "swVersion=\"" VERSION \ "\" x-pid=\"%d\" x-info=\"http://www.rsyslog.com\"] start", @@ -1766,25 +1756,6 @@ finalize_it: } - -/* Put the rsyslog main thread to sleep for n seconds. This was introduced as - * a quick and dirty workaround for a privilege drop race in regard to listener - * startup, which itself was a result of the not-yet-done proper coding of - * privilege drop code (quite some effort). It may be useful for other occasions, too. - * is specified). - * rgerhards, 2009-06-12 - */ -static rsRetVal -putToSleep(void __attribute__((unused)) *pVal, int iNewVal) -{ - DEFiRet; - DBGPRINTF("rsyslog main thread put to sleep via $sleep %d directive...\n", iNewVal); - srSleep(iNewVal, 0); - DBGPRINTF("rsyslog main thread continues after $sleep %d\n", iNewVal); - RETiRet; -} - - /* Switch to either an already existing rule set or start a new one. The * named rule set becomes the new "current" rule set (what means that new * actions are added to it). @@ -1904,7 +1875,7 @@ doHUP(void) { char buf[512]; - if(bLogStatusMsgs) { + if(ourConf->globals.bLogStatusMsgs) { snprintf(buf, sizeof(buf) / sizeof(char), " [origin software=\"rsyslogd\" " "swVersion=\"" VERSION "\" x-pid=\"%d\" x-info=\"http://www.rsyslog.com\"] rsyslogd was HUPed", @@ -2026,7 +1997,7 @@ doIncludeLine(void *pVal, uchar *pNewVal) /* load build-in modules * very first version begun on 2007-07-23 by rgerhards */ -static rsRetVal loadBuildInModules(void) +static rsRetVal loadBuildInModules(rsconf_t *config) { DEFiRet; @@ -2080,10 +2051,10 @@ static rsRetVal loadBuildInModules(void) * is that rsyslog will terminate if we can not register our built-in config commands. * This, I think, is the right thing to do. -- rgerhards, 2007-07-31 */ - CHKiRet(regCfSysLineHdlr((uchar *)"logrsyslogstatusmessages", 0, eCmdHdlrBinary, NULL, &bLogStatusMsgs, NULL, eConfObjGlobal)); + CHKiRet(regCfSysLineHdlr((uchar *)"logrsyslogstatusmessages", 0, eCmdHdlrBinary, NULL, &ourConf->globals.bLogStatusMsgs, NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"defaultruleset", 0, eCmdHdlrGetWord, setDefaultRuleset, NULL, NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"ruleset", 0, eCmdHdlrGetWord, setCurrRuleset, NULL, NULL, eConfObjGlobal)); - CHKiRet(regCfSysLineHdlr((uchar *)"sleep", 0, eCmdHdlrInt, putToSleep, NULL, NULL, eConfObjGlobal)); + CHKiRet(regCfSysLineHdlr((uchar *)"sleep", 0, eCmdHdlrGoneAway, NULL, NULL, NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"mainmsgqueuefilename", 0, eCmdHdlrGetWord, NULL, &pszMainMsgQFName, NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"mainmsgqueuesize", 0, eCmdHdlrInt, NULL, &iMainMsgQueueSize, NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"mainmsgqueuehighwatermark", 0, eCmdHdlrInt, NULL, &iMainMsgQHighWtrMark, NULL, eConfObjGlobal)); @@ -2116,14 +2087,14 @@ static rsRetVal loadBuildInModules(void) 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)); - CHKiRet(regCfSysLineHdlr((uchar *)"debugprintmodulelist", 0, eCmdHdlrBinary, NULL, &bDebugPrintModuleList, NULL, eConfObjGlobal)); + CHKiRet(regCfSysLineHdlr((uchar *)"debugprinttemplatelist", 0, eCmdHdlrBinary, NULL, &(config->globals.bDebugPrintTemplateList), NULL, eConfObjGlobal)); + CHKiRet(regCfSysLineHdlr((uchar *)"debugprintmodulelist", 0, eCmdHdlrBinary, NULL, &(config->globals.bDebugPrintModuleList), NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"debugprintcfsyslinehandlerlist", 0, eCmdHdlrBinary, - NULL, &bDebugPrintCfSysLineHandlerList, NULL, eConfObjGlobal)); + NULL, &(config->globals.bDebugPrintCfSysLineHandlerList), NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"moddir", 0, eCmdHdlrGetWord, NULL, &pModDir, NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"generateconfiggraph", 0, eCmdHdlrGetWord, NULL, &pszConfDAGFile, NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, NULL, eConfObjGlobal)); - CHKiRet(regCfSysLineHdlr((uchar *)"errormessagestostderr", 0, eCmdHdlrBinary, NULL, &bErrMsgToStderr, NULL, eConfObjGlobal)); + CHKiRet(regCfSysLineHdlr((uchar *)"errormessagestostderr", 0, eCmdHdlrBinary, NULL, &ourConf->globals.bErrMsgToStderr, NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"maxmessagesize", 0, eCmdHdlrSize, setMaxMsgSize, NULL, NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"privdroptouser", 0, eCmdHdlrUID, NULL, &uidDropPriv, NULL, eConfObjGlobal)); CHKiRet(regCfSysLineHdlr((uchar *)"privdroptouserid", 0, eCmdHdlrInt, NULL, &uidDropPriv, NULL, eConfObjGlobal)); @@ -2189,9 +2160,6 @@ static rsRetVal mainThread() DEFiRet; uchar *pTmp; - /* we need to init the config object first! */ - CHKiRet(rsconf.Construct(&ourConf)); - /* initialize the build-in templates */ pTmp = template_DebugFormat; tplAddLine(ourConf, "RSYSLOG_DebugFormat", &pTmp); @@ -2260,7 +2228,7 @@ static rsRetVal mainThread() if(!(Debug == DEBUG_FULL || NoFork)) { close(1); close(2); - bErrMsgToStderr = 0; + ourConf->globals.bErrMsgToStderr = 0; } mainloop(); @@ -2743,6 +2711,9 @@ int realMain(int argc, char **argv) for(p = LocalDomain ; *p ; p++) *p = (char)tolower((int)*p); + /* we need to init the config object first! */ + CHKiRet(rsconf.Construct(&ourConf)); + /* we now have our hostname and can set it inside the global vars. * TODO: think if all of this would better be a runtime function * rgerhards, 2008-04-17 @@ -2758,7 +2729,7 @@ int realMain(int argc, char **argv) exit(1); /* "good" exit, leaving at init for fatal error */ } - if((iRet = loadBuildInModules()) != RS_RET_OK) { + if((iRet = loadBuildInModules(ourConf)) != RS_RET_OK) { fprintf(stderr, "fatal error: could not activate built-in modules. Error code %d.\n", iRet); exit(1); /* "good" exit, leaving at init for fatal error */ -- cgit