summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-06-23 14:50:03 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-06-23 14:50:03 +0200
commitb50d13a6a97c0b6fa14807775ae0edf52ef015fb (patch)
tree86817355dc2631e21b7b4e2977ecbbf9007537cd
parent6181156b1c42825bac892d3e1284dcb2d4fcf5d3 (diff)
downloadrsyslog-b50d13a6a97c0b6fa14807775ae0edf52ef015fb.tar.gz
rsyslog-b50d13a6a97c0b6fa14807775ae0edf52ef015fb.tar.xz
rsyslog-b50d13a6a97c0b6fa14807775ae0edf52ef015fb.zip
restored repeated message reduction processing
-rw-r--r--action.c22
-rw-r--r--runtime/msg.c70
-rw-r--r--runtime/msg.h5
-rw-r--r--runtime/rsyslog.h3
-rw-r--r--runtime/ruleset.c7
-rw-r--r--tools/syslogd.c1
6 files changed, 69 insertions, 39 deletions
diff --git a/action.c b/action.c
index d214e808..2040d6bd 100644
--- a/action.c
+++ b/action.c
@@ -4,7 +4,7 @@
*
* File begun on 2007-08-06 by RGerhards (extracted from syslogd.c)
*
- * Copyright 2007 Rainer Gerhards and Adiscon GmbH.
+ * Copyright 2007-2009 Rainer Gerhards and Adiscon GmbH.
*
* This file is part of rsyslog.
*
@@ -239,10 +239,7 @@ rsRetVal actionConstruct(action_t **ppThis)
ASSERT(ppThis != NULL);
- if((pThis = (action_t*) calloc(1, sizeof(action_t))) == NULL) {
- ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
- }
-
+ CHKmalloc(pThis = (action_t*) calloc(1, sizeof(action_t)));
pThis->iResumeInterval = glbliActionResumeInterval;
pThis->iResumeRetryCount = glbliActionResumeRetryCount;
pThis->tLastOccur = time(NULL); /* done once per action on startup only */
@@ -658,7 +655,7 @@ actionWriteToAction(action_t *pAction)
if(pAction->iNbrNoExec < pAction->iExecEveryNthOccur - 1) {
++pAction->iNbrNoExec;
dbgprintf("action %p passed %d times to execution - less than neded - discarding\n",
- pAction, pAction->iNbrNoExec);
+ pAction, pAction->iNbrNoExec);
FINALIZE;
} else {
pAction->iNbrNoExec = 0; /* we execute the action now, so the number of no execs is down to */
@@ -675,6 +672,7 @@ actionWriteToAction(action_t *pAction)
*/
if(pAction->f_prevcount > 1) {
msg_t *pMsg;
+ size_t lenRepMsg;
uchar szRepMsg[1024];
if((pMsg = MsgDup(pAction->f_pMsg)) == NULL) {
@@ -684,23 +682,19 @@ actionWriteToAction(action_t *pAction)
}
if(pAction->bRepMsgHasMsg == 0) { /* old format repeat message? */
- snprintf((char*)szRepMsg, sizeof(szRepMsg), "last message repeated %d times",
+ lenRepMsg = snprintf((char*)szRepMsg, sizeof(szRepMsg), " last message repeated %d times",
pAction->f_prevcount);
} else {
- snprintf((char*)szRepMsg, sizeof(szRepMsg), "message repeated %d times: [%.800s]",
+ lenRepMsg = snprintf((char*)szRepMsg, sizeof(szRepMsg), " message repeated %d times: [%.800s]",
pAction->f_prevcount, getMSG(pAction->f_pMsg));
}
- /* We now need to update the other message properties.
- * ... RAWMSG is a problem ... Please note that digital
+ /* We now need to update the other message properties. Please note that digital
* signatures inside the message are also invalidated.
*/
datetime.getCurrTime(&(pMsg->tRcvdAt), &(pMsg->ttGenTime));
memcpy(&pMsg->tTIMESTAMP, &pMsg->tRcvdAt, sizeof(struct syslogTime));
-#pragma warn "need fix msg repeationg handling"
- //MsgSetMSG(pMsg, (char*)szRepMsg);
- MsgSetRawMsgWOSize(pMsg, (char*)szRepMsg);
-
+ MsgReplaceMSG(pMsg, szRepMsg, lenRepMsg);
pMsgSave = pAction->f_pMsg; /* save message pointer for later restoration */
pAction->f_pMsg = pMsg; /* use the new msg (pointer will be restored below) */
}
diff --git a/runtime/msg.c b/runtime/msg.c
index 6ad0ee4f..8c306aca 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -1733,38 +1733,76 @@ void MsgSetHOSTNAME(msg_t *pMsg, uchar* pszHOSTNAME)
}
-/* rgerhards 2004-11-09: set MSG in msg object
+/* set the offset of the MSG part into the raw msg buffer
*/
void MsgSetMSGoffs(msg_t *pMsg, short offs)
{
- assert(pMsg != NULL);
-
- pMsg->iLenMSG = ustrlen(pMsg->pszRawMsg + offs);
+ ISOBJ_TYPE_assert(pMsg, msg);
+ pMsg->iLenMSG = pMsg->iLenRawMsg - offs;
pMsg->offMSG = offs;
}
+/* replace the MSG part of a message. The update actually takes place inside
+ * rawmsg.
+ * There are two cases: either the new message will be larger than the new msg
+ * or it will be less than or equal. If it is less than or equal, we can utilize
+ * the previous message buffer. If it is larger, we can utilize the msg_t-included
+ * message buffer if it fits in there. If this is not the case, we need to alloc
+ * a new, larger, chunk and copy over the data to it. Note that this function is
+ * (hopefully) relatively seldom being called, so some performance impact is
+ * uncritical. In any case, pszMSG is copied, so if it was dynamically allocated,
+ * the caller is responsible for freeing it.
+ * rgerhards, 2009-06-23
+ */
+rsRetVal MsgReplaceMSG(msg_t *pThis, uchar* pszMSG, int lenMSG)
+{
+ int lenNew;
+ uchar *bufNew;
+ DEFiRet;
+ ISOBJ_TYPE_assert(pThis, msg);
+ assert(pszMSG != NULL);
+
+ lenNew = pThis->iLenRawMsg + lenMSG - pThis->iLenMSG;
+ if(lenMSG > pThis->iLenMSG && lenNew >= CONF_RAWMSG_BUFSIZE) {
+ /* we have lost and need to alloc a new buffer ;) */
+ CHKmalloc(bufNew = malloc(lenNew + 1));
+ memcpy(bufNew, pThis->pszRawMsg, pThis->offMSG);
+ free(pThis->pszRawMsg);
+ pThis->pszRawMsg = bufNew;
+ }
+
+ memcpy(pThis->pszRawMsg + pThis->offMSG, pszMSG, lenMSG);
+ pThis->pszRawMsg[lenNew] = '\0'; /* this also works with truncation! */
+ pThis->iLenRawMsg = lenNew;
+ pThis->iLenMSG = lenMSG;
+
+finalize_it:
+ RETiRet;
+}
+
+
/* set raw message in message object. Size of message is provided.
* rgerhards, 2009-06-16
*/
-void MsgSetRawMsg(msg_t *pMsg, char* pszRawMsg, size_t lenMsg)
+void MsgSetRawMsg(msg_t *pThis, char* pszRawMsg, size_t lenMsg)
{
- assert(pMsg != NULL);
- if(pMsg->pszRawMsg != pMsg->szRawMsg)
- free(pMsg->pszRawMsg);
+ assert(pThis != NULL);
+ if(pThis->pszRawMsg != pThis->szRawMsg)
+ free(pThis->pszRawMsg);
- pMsg->iLenRawMsg = lenMsg;
- if(pMsg->iLenRawMsg < CONF_RAWMSG_BUFSIZE) {
+ pThis->iLenRawMsg = lenMsg;
+ if(pThis->iLenRawMsg < CONF_RAWMSG_BUFSIZE) {
/* small enough: use fixed buffer (faster!) */
- pMsg->pszRawMsg = pMsg->szRawMsg;
- } else if((pMsg->pszRawMsg = (uchar*) malloc(pMsg->iLenRawMsg + 1)) == NULL) {
+ pThis->pszRawMsg = pThis->szRawMsg;
+ } else if((pThis->pszRawMsg = (uchar*) malloc(pThis->iLenRawMsg + 1)) == NULL) {
/* truncate message, better than completely loosing it... */
- pMsg->pszRawMsg = pMsg->szRawMsg;
- pMsg->iLenRawMsg = CONF_RAWMSG_BUFSIZE - 1;
+ pThis->pszRawMsg = pThis->szRawMsg;
+ pThis->iLenRawMsg = CONF_RAWMSG_BUFSIZE - 1;
}
- memcpy(pMsg->pszRawMsg, pszRawMsg, pMsg->iLenRawMsg);
- pMsg->pszRawMsg[pMsg->iLenRawMsg] = '\0'; /* this also works with truncation! */
+ memcpy(pThis->pszRawMsg, pszRawMsg, pThis->iLenRawMsg);
+ pThis->pszRawMsg[pThis->iLenRawMsg] = '\0'; /* this also works with truncation! */
}
diff --git a/runtime/msg.h b/runtime/msg.h
index 9113882a..c38cb788 100644
--- a/runtime/msg.h
+++ b/runtime/msg.h
@@ -28,10 +28,6 @@
#ifndef MSG_H_INCLUDED
#define MSG_H_INCLUDED 1
-/* some configuration constants */
-#define CONF_RAWMSG_BUFSIZE 101
-#define CONF_TAG_BUFSIZE 33 /* RFC says 32 chars (+ \0), but in practice we see longer ones... */
-
#include <pthread.h>
#include "obj.h"
#include "syslogd-types.h"
@@ -162,6 +158,7 @@ rsRetVal MsgSetAfterPRIOffs(msg_t *pMsg, short offs);
void MsgSetMSGoffs(msg_t *pMsg, short offs);
void MsgSetRawMsgWOSize(msg_t *pMsg, char* pszRawMsg);
void MsgSetRawMsg(msg_t *pMsg, char* pszRawMsg, size_t lenMsg);
+rsRetVal MsgReplaceMSG(msg_t *pThis, uchar* pszMSG, int lenMSG);
void moveHOSTNAMEtoTAG(msg_t *pM);
char *MsgGetProp(msg_t *pMsg, struct templateEntry *pTpe,
cstr_t *pCSPropName, size_t *pPropLen, unsigned short *pbMustBeFreed);
diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h
index ac068d5e..793df782 100644
--- a/runtime/rsyslog.h
+++ b/runtime/rsyslog.h
@@ -31,6 +31,9 @@
* ############################################################# */
#define RS_STRINGBUF_ALLOC_INCREMENT 128
#define CONF_TAG_MAXSIZE 512 /* a value that is deemed far too large for any valid TAG */
+#define CONF_RAWMSG_BUFSIZE 101
+#define CONF_TAG_BUFSIZE 33 /* RFC says 32 chars (+ \0), but in practice we see longer ones... */
+
/* ############################################################# *
* # End Config Settings # *
diff --git a/runtime/ruleset.c b/runtime/ruleset.c
index 93d40e24..d98b4217 100644
--- a/runtime/ruleset.c
+++ b/runtime/ruleset.c
@@ -84,7 +84,6 @@ DEFFUNC_llExecFunc(doIterateRulesetActions)
iRet = rule.IterateAllActions(pRule, pMyParam->pFunc, pMyParam->pParam);
RETiRet;
}
-#if 0
/* iterate over all actions of THIS rule set.
*/
static rsRetVal
@@ -96,7 +95,7 @@ iterateRulesetAllActions(ruleset_t *pThis, rsRetVal (*pFunc)(void*, void*), void
params.pFunc = pFunc;
params.pParam = pParam;
- CHKiRet(llExecFunc(&llRulesets, doIterateRulesetActions, &params));
+ CHKiRet(llExecFunc(&(pThis->llRules), doIterateRulesetActions, &params));
finalize_it:
RETiRet;
@@ -112,7 +111,6 @@ DEFFUNC_llExecFunc(doIterateAllActions)
iRet = iterateRulesetAllActions(pThis, pMyParam->pFunc, pMyParam->pParam);
RETiRet;
}
-#endif
/* iterate over ALL actions present in the WHOLE system.
* this is often needed, for example when HUP processing
* must be done or a shutdown is pending.
@@ -126,8 +124,7 @@ iterateAllActions(rsRetVal (*pFunc)(void*, void*), void* pParam)
params.pFunc = pFunc;
params.pParam = pParam;
- //CHKiRet(llExecFunc(&llRulesets, doIterateAllActions, &params));
- CHKiRet(llExecFunc(&llRulesets, doIterateRulesetActions, &params));
+ CHKiRet(llExecFunc(&llRulesets, doIterateAllActions, &params));
finalize_it:
RETiRet;
diff --git a/tools/syslogd.c b/tools/syslogd.c
index ed826fc1..178ad455 100644
--- a/tools/syslogd.c
+++ b/tools/syslogd.c
@@ -1469,6 +1469,7 @@ DEFFUNC_llExecFunc(flushRptdMsgsActions)
assert(pAction != NULL);
BEGINfunc
+RUNLOG_VAR("%p", pAction);
LockObj(pAction);
/* TODO: time() performance: the call below could be moved to
* the beginn of the llExec(). This makes it slightly less correct, but