summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2011-02-25 14:46:07 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2011-02-25 14:46:07 +0100
commit74a71e798efd58e20cc150b04de2613bf518eed4 (patch)
tree5b0b04e1b44912c6a143b180dead5b62e4390343 /runtime
parenta8760241a30dc2618c53c569d23acdec1e06908e (diff)
parent5b1cd3330196c5ffa2b8695798946aa2441b7e84 (diff)
downloadrsyslog-74a71e798efd58e20cc150b04de2613bf518eed4.tar.gz
rsyslog-74a71e798efd58e20cc150b04de2613bf518eed4.tar.xz
rsyslog-74a71e798efd58e20cc150b04de2613bf518eed4.zip
Merge branch 'v5-beta'
Conflicts: ChangeLog configure.ac doc/manual.html
Diffstat (limited to 'runtime')
-rw-r--r--runtime/batch.h8
-rw-r--r--runtime/msg.c10
-rw-r--r--runtime/msg.h3
-rw-r--r--runtime/queue.c5
-rw-r--r--runtime/ruleset.c23
5 files changed, 38 insertions, 11 deletions
diff --git a/runtime/batch.h b/runtime/batch.h
index d0504f2b..944889bd 100644
--- a/runtime/batch.h
+++ b/runtime/batch.h
@@ -136,11 +136,16 @@ batchIsValidElem(batch_t *pBatch, int i) {
/* copy one batch element to another.
* This creates a complete duplicate in those cases where
* it is needed. Use duplication only when absolutely necessary!
+ * Note that all working fields are reset to zeros. If that were
+ * not done, we would have potential problems with invalid
+ * or double pointer frees.
* rgerhards, 2010-06-10
*/
static inline void
batchCopyElem(batch_obj_t *pDest, batch_obj_t *pSrc) {
- memcpy(pDest, pSrc, sizeof(batch_obj_t));
+ memset(pDest, 0, sizeof(batch_obj_t));
+ pDest->pUsrp = pSrc->pUsrp;
+ pDest->state = pSrc->state;
}
@@ -171,6 +176,7 @@ batchFree(batch_t *pBatch) {
static inline rsRetVal
batchInit(batch_t *pBatch, int maxElem) {
DEFiRet;
+ pBatch->iDoneUpTo = 0;
pBatch->maxElem = maxElem;
CHKmalloc(pBatch->pElem = calloc((size_t)maxElem, sizeof(batch_obj_t)));
// TODO: replace calloc by inidividual writes?
diff --git a/runtime/msg.c b/runtime/msg.c
index ad045dec..70b20749 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -686,6 +686,7 @@ static inline rsRetVal msgBaseConstruct(msg_t **ppThis)
/* initialize members in ORDER they appear in structure (think "cache line"!) */
pM->flowCtlType = 0;
pM->bDoLock = 0;
+ pM->bAlreadyFreed = 0;
pM->iRefCount = 1;
pM->iSeverity = -1;
pM->iFacility = -1;
@@ -813,6 +814,15 @@ CODESTARTobjDestruct(msg)
if(currRefCount == 0)
{
/* DEV Debugging Only! dbgprintf("msgDestruct\t0x%lx, RefCount now 0, doing DESTROY\n", (unsigned long)pThis); */
+ /* The if below is included to try to nail down a well-hidden bug causing
+ * segfaults. I hope that do to the test code the problem is sooner detected and
+ * thus we get better data for debugging and resolving it. -- rgerhards, 2011-02-23.
+ * TODO: remove when no longer needed.
+ */
+ if(pThis->bAlreadyFreed)
+ abort();
+ pThis->bAlreadyFreed = 1;
+ /* end debug code */
if(pThis->pszRawMsg != pThis->szRawMsg)
free(pThis->pszRawMsg);
freeTAG(pThis);
diff --git a/runtime/msg.h b/runtime/msg.h
index 1fd95994..01a1e059 100644
--- a/runtime/msg.h
+++ b/runtime/msg.h
@@ -63,7 +63,8 @@ struct msg {
once data has entered the queue, this property is no longer needed. */
pthread_mutex_t mut;
int iRefCount; /* reference counter (0 = unused) */
- sbool bDoLock; /* use the mutex? */
+ sbool bDoLock; /* use the mutex? */
+ sbool bAlreadyFreed; /* aid to help detect a well-hidden bad bug -- TODO: remove when no longer needed */
short iSeverity; /* the severity 0..7 */
short iFacility; /* Facility code 0 .. 23*/
short offAfterPRI; /* offset, at which raw message WITHOUT PRI part starts in pszRawMsg */
diff --git a/runtime/queue.c b/runtime/queue.c
index 76327f6a..ef6e843b 100644
--- a/runtime/queue.c
+++ b/runtime/queue.c
@@ -842,6 +842,7 @@ static rsRetVal qAddDirect(qqueue_t *pThis, void* pUsr)
{
batch_t singleBatch;
batch_obj_t batchObj;
+ int i;
DEFiRet;
//TODO: init batchObj (states _OK and new fields -- CHECK)
@@ -863,6 +864,10 @@ static rsRetVal qAddDirect(qqueue_t *pThis, void* pUsr)
singleBatch.nElem = 1; /* there always is only one in direct mode */
singleBatch.pElem = &batchObj;
iRet = pThis->pConsumer(pThis->pUsr, &singleBatch, &pThis->bShutdownImmediate);
+ /* delete the batch string params: TODO: create its own "class" for this */
+ for(i = 0 ; i < CONF_OMOD_NUMSTRINGS_MAXSIZE ; ++i) {
+ free(batchObj.staticActStrings[i]);
+ }
objDestruct(pUsr);
RETiRet;
diff --git a/runtime/ruleset.c b/runtime/ruleset.c
index 8162c752..f48c2c2d 100644
--- a/runtime/ruleset.c
+++ b/runtime/ruleset.c
@@ -171,35 +171,40 @@ processBatchMultiRuleset(batch_t *pBatch)
int i;
int iStart; /* start index of partial batch */
int iNew; /* index for new (temporary) batch */
+ int bHaveUnprocessed; /* do we (still) have unprocessed entries? (loop term predicate) */
DEFiRet;
- CHKiRet(batchInit(&snglRuleBatch, pBatch->nElem));
- snglRuleBatch.pbShutdownImmediate = pBatch->pbShutdownImmediate;
-
- while(1) { /* loop broken inside */
+ do {
+ bHaveUnprocessed = 0;
/* search for first unprocessed element */
for(iStart = 0 ; iStart < pBatch->nElem && pBatch->pElem[iStart].state == BATCH_STATE_DISC ; ++iStart)
/* just search, no action */;
-
if(iStart == pBatch->nElem)
- FINALIZE; /* everything processed */
+ break; /* everything processed */
/* prepare temporary batch */
+ CHKiRet(batchInit(&snglRuleBatch, pBatch->nElem));
+ snglRuleBatch.pbShutdownImmediate = pBatch->pbShutdownImmediate;
currRuleset = batchElemGetRuleset(pBatch, iStart);
iNew = 0;
for(i = iStart ; i < pBatch->nElem ; ++i) {
if(batchElemGetRuleset(pBatch, i) == currRuleset) {
- batchCopyElem(&(snglRuleBatch.pElem[iNew++]), &(pBatch->pElem[i]));
+ /* for performance reasons, we copy only those members that we actually need */
+ snglRuleBatch.pElem[iNew].pUsrp = pBatch->pElem[i].pUsrp;
+ snglRuleBatch.pElem[iNew].state = pBatch->pElem[i].state;
+ ++iNew;
/* We indicate the element also as done, so it will not be processed again */
pBatch->pElem[i].state = BATCH_STATE_DISC;
+ } else {
+ bHaveUnprocessed = 1;
}
}
snglRuleBatch.nElem = iNew; /* was left just right by the for loop */
batchSetSingleRuleset(&snglRuleBatch, 1);
/* process temp batch */
processBatch(&snglRuleBatch);
- }
- batchFree(&snglRuleBatch);
+ batchFree(&snglRuleBatch);
+ } while(bHaveUnprocessed == 1);
finalize_it:
RETiRet;