summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2010-03-21 18:52:51 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2010-03-21 18:52:51 +0100
commitdccadb677c5a6b8379f631e4c1f14c8c4089d4a6 (patch)
tree8a1beb0a96dae348762322e5d3917dc5c5c87e80
parent95cde529cc2d2aab2047f5ab2c52d9cd8ba23f31 (diff)
downloadrsyslog-dccadb677c5a6b8379f631e4c1f14c8c4089d4a6.tar.gz
rsyslog-dccadb677c5a6b8379f631e4c1f14c8c4089d4a6.tar.xz
rsyslog-dccadb677c5a6b8379f631e4c1f14c8c4089d4a6.zip
exp: made omfile ensure that it is not called twice in parallel on the same file instance
In theory, the rsyslog core should never call in parallel into an output module for the same instance. However, it looks like this seems to happen under (strange?) circumstances. I have now enhanced omfile so that it guards itself against being called in parallel on the same instance data. This is done to help troubleshooting and may stay as an interim solution if it proves to solve an anomaly we see in at least one installation (to trigger this problem, an extremely large traffic volume is needed).
-rw-r--r--tools/omfile.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/tools/omfile.c b/tools/omfile.c
index c4e834cc..f4db7dab 100644
--- a/tools/omfile.c
+++ b/tools/omfile.c
@@ -48,6 +48,7 @@
#include <libgen.h>
#include <unistd.h>
#include <sys/file.h>
+#include <pthread.h>
#ifdef OS_SOLARIS
# include <fcntl.h>
@@ -65,6 +66,7 @@
#include "stream.h"
#include "unicode-helper.h"
#include "atomic.h"
+#include "debug.h"
MODULE_TYPE_OUTPUT
@@ -134,6 +136,7 @@ typedef struct _instanceData {
int iIOBufSize; /* size of associated io buffer */
int iFlushInterval; /* how fast flush buffer on inactivity? */
bool bFlushOnTXEnd; /* flush write buffers when transaction has ended? */
+ pthread_mutex_t mutEx; /* guard ourselves against being called multiple times with the same instance */
} instanceData;
@@ -603,6 +606,7 @@ finalize_it:
BEGINcreateInstance
CODESTARTcreateInstance
pData->pStrm = NULL;
+ pthread_mutex_init(&pData->mutEx, NULL);
ENDcreateInstance
@@ -612,6 +616,7 @@ CODESTARTfreeInstance
dynaFileFreeCache(pData);
} else if(pData->pStrm != NULL)
strm.Destruct(&pData->pStrm);
+ pthread_mutex_destroy(&pData->mutEx);
ENDfreeInstance
@@ -621,12 +626,14 @@ ENDtryResume
BEGINdoAction
CODESTARTdoAction
+ d_pthread_mutex_lock(&pData->mutEx);
DBGPRINTF("file to log to: %s\n", pData->f_fname);
CHKiRet(writeFile(ppString, iMsgOpts, pData));
if(pData->bFlushOnTXEnd) {
/* TODO v5: do this in endTransaction only! */
CHKiRet(strm.Flush(pData->pStrm));
}
+ d_pthread_mutex_unlock(&pData->mutEx);
finalize_it:
ENDdoAction
@@ -764,6 +771,7 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a
BEGINdoHUP
CODESTARTdoHUP
+ d_pthread_mutex_lock(&pData->mutEx);
if(pData->bDynamicName) {
dynaFileFreeCacheEntries(pData);
} else {
@@ -772,6 +780,7 @@ CODESTARTdoHUP
pData->pStrm = NULL;
}
}
+ d_pthread_mutex_unlock(&pData->mutEx);
ENDdoHUP