From dccadb677c5a6b8379f631e4c1f14c8c4089d4a6 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Sun, 21 Mar 2010 18:52:51 +0100 Subject: 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). --- tools/omfile.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'tools') 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 #include #include +#include #ifdef OS_SOLARIS # include @@ -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 -- cgit