summaryrefslogtreecommitdiffstats
path: root/runtime/ruleset.c
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/ruleset.c')
-rw-r--r--runtime/ruleset.c135
1 files changed, 71 insertions, 64 deletions
diff --git a/runtime/ruleset.c b/runtime/ruleset.c
index 8e241c8a..c384663a 100644
--- a/runtime/ruleset.c
+++ b/runtime/ruleset.c
@@ -1,7 +1,7 @@
/* ruleset.c - rsyslog's ruleset object
*
- * We have a two-way structure of linked lists: one global linked list
- * (llAllRulesets) hold alls rule sets that we know. Included in each
+ * We have a two-way structure of linked lists: one config-specifc linked list
+ * (conf->rulesets.llRulesets) hold alls rule sets that we know. Included in each
* list is a list of rules (which contain a list of actions, but that's
* a different story).
*
@@ -11,7 +11,7 @@
*
* Module begun 2009-06-10 by Rainer Gerhards
*
- * Copyright 2009 Rainer Gerhards and Adiscon GmbH.
+ * Copyright 2009-2011 Rainer Gerhards and Adiscon GmbH.
*
* This file is part of the rsyslog runtime library.
*
@@ -34,7 +34,6 @@
#include "config.h"
#include <stdlib.h>
-#include <string.h>
#include <assert.h>
#include <ctype.h>
@@ -48,6 +47,7 @@
#include "parser.h"
#include "batch.h"
#include "unicode-helper.h"
+#include "rsconf.h"
#include "dirty.h" /* for main ruleset queue creation */
/* static data */
@@ -56,26 +56,23 @@ DEFobjCurrIf(errmsg)
DEFobjCurrIf(rule)
DEFobjCurrIf(parser)
-linkedList_t llRulesets; /* this is NOT a pointer - no typo here ;) */
-ruleset_t *pCurrRuleset = NULL; /* currently "active" ruleset */
-ruleset_t *pDfltRuleset = NULL; /* current default ruleset, e.g. for binding to actions which have no other */
-
/* forward definitions */
static rsRetVal processBatch(batch_t *pBatch);
-/* ---------- linked-list key handling functions ---------- */
+
+/* ---------- linked-list key handling functions (ruleset) ---------- */
/* destructor for linked list keys.
*/
-static rsRetVal keyDestruct(void __attribute__((unused)) *pData)
+rsRetVal
+rulesetKeyDestruct(void __attribute__((unused)) *pData)
{
free(pData);
return RS_RET_OK;
}
+/* ---------- END linked-list key handling functions (ruleset) ---------- */
-/* ---------- END linked-list key handling functions ---------- */
-
/* driver to iterate over all of this ruleset actions */
typedef struct iterateAllActions_s {
@@ -122,7 +119,7 @@ DEFFUNC_llExecFunc(doIterateAllActions)
* must be done or a shutdown is pending.
*/
static rsRetVal
-iterateAllActions(rsRetVal (*pFunc)(void*, void*), void* pParam)
+iterateAllActions(rsconf_t *conf, rsRetVal (*pFunc)(void*, void*), void* pParam)
{
iterateAllActions_t params;
DEFiRet;
@@ -130,7 +127,7 @@ iterateAllActions(rsRetVal (*pFunc)(void*, void*), void* pParam)
params.pFunc = pFunc;
params.pParam = pParam;
- CHKiRet(llExecFunc(&llRulesets, doIterateAllActions, &params));
+ CHKiRet(llExecFunc(&(conf->rulesets.llRulesets), doIterateAllActions, &params));
finalize_it:
RETiRet;
@@ -227,7 +224,7 @@ processBatch(batch_t *pBatch)
if(pBatch->bSingleRuleset) {
pThis = batchGetRuleset(pBatch);
if(pThis == NULL)
- pThis = pDfltRuleset;
+ pThis = ourConf->rulesets.pDflt;
ISOBJ_TYPE_assert(pThis, ruleset);
CHKiRet(llExecFunc(&pThis->llRules, processBatchDoRules, pBatch));
} else {
@@ -245,9 +242,9 @@ finalize_it:
* rgerhards, 2009-11-04
*/
static parserList_t*
-GetParserList(msg_t *pMsg)
+GetParserList(rsconf_t *conf, msg_t *pMsg)
{
- return (pMsg->pRuleset == NULL) ? pDfltRuleset->pParserLst : pMsg->pRuleset->pParserLst;
+ return (pMsg->pRuleset == NULL) ? conf->rulesets.pDflt->pParserLst : pMsg->pRuleset->pParserLst;
}
@@ -269,7 +266,7 @@ addRule(ruleset_t *pThis, rule_t **ppRule)
rule.Destruct(ppRule);
} else {
CHKiRet(llAppend(&pThis->llRules, NULL, *ppRule));
- dbgprintf("selector line successfully processed\n");
+ dbgprintf("selector line successfully processed, %d actions\n", iActionCnt);
}
finalize_it:
@@ -294,9 +291,9 @@ finalize_it:
* is really much more natural to return the pointer directly.
*/
static ruleset_t*
-GetCurrent(void)
+GetCurrent(rsconf_t *conf)
{
- return pCurrRuleset;
+ return conf->rulesets.pCurr;
}
@@ -316,13 +313,13 @@ GetRulesetQueue(ruleset_t *pThis)
/* Find the ruleset with the given name and return a pointer to its object.
*/
rsRetVal
-rulesetGetRuleset(ruleset_t **ppRuleset, uchar *pszName)
+rulesetGetRuleset(rsconf_t *conf, ruleset_t **ppRuleset, uchar *pszName)
{
DEFiRet;
assert(ppRuleset != NULL);
assert(pszName != NULL);
- CHKiRet(llFind(&llRulesets, pszName, (void*) ppRuleset));
+ CHKiRet(llFind(&(conf->rulesets.llRulesets), pszName, (void*) ppRuleset));
finalize_it:
RETiRet;
@@ -332,14 +329,14 @@ finalize_it:
/* Set a new default rule set. If the default can not be found, no change happens.
*/
static rsRetVal
-SetDefaultRuleset(uchar *pszName)
+SetDefaultRuleset(rsconf_t *conf, uchar *pszName)
{
ruleset_t *pRuleset;
DEFiRet;
assert(pszName != NULL);
- CHKiRet(rulesetGetRuleset(&pRuleset, pszName));
- pDfltRuleset = pRuleset;
+ CHKiRet(rulesetGetRuleset(conf, &pRuleset, pszName));
+ conf->rulesets.pDflt = pRuleset;
dbgprintf("default rule set changed to %p: '%s'\n", pRuleset, pszName);
finalize_it:
@@ -350,14 +347,14 @@ finalize_it:
/* Set a new current rule set. If the ruleset can not be found, no change happens.
*/
static rsRetVal
-SetCurrRuleset(uchar *pszName)
+SetCurrRuleset(rsconf_t *conf, uchar *pszName)
{
ruleset_t *pRuleset;
DEFiRet;
assert(pszName != NULL);
- CHKiRet(rulesetGetRuleset(&pRuleset, pszName));
- pCurrRuleset = pRuleset;
+ CHKiRet(rulesetGetRuleset(conf, &pRuleset, pszName));
+ conf->rulesets.pCurr = pRuleset;
dbgprintf("current rule set changed to %p: '%s'\n", pRuleset, pszName);
finalize_it:
@@ -389,7 +386,7 @@ ENDobjConstruct(ruleset)
* This also adds the rule set to the list of all known rulesets.
*/
static rsRetVal
-rulesetConstructFinalize(ruleset_t *pThis)
+rulesetConstructFinalize(rsconf_t *conf, ruleset_t *pThis)
{
uchar *keyName;
DEFiRet;
@@ -400,14 +397,14 @@ rulesetConstructFinalize(ruleset_t *pThis)
* two separate copies.
*/
CHKmalloc(keyName = ustrdup(pThis->pszName));
- CHKiRet(llAppend(&llRulesets, keyName, pThis));
+ CHKiRet(llAppend(&(conf->rulesets.llRulesets), keyName, pThis));
/* this now also is the new current ruleset */
- pCurrRuleset = pThis;
+ conf->rulesets.pCurr = pThis;
/* and also the default, if so far none has been set */
- if(pDfltRuleset == NULL)
- pDfltRuleset = pThis;
+ if(conf->rulesets.pDflt == NULL)
+ conf->rulesets.pDflt = pThis;
finalize_it:
RETiRet;
@@ -428,17 +425,6 @@ CODESTARTobjDestruct(ruleset)
free(pThis->pszName);
ENDobjDestruct(ruleset)
-/* this is a special destructor for the linkedList class. LinkedList does NOT
- * provide a pointer to the pointer, but rather the raw pointer itself. So we
- * must map this, otherwise the destructor will abort.
- */
-static rsRetVal
-rulesetDestructForLinkedList(void *pData)
-{
- ruleset_t *pThis = (ruleset_t*) pData;
- return rulesetDestruct(&pThis);
-}
-
/* destruct ALL rule sets that reside in the system. This must
* be callable before unloading this module as the module may
@@ -447,18 +433,29 @@ rulesetDestructForLinkedList(void *pData)
* everything runs stable again. -- rgerhards, 2009-06-10
*/
static rsRetVal
-destructAllActions(void)
+destructAllActions(rsconf_t *conf)
{
DEFiRet;
- CHKiRet(llDestroy(&llRulesets));
- CHKiRet(llInit(&llRulesets, rulesetDestructForLinkedList, keyDestruct, strcasecmp));
- pDfltRuleset = NULL;
+ CHKiRet(llDestroy(&(conf->rulesets.llRulesets)));
+ CHKiRet(llInit(&(conf->rulesets.llRulesets), rulesetDestructForLinkedList, rulesetKeyDestruct, strcasecmp));
+ conf->rulesets.pDflt = NULL;
finalize_it:
RETiRet;
}
+/* this is a special destructor for the linkedList class. LinkedList does NOT
+ * provide a pointer to the pointer, but rather the raw pointer itself. So we
+ * must map this, otherwise the destructor will abort.
+ */
+rsRetVal
+rulesetDestructForLinkedList(void *pData)
+{
+ ruleset_t *pThis = (ruleset_t*) pData;
+ return rulesetDestruct(&pThis);
+}
+
/* helper for debugPrint(), initiates rule printing */
DEFFUNC_llExecFunc(doDebugPrintRule)
{
@@ -480,11 +477,11 @@ DEFFUNC_llExecFunc(doDebugPrintAll)
/* debug print all rulesets
*/
static rsRetVal
-debugPrintAll(void)
+debugPrintAll(rsconf_t *conf)
{
DEFiRet;
dbgprintf("All Rulesets:\n");
- llExecFunc(&llRulesets, doDebugPrintAll, NULL);
+ llExecFunc(&(conf->rulesets.llRulesets), doDebugPrintAll, NULL);
dbgprintf("End of Rulesets.\n");
RETiRet;
}
@@ -497,18 +494,19 @@ debugPrintAll(void)
* considered acceptable for the time being.
* rgerhards, 2009-10-27
*/
-static rsRetVal
-rulesetCreateQueue(void __attribute__((unused)) *pVal, int *pNewVal)
+static inline rsRetVal
+doRulesetCreateQueue(rsconf_t *conf, int *pNewVal)
{
+ uchar *rulesetMainQName;
DEFiRet;
- if(pCurrRuleset == NULL) {
+ if(conf->rulesets.pCurr == NULL) {
errmsg.LogError(0, RS_RET_NO_CURR_RULESET, "error: currently no specific ruleset specified, thus a "
"queue can not be added to it");
ABORT_FINALIZE(RS_RET_NO_CURR_RULESET);
}
- if(pCurrRuleset->pQueue != NULL) {
+ if(conf->rulesets.pCurr->pQueue != NULL) {
errmsg.LogError(0, RS_RET_RULES_QUEUE_EXISTS, "error: ruleset already has a main queue, can not "
"add another one");
ABORT_FINALIZE(RS_RET_RULES_QUEUE_EXISTS);
@@ -518,12 +516,19 @@ rulesetCreateQueue(void __attribute__((unused)) *pVal, int *pNewVal)
FINALIZE; /* if it is turned off, we do not need to change anything ;) */
dbgprintf("adding a ruleset-specific \"main\" queue");
- CHKiRet(createMainQueue(&pCurrRuleset->pQueue, UCHAR_CONSTANT("ruleset")));
+ rulesetMainQName = (conf->rulesets.pCurr->pszName == NULL)? UCHAR_CONSTANT("ruleset") :
+ conf->rulesets.pCurr->pszName;
+ CHKiRet(createMainQueue(&conf->rulesets.pCurr->pQueue, rulesetMainQName));
finalize_it:
RETiRet;
}
+static rsRetVal
+rulesetCreateQueue(void __attribute__((unused)) *pVal, int *pNewVal)
+{
+ return doRulesetCreateQueue(ourConf, pNewVal);
+}
/* Add a ruleset specific parser to the ruleset. Note that adding the first
* parser automatically disables the default parsers. If they are needed as well,
@@ -535,12 +540,12 @@ finalize_it:
* rgerhards, 2009-11-04
*/
static rsRetVal
-rulesetAddParser(void __attribute__((unused)) *pVal, uchar *pName)
+doRulesetAddParser(rsconf_t *conf, uchar *pName)
{
parser_t *pParser;
DEFiRet;
- assert(pCurrRuleset != NULL);
+ assert(conf->rulesets.pCurr != NULL);
CHKiRet(objUse(parser, CORE_COMPONENT));
iRet = parser.FindParser(&pParser, pName);
@@ -553,10 +558,10 @@ rulesetAddParser(void __attribute__((unused)) *pVal, uchar *pName)
FINALIZE;
}
- CHKiRet(parser.AddParserToList(&pCurrRuleset->pParserLst, pParser));
+ CHKiRet(parser.AddParserToList(&conf->rulesets.pCurr->pParserLst, pParser));
- dbgprintf("added parser '%s' to ruleset '%s'\n", pName, pCurrRuleset->pszName);
-RUNLOG_VAR("%p", pCurrRuleset->pParserLst);
+ dbgprintf("added parser '%s' to ruleset '%s'\n", pName, conf->rulesets.pCurr->pszName);
+RUNLOG_VAR("%p", conf->rulesets.pCurr->pParserLst);
finalize_it:
d_free(pName); /* no longer needed */
@@ -564,6 +569,12 @@ finalize_it:
RETiRet;
}
+static rsRetVal
+rulesetAddParser(void __attribute__((unused)) *pVal, uchar *pName)
+{
+ return doRulesetAddParser(ourConf, pName);
+}
+
/* queryInterface function
* rgerhards, 2008-02-21
@@ -604,7 +615,6 @@ ENDobjQueryInterface(ruleset)
* rgerhards, 2009-04-06
*/
BEGINObjClassExit(ruleset, OBJ_IS_CORE_MODULE) /* class, version */
- llDestroy(&llRulesets);
objRelease(errmsg, CORE_COMPONENT);
objRelease(rule, CORE_COMPONENT);
objRelease(parser, CORE_COMPONENT);
@@ -624,9 +634,6 @@ BEGINObjClassInit(ruleset, 1, OBJ_IS_CORE_MODULE) /* class, version */
OBJSetMethodHandler(objMethod_DEBUGPRINT, rulesetDebugPrint);
OBJSetMethodHandler(objMethod_CONSTRUCTION_FINALIZER, rulesetConstructFinalize);
- /* prepare global data */
- CHKiRet(llInit(&llRulesets, rulesetDestructForLinkedList, keyDestruct, strcasecmp));
-
/* config file handlers */
CHKiRet(regCfSysLineHdlr((uchar *)"rulesetparser", 0, eCmdHdlrGetWord, rulesetAddParser, NULL, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"rulesetcreatemainqueue", 0, eCmdHdlrBinary, rulesetCreateQueue, NULL, NULL));