summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2012-04-18 16:37:04 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2012-04-18 16:37:04 +0200
commit30b0a28786c5c198223cf2fa354d906710f68e0a (patch)
tree38e6027d5a9d2bf6d1e6424ff70ecc20ac6a6b6a /runtime
parentfba7f66590c6c60c1c08585d210734884654c912 (diff)
parentdac70ef76e14e677f11579b7d11d13ddd92c25c8 (diff)
downloadrsyslog-30b0a28786c5c198223cf2fa354d906710f68e0a.tar.gz
rsyslog-30b0a28786c5c198223cf2fa354d906710f68e0a.tar.xz
rsyslog-30b0a28786c5c198223cf2fa354d906710f68e0a.zip
Merge branch 'v6-stable'
Conflicts: runtime/msg.c runtime/ruleset.c runtime/ruleset.h
Diffstat (limited to 'runtime')
-rw-r--r--runtime/msg.c42
-rw-r--r--runtime/rsyslog.h1
-rw-r--r--runtime/ruleset.c10
-rw-r--r--runtime/ruleset.h16
4 files changed, 64 insertions, 5 deletions
diff --git a/runtime/msg.c b/runtime/msg.c
index 8f92565a..1cc5f6b4 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -36,6 +36,7 @@
#include <assert.h>
#include <ctype.h>
#include <sys/socket.h>
+#include <sys/sysinfo.h>
#include <netdb.h>
#include <libestr.h>
#include <libee/libee.h>
@@ -55,6 +56,7 @@
#include "ruleset.h"
#include "prop.h"
#include "net.h"
+#include "rsconf.h"
/* static data */
DEFobjStaticHelpers
@@ -562,6 +564,8 @@ propNameStrToID(uchar *pName, propid_t *pPropID)
*pPropID = PROP_CEE;
} else if(!strcmp((char*) pName, "$bom")) {
*pPropID = PROP_SYS_BOM;
+ } else if(!strcmp((char*) pName, "$uptime")) {
+ *pPropID = PROP_SYS_UPTIME;
} else {
*pPropID = PROP_INVALID;
iRet = RS_RET_VAR_NOT_FOUND;
@@ -1069,6 +1073,12 @@ static rsRetVal MsgSerialize(msg_t *pThis, strm_t *pStrm)
objSerializePTR(pStrm, pCSAPPNAME, CSTR);
objSerializePTR(pStrm, pCSPROCID, CSTR);
objSerializePTR(pStrm, pCSMSGID, CSTR);
+
+ if(pThis->pRuleset != NULL) {
+ rulesetGetName(pThis->pRuleset);
+ CHKiRet(obj.SerializeProp(pStrm, UCHAR_CONSTANT("pszRuleset"), PROPTYPE_PSZ,
+ rulesetGetName(pThis->pRuleset)));
+ }
/* offset must be serialized after pszRawMsg, because we need that to obtain the correct
* MSG size.
@@ -1694,6 +1704,16 @@ void MsgSetRuleset(msg_t *pMsg, ruleset_t *pRuleset)
}
+/* rgerhards 2012-04-18: set associated ruleset (by ruleset name)
+ * If ruleset cannot be found, no update is done.
+ */
+static void
+MsgSetRulesetByName(msg_t *pMsg, cstr_t *rulesetName)
+{
+ rulesetGetRuleset(runConf, &(pMsg->pRuleset), rsCStrGetSzStrNoNULL(rulesetName));
+}
+
+
/* set TAG in msg object
* (rewritten 2009-06-18 rgerhards)
*/
@@ -2673,6 +2693,23 @@ uchar *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe,
pRes = (uchar*) "\xEF\xBB\xBF";
*pbMustBeFreed = 0;
break;
+ case PROP_SYS_UPTIME:
+ {
+ struct sysinfo s_info;
+
+ if((pRes = (uchar*) MALLOC(sizeof(uchar) * 32)) == NULL) {
+ RET_OUT_OF_MEMORY;
+ }
+ *pbMustBeFreed = 1;
+
+ if(sysinfo(&s_info) < 0) {
+ *pPropLen = sizeof("**SYSCALL FAILED**") - 1;
+ return(UCHAR_CONSTANT("**SYSCALL FAILED**"));
+ }
+
+ snprintf((char*) pRes, sizeof(uchar) * 32, "%ld", s_info.uptime);
+ }
+ break;
default:
/* there is no point in continuing, we may even otherwise render the
* error message unreadable. rgerhards, 2007-07-10
@@ -3403,8 +3440,13 @@ rsRetVal MsgSetProperty(msg_t *pThis, var_t *pProp)
memcpy(&pThis->tRcvdAt, &pProp->val.vSyslogTime, sizeof(struct syslogTime));
} else if(isProp("tTIMESTAMP")) {
memcpy(&pThis->tTIMESTAMP, &pProp->val.vSyslogTime, sizeof(struct syslogTime));
+ } else if(isProp("pszRuleset")) {
+ MsgSetRulesetByName(pThis, pProp->val.pStr);
} else if(isProp("pszMSG")) {
dbgprintf("no longer supported property pszMSG silently ignored\n");
+ } else {
+ dbgprintf("unknown supported property '%s' silently ignored\n",
+ rsCStrGetSzStrNoNULL(pProp->pcsName));
}
finalize_it:
diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h
index fb0da2d2..058322bd 100644
--- a/runtime/rsyslog.h
+++ b/runtime/rsyslog.h
@@ -141,6 +141,7 @@ typedef uintTiny propid_t;
#define PROP_CEE 200
#define PROP_CEE_ALL_JSON 201
#define PROP_SYS_BOM 159
+#define PROP_SYS_UPTIME 160
/* The error codes below are orginally "borrowed" from
diff --git a/runtime/ruleset.c b/runtime/ruleset.c
index 2788f34c..c384663a 100644
--- a/runtime/ruleset.c
+++ b/runtime/ruleset.c
@@ -312,8 +312,8 @@ GetRulesetQueue(ruleset_t *pThis)
/* Find the ruleset with the given name and return a pointer to its object.
*/
-static rsRetVal
-GetRuleset(rsconf_t *conf, ruleset_t **ppRuleset, uchar *pszName)
+rsRetVal
+rulesetGetRuleset(rsconf_t *conf, ruleset_t **ppRuleset, uchar *pszName)
{
DEFiRet;
assert(ppRuleset != NULL);
@@ -335,7 +335,7 @@ SetDefaultRuleset(rsconf_t *conf, uchar *pszName)
DEFiRet;
assert(pszName != NULL);
- CHKiRet(GetRuleset(conf, &pRuleset, pszName));
+ CHKiRet(rulesetGetRuleset(conf, &pRuleset, pszName));
conf->rulesets.pDflt = pRuleset;
dbgprintf("default rule set changed to %p: '%s'\n", pRuleset, pszName);
@@ -353,7 +353,7 @@ SetCurrRuleset(rsconf_t *conf, uchar *pszName)
DEFiRet;
assert(pszName != NULL);
- CHKiRet(GetRuleset(conf, &pRuleset, pszName));
+ CHKiRet(rulesetGetRuleset(conf, &pRuleset, pszName));
conf->rulesets.pCurr = pRuleset;
dbgprintf("current rule set changed to %p: '%s'\n", pRuleset, pszName);
@@ -602,7 +602,7 @@ CODESTARTobjQueryInterface(ruleset)
pIf->SetName = setName;
pIf->DebugPrintAll = debugPrintAll;
pIf->GetCurrent = GetCurrent;
- pIf->GetRuleset = GetRuleset;
+ pIf->GetRuleset = rulesetGetRuleset;
pIf->SetDefaultRuleset = SetDefaultRuleset;
pIf->SetCurrRuleset = SetCurrRuleset;
pIf->GetRulesetQueue = GetRulesetQueue;
diff --git a/runtime/ruleset.h b/runtime/ruleset.h
index 9d50f6f7..f4443e18 100644
--- a/runtime/ruleset.h
+++ b/runtime/ruleset.h
@@ -69,7 +69,23 @@ PROTOTYPEObj(ruleset);
/* TODO: remove these -- currently done dirty for config file
* redo -- rgerhards, 2011-04-19
+ * rgerhards, 2012-04-19: actually, it may be way cooler not to remove
+ * them and use plain c-style conventions at least inside core objects.
*/
rsRetVal rulesetDestructForLinkedList(void *pData);
rsRetVal rulesetKeyDestruct(void __attribute__((unused)) *pData);
+
+/* Get name associated to ruleset. This function cannot fail (except,
+ * of course, if previously something went really wrong). Returned
+ * pointer is read-only.
+ * rgerhards, 2012-04-18
+ */
+static inline uchar*
+rulesetGetName(ruleset_t *pRuleset)
+{
+ return pRuleset->pszName;
+}
+
+
+rsRetVal rulesetGetRuleset(rsconf_t *conf, ruleset_t **ppRuleset, uchar *pszName);
#endif /* #ifndef INCLUDED_RULESET_H */