summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-06-10 19:03:38 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-06-10 19:03:38 +0200
commit1c8fe77b78a64d69138b30ec28b430677b197601 (patch)
tree00fa6fb834c1ba9d185b989f641f133b5e552b0b
parent6141845f7514622f77d308b7aadb15891d3a627a (diff)
downloadrsyslog-1c8fe77b78a64d69138b30ec28b430677b197601.tar.gz
rsyslog-1c8fe77b78a64d69138b30ec28b430677b197601.tar.xz
rsyslog-1c8fe77b78a64d69138b30ec28b430677b197601.zip
added $Ruleset config command
so we now can define multiple rule sets, we just can not use them ;) That means we have the foundation to bind listeners to different rule sets.
-rw-r--r--doc/rsyslog_conf_global.html2
-rw-r--r--runtime/conf.c6
-rw-r--r--runtime/rule.c22
-rw-r--r--runtime/rule.h3
-rw-r--r--tools/syslogd.c27
5 files changed, 57 insertions, 3 deletions
diff --git a/doc/rsyslog_conf_global.html b/doc/rsyslog_conf_global.html
index 1e268f4b..e9b1c082 100644
--- a/doc/rsyslog_conf_global.html
+++ b/doc/rsyslog_conf_global.html
@@ -201,6 +201,8 @@ line is that n is large enough to get a good idea which message was repeated but
large enough for the whole message. (Introduced with 4.1.5). Once set, it affects all following actions.</li>
<li><a href="rsconf1_repeatedmsgreduction.html">$RepeatedMsgReduction</a></li>
<li><a href="rsconf1_resetconfigvariables.html">$ResetConfigVariables</a></li>
+<li><b>$Ruleset</b> name - starts a new ruleset. All following actions belong to
+that new rule set.</li>
<li><b>$OptimizeForUniprocessor</b> [on/<b>off</b>] - turns on optimizatons which lead to better
performance on uniprocessors. If you run on multicore-machiens, turning this off lessens CPU load. The
default may change as uniprocessor systems become less common. [available since 4.1.0]</li>
diff --git a/runtime/conf.c b/runtime/conf.c
index e0ed3d6a..014d5a9a 100644
--- a/runtime/conf.c
+++ b/runtime/conf.c
@@ -471,7 +471,7 @@ processConfFile(uchar *pConfFile)
/* we probably have one selector left to be added - so let's do that now */
if(pCurrRule != NULL) {
- CHKiRet(ruleset.AddRule(pCurrRuleset, &pCurrRule));
+ CHKiRet(ruleset.AddRule(rule.GetAssRuleset(pCurrRule), &pCurrRule));
}
/* close the configuration file */
@@ -1141,9 +1141,10 @@ cflineClassic(uchar *p, rule_t **ppRule)
* all. -- rgerhards, 2007-08-01
*/
if(*ppRule != NULL) {
- CHKiRet(ruleset.AddRule(pCurrRuleset, ppRule));
+ CHKiRet(ruleset.AddRule(rule.GetAssRuleset(*ppRule), ppRule));
}
CHKiRet(rule.Construct(ppRule)); /* create "fresh" selector */
+ CHKiRet(rule.SetAssRuleset(*ppRule, pCurrRuleset)); /* create "fresh" selector */
CHKiRet(rule.ConstructFinalize(*ppRule)); /* create "fresh" selector */
CHKiRet(cflineDoFilter(&p, *ppRule)); /* pull filters */
}
@@ -1166,7 +1167,6 @@ cfline(uchar *line, rule_t **pfCurr)
DEFiRet;
ASSERT(line != NULL);
-if(*pfCurr != NULL){ ISOBJ_TYPE_assert(*pfCurr, rule);}
dbgprintf("cfline: '%s'\n", line);
diff --git a/runtime/rule.c b/runtime/rule.c
index c157242c..f17c524e 100644
--- a/runtime/rule.c
+++ b/runtime/rule.c
@@ -320,6 +320,26 @@ CODESTARTobjDestruct(rule)
ENDobjDestruct(rule)
+/* set the associated ruleset */
+static rsRetVal
+setAssRuleset(rule_t *pThis, ruleset_t *pRuleset)
+{
+ DEFiRet;
+ ISOBJ_TYPE_assert(pThis, rule);
+ ISOBJ_TYPE_assert(pRuleset, ruleset);
+ pThis->pRuleset = pRuleset;
+ RETiRet;
+}
+
+/* get the associated ruleset (may be NULL if not set!) */
+static ruleset_t*
+getAssRuleset(rule_t *pThis)
+{
+ ISOBJ_TYPE_assert(pThis, rule);
+ return pThis->pRuleset;
+}
+
+
/* helper to DebugPrint, to print out all actions via
* the llExecFunc() facility.
*/
@@ -393,6 +413,8 @@ CODESTARTobjQueryInterface(rule)
pIf->IterateAllActions = iterateAllActions;
pIf->ProcessMsg = processMsg;
+ pIf->SetAssRuleset = setAssRuleset;
+ pIf->GetAssRuleset = getAssRuleset;
finalize_it:
ENDobjQueryInterface(rule)
diff --git a/runtime/rule.h b/runtime/rule.h
index 96be9e30..38b11c63 100644
--- a/runtime/rule.h
+++ b/runtime/rule.h
@@ -53,6 +53,7 @@ struct rule_s {
expr_t *f_expr; /* expression object */
} f_filterData;
+ ruleset_t *pRuleset; /* associated ruleset */
linkedList_t llActList; /* list of configured actions */
};
@@ -64,6 +65,8 @@ BEGINinterface(rule) /* name must also be changed in ENDinterface macro! */
rsRetVal (*Destruct)(rule_t **ppThis);
rsRetVal (*IterateAllActions)(rule_t *pThis, rsRetVal (*pFunc)(void*, void*), void *pParam);
rsRetVal (*ProcessMsg)(rule_t *pThis, msg_t *pMsg);
+ rsRetVal (*SetAssRuleset)(rule_t *pThis, ruleset_t*);
+ ruleset_t* (*GetAssRuleset)(rule_t *pThis);
ENDinterface(rule)
#define ruleCURR_IF_VERSION 1 /* increment whenever you change the interface structure! */
diff --git a/tools/syslogd.c b/tools/syslogd.c
index 183c7760..f4b59970 100644
--- a/tools/syslogd.c
+++ b/tools/syslogd.c
@@ -2398,6 +2398,32 @@ finalize_it:
}
+/* Begin a new rule set. The new rule set is created, and all rules that now
+ * follow go into that rule set.
+ * TODO: we may later add the capability to switch back to an already existing
+ * rule set.
+ * NOTE: pCurrRuleset is NOT desructed and must not be! The ruleset class keeps
+ * a list of all known rule sets, and can destruct them at the end of execution.
+ * pCurrRuleset is just a shortcut so that "everyone" knows which ruleset to
+ * extend.
+ * TODO: A problem with this function is the way config lines are processed. The rule
+ * is actually only written when the next rule is completely read. That way, this
+ * (past) rule goes into the wrong (new) ruleset. I need to see how to fix this best...
+ * rgerhards, 2009-06-10
+ */
+static rsRetVal beginNewRuleset(void __attribute__((unused)) *pVal, uchar *pszName)
+{
+ DEFiRet;
+ CHKiRet(ruleset.Construct(&pCurrRuleset));
+ CHKiRet(ruleset.SetName(pCurrRuleset, pszName));
+ CHKiRet(ruleset.ConstructFinalize(pCurrRuleset));
+
+finalize_it:
+ free(pszName); /* no longer needed */
+ RETiRet;
+}
+
+
/* set the main message queue mode
* rgerhards, 2008-01-03
*/
@@ -2651,6 +2677,7 @@ static rsRetVal loadBuildInModules(void)
* This, I think, is the right thing to do. -- rgerhards, 2007-07-31
*/
CHKiRet(regCfSysLineHdlr((uchar *)"actionresumeretrycount", 0, eCmdHdlrInt, NULL, &glbliActionResumeRetryCount, NULL));
+ CHKiRet(regCfSysLineHdlr((uchar *)"ruleset", 0, eCmdHdlrGetWord, beginNewRuleset, NULL, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"mainmsgqueuefilename", 0, eCmdHdlrGetWord, NULL, &pszMainMsgQFName, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"mainmsgqueuesize", 0, eCmdHdlrInt, NULL, &iMainMsgQueueSize, NULL));
CHKiRet(regCfSysLineHdlr((uchar *)"mainmsgqueuehighwatermark", 0, eCmdHdlrInt, NULL, &iMainMsgQHighWtrMark, NULL));