diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2012-11-05 13:01:25 +0100 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2012-11-05 13:01:25 +0100 |
commit | 557f20f84114bb20b578b43a3b9d33bed64fc49c (patch) | |
tree | 3c7abd45137a2116de271ab1a0dd63f64f34431d /runtime/stream.c | |
parent | 9ab150318063524b41176d587e0c0f7e4edf6472 (diff) | |
download | rsyslog-557f20f84114bb20b578b43a3b9d33bed64fc49c.tar.gz rsyslog-557f20f84114bb20b578b43a3b9d33bed64fc49c.tar.bz2 rsyslog-557f20f84114bb20b578b43a3b9d33bed64fc49c.zip |
bugfix: dynafile zip files could be corrupted
This could happen if a dynafile was destructed before the first write.
In practice, this could happen if few lines were written to a file and
it then became evicted from the dynafile cache. This would probably
look very random, because it depended on the timing in regard to
message volume and dynafile cache size.
Diffstat (limited to 'runtime/stream.c')
-rw-r--r-- | runtime/stream.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/runtime/stream.c b/runtime/stream.c index b8dd5150..26abeb39 100644 --- a/runtime/stream.c +++ b/runtime/stream.c @@ -343,6 +343,9 @@ static rsRetVal strmCloseFile(strm_t *pThis) if(pThis->tOperationsMode != STREAMMODE_READ) { strmFlushInternal(pThis, 0); + if(pThis->iZipLevel) { + doZipFinish(pThis); + } if(pThis->bAsyncWrite) { strmWaitAsyncWriterDone(pThis); } @@ -780,9 +783,6 @@ BEGINobjDestruct(strm) /* be sure to specify the object type also in END and COD int i; CODESTARTobjDestruct(strm) /* we need to stop the ZIP writer */ - if(pThis->iZipLevel) { - doZipFinish(pThis); - } if(pThis->bAsyncWrite) /* Note: mutex will be unlocked in stopWriter! */ d_pthread_mutex_lock(&pThis->mut); @@ -1231,11 +1231,9 @@ doZipFinish(strm_t *pThis) unsigned outavail; assert(pThis != NULL); - if(!pThis->bzInitDone) { - FINALIZE; - } + if(!pThis->bzInitDone) + goto done; -dbgprintf("AAAA: doZipFinish() called\n"); pThis->zstrm.avail_in = 0; /* run deflate() on buffer until everything has been compressed */ do { @@ -1257,7 +1255,7 @@ finalize_it: } pThis->bzInitDone = 0; - RETiRet; +done: RETiRet; } /* flush stream output buffer to persistent storage. This can be called at any time @@ -1423,7 +1421,7 @@ strmWrite(strm_t *pThis, uchar *pBuf, size_t lenBuf) ASSERT(pThis != NULL); ASSERT(pBuf != NULL); -//DBGPRINTF("strmWrite(%p, '%65.65s', %ld);, disabled %d, sizelim %ld, size %lld\n", pThis, pBuf,lenBuf, pThis->bDisabled, pThis->iSizeLimit, pThis->iCurrOffs); + /* DEV DEBUG ONLY DBGPRINTF("strmWrite(%p[%s], '%65.65s', %ld);, disabled %d, sizelim %ld, size %lld\n", pThis, pThis->pszCurrFName, pBuf,(long) lenBuf, pThis->bDisabled, (long) pThis->iSizeLimit, (long long) pThis->iCurrOffs); */ if(pThis->bAsyncWrite) d_pthread_mutex_lock(&pThis->mut); |