File rsyslog-flush-dyn-file.patch of Package rsyslog.5379
Index: rsyslog-8.4.0/tools/omfile.c
===================================================================
--- rsyslog-8.4.0.orig/tools/omfile.c
+++ rsyslog-8.4.0/tools/omfile.c
@@ -1047,10 +1047,29 @@ BEGINcommitTransaction
instanceData *__restrict__ const pData = pWrkrData->pData;
unsigned i;
CODESTARTcommitTransaction
+ strm_t *lastStream = NULL;
+
pthread_mutex_lock(&pData->mutWrite);
for(i = 0 ; i < nParams ; ++i) {
writeFile(pData, pParams, i);
+
+ /* If prepareDynFile() is called inside writeFile(),
+ * it could switch pData->pStrm in batch mode. When
+ * this happens, make sure we flush the old pStrm
+ * because the last flush will not cover it.
+ *
+ * Note, I'm not sure about the life cycle of these
+ * strm_t (they seem to be managed ins pCache[]), if
+ * lastStream points to a free'd memory, I'm screwed.
+ */
+ if(pData->bDynamicName &&
+ pData->bFlushOnTXEnd && !pData->bUseAsyncWriter &&
+ lastStream != NULL && pData->pStrm != lastStream) {
+ CHKiRet(strm.Flush(lastStream));
+ }
+
+ lastStream = pData->pStrm;
}
/* Note: pStrm may be NULL if there was an error opening the stream */
if(pData->bFlushOnTXEnd && pData->pStrm != NULL) {