From 71e9b4eda329fc9e59fbbcdc86353a7690f8d383 Mon Spe 17 00:00:00 2001 From: guoxiaoqi Date: Tue, 26 Feb 2019 23:33:08 +0000 Subject: [PATCH] bugfix-rsyslog-7.4.7-add-configuration-to-avoid-memory-leak reason: add configuration to avoid memory leak for bugfix of rsyslog-7.4.7i --- From a633ee629468562499ead31e26c8dfca5a5f3293 Mon Sep 17 00:00:00 2001 From: pengyi Date: Fri, 3 Feb 2023 15:26:23 +0800 Subject: [PATCH] bugfix-rsyslog-7.4.7-add-configuration-to-avoid-memory-leak V-2: adapt due to line mismatch --- action.c | 7 ++++++- runtime/queue.c | 30 +++++++++++++++++++++++++++++- runtime/queue.h | 2 ++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/action.c b/action.c index 4c3b581..4fa53ed 100644 --- a/action.c +++ b/action.c @@ -176,6 +176,7 @@ typedef struct configSettings_s { int iActionQWrkMinMsgs; /* minimum messages per worker needed to start a new one */ int bActionQSaveOnShutdown; /* save queue on shutdown (when DA enabled)? */ int64 iActionQueMaxDiskSpace; /* max disk space allocated 0 ==> unlimited */ + int64 iActionQueDiskSpaceMark; /* rsyslog cannot run out of disk space */ int iActionQueueDeqSlowdown; /* dequeue slowdown (simple rate limiting) */ int iActionQueueDeqtWinFromHr; /* hour begin of time frame when queue is to be dequeued */ int iActionQueueDeqtWinToHr; /* hour begin of time frame when queue is to be dequeued */ @@ -303,7 +304,8 @@ actionResetQueueParams(void) cs.iActionQtoWrkShutdown = 60000; /* timeout for worker thread shutdown */ cs.iActionQWrkMinMsgs = -1; /* minimum messages per worker needed to start a new one */ cs.bActionQSaveOnShutdown = 1; /* save queue on shutdown (when DA enabled)? */ - cs.iActionQueMaxDiskSpace = 0; + cs.iActionQueMaxDiskSpace = 100*1024*1024; + cs.iActionQueDiskSpaceMark = 100*1024*1024; cs.iActionQueueDeqSlowdown = 0; cs.iActionQueueDeqtWinFromHr = 0; cs.iActionQueueDeqtWinToHr = 25; /* 25 disables time windowed dequeuing */ @@ -539,6 +541,7 @@ actionConstructFinalize(action_t *__restrict__ const pThis, struct nvlst *lst) error %d. Ignored, running with default setting", iRet); \ } setQPROP(qqueueSetsizeOnDiskMax, "$ActionQueueMaxDiskSpace", cs.iActionQueMaxDiskSpace); + setQPROP(qqueueSetsizeOnDiskMrk, "$ActionQueueDiskSpaceMark", cs.iActionQueDiskSpaceMark); setQPROP(qqueueSetiDeqBatchSize, "$ActionQueueDequeueBatchSize", cs.iActionQueueDeqBatchSize); setQPROP(qqueueSetMaxFileSize, "$ActionQueueFileSize", cs.iActionQueMaxFileSize); setQPROPstr(qqueueSetFilePrefix, "$ActionQueueFileName", cs.pszActionQFName); @@ -2318,6 +2321,8 @@ rsRetVal actionClassInit(void) &cs.iActionQueueDeqBatchSize, NULL)); CHKiRet(regCfSysLineHdlr((uchar *)"actionqueuemaxdiskspace", 0, eCmdHdlrSize, NULL, &cs.iActionQueMaxDiskSpace, NULL)); + CHKiRet(regCfSysLineHdlr((uchar *)"actionqueuediskspacemark", 0, eCmdHdlrSize, NULL, + &cs.iActionQueDiskSpaceMark, NULL)); CHKiRet(regCfSysLineHdlr((uchar *)"actionqueuehighwatermark", 0, eCmdHdlrInt, NULL, &cs.iActionQHighWtrMark, NULL)); CHKiRet(regCfSysLineHdlr((uchar *)"actionqueuelowwatermark", 0, eCmdHdlrInt, NULL, diff --git a/runtime/queue.c b/runtime/queue.c index bd3fb8e..de9c619 100644 --- a/runtime/queue.c +++ b/runtime/queue.c @@ -46,6 +46,7 @@ #include #include #include +#include #include "rsyslog.h" #include "queue.h" @@ -115,6 +116,7 @@ static struct cnfparamdescr cnfpdescr[] = { { "queue.mindequeuebatchsize", eCmdHdlrInt, 0 }, { "queue.mindequeuebatchsize.timeout", eCmdHdlrInt, 0 }, { "queue.maxdiskspace", eCmdHdlrSize, 0 }, + { "queue.diskspacemark", eCmdHdlrSize, 0 }, { "queue.highwatermark", eCmdHdlrInt, 0 }, { "queue.lowwatermark", eCmdHdlrInt, 0 }, { "queue.fulldelaymark", eCmdHdlrInt, 0 }, @@ -464,6 +466,7 @@ StartDA(qqueue_t *pThis) CHKiRet(qqueueSetpAction(pThis->pqDA, pThis->pAction)); CHKiRet(qqueueSetsizeOnDiskMax(pThis->pqDA, pThis->sizeOnDiskMax)); + CHKiRet(qqueueSetsizeOnDiskMrk(pThis->pqDA, pThis->sizeOnDiskMrk)); CHKiRet(qqueueSetiDeqSlowdown(pThis->pqDA, pThis->iDeqSlowdown)); CHKiRet(qqueueSetMaxFileSize(pThis->pqDA, pThis->iMaxFileSize)); CHKiRet(qqueueSetFilePrefix(pThis->pqDA, pThis->pszFilePrefix, pThis->lenFilePrefix)); @@ -1019,6 +1022,20 @@ qAddDisk(qqueue_t *const pThis, smsg_t* pMsg) ISOBJ_TYPE_assert(pMsg, msg); number_t nWriteCount; const int oldfile = strmGetCurrFileNum(pThis->tVars.disk.pWrite); + struct statfs stDiskInfo; + unsigned long long ullFreeDisk = 0; + + /* rsyslog cannot run out of disk space:start */ + iRet = statfs(pThis->pszSpoolDir, &stDiskInfo); + if (iRet != 0||&stDiskInfo == NULL){ + FINALIZE; + } + ullFreeDisk = stDiskInfo.f_bsize * stDiskInfo.f_bfree; + if ( ullFreeDisk < pThis->sizeOnDiskMrk ){ + iRet = RS_RET_WRN_WRKDIR; + FINALIZE; + } + /* rsyslog cannot run out of disk space:end */ CHKiRet(strm.SetWCntr(pThis->tVars.disk.pWrite, &nWriteCount)); CHKiRet((objSerialize(pMsg))(pMsg, pThis->tVars.disk.pWrite)); @@ -1050,6 +1067,13 @@ qAddDisk(qqueue_t *const pThis, smsg_t* pMsg) } finalize_it: + if(iRet != RS_RET_OK){ + DBGOPRINT((obj_t*) pThis, "cannot write to disk, queue disk size now %lld octets, EnqOnly:%d\n", + pThis->tVars.disk.sizeOnDisk, pThis->bEnqOnly); + + if(pMsg != NULL) + msgDestruct(&pMsg); + } RETiRet; } @@ -1546,7 +1570,8 @@ qqueueSetDefaultsActionQueue(qqueue_t *pThis) pThis->toWrkShutdown = loadConf->globals.actq_dflt_toWrkShutdown; /* timeout for worker thread shutdown */ pThis->iMinMsgsPerWrkr = -1; /* minimum messages per worker needed to start a new one */ pThis->bSaveOnShutdown = 1; /* save queue on shutdown (when DA enabled)? */ - pThis->sizeOnDiskMax = 0; /* unlimited */ + pThis->sizeOnDiskMax = 100*1024*1024; /* unlimited */ + pThis->sizeOnDiskMrk = 100*1024*1024; pThis->iDeqSlowdown = 0; pThis->iDeqtWinFromHr = 0; pThis->iDeqtWinToHr = 25; /* disable time-windowed dequeuing by default */ @@ -3401,6 +3426,8 @@ qqueueApplyCnfParam(qqueue_t *pThis, struct nvlst *lst) pThis->toMinDeqBatchSize = pvals[i].val.d.n; } else if(!strcmp(pblk.descr[i].name, "queue.maxdiskspace")) { pThis->sizeOnDiskMax = pvals[i].val.d.n; + } else if(!strcmp(pblk.descr[i].name, "queue.diskspacemark")) { + pThis->sizeOnDiskMrk = pvals[i].val.d.n; } else if(!strcmp(pblk.descr[i].name, "queue.highwatermark")) { pThis->iHighWtrMrk = pvals[i].val.d.n; } else if(!strcmp(pblk.descr[i].name, "queue.lowwatermark")) { @@ -3555,6 +3582,7 @@ DEFpropSetMeth(qqueue, iDeqBatchSize, int) DEFpropSetMeth(qqueue, iMinDeqBatchSize, int) DEFpropSetMeth(qqueue, sizeOnDiskMax, int64) DEFpropSetMeth(qqueue, iSmpInterval, int) +DEFpropSetMeth(qqueue, sizeOnDiskMrk, int64) /* This function can be used as a generic way to set properties. Only the subset diff --git a/runtime/queue.h b/runtime/queue.h index dd989bd..2264f08 100644 --- a/runtime/queue.h +++ b/runtime/queue.h @@ -144,6 +144,7 @@ struct queue_s { int iNumberFiles; /* how many files make up the queue? */ int64 iMaxFileSize; /* max size for a single queue file */ int64 sizeOnDiskMax; /* maximum size on disk allowed */ + int64 sizeOnDiskMrk; /*rsyslog cannot run out of disk space*/ qDeqID deqIDAdd; /* next dequeue ID to use during add to queue store */ qDeqID deqIDDel; /* queue store delete position */ int bIsDA; /* is this queue disk assisted? */ @@ -237,6 +238,7 @@ PROTOTYPEpropSetMeth(qqueue, bSaveOnShutdown, int); PROTOTYPEpropSetMeth(qqueue, pAction, action_t*); PROTOTYPEpropSetMeth(qqueue, iDeqSlowdown, int); PROTOTYPEpropSetMeth(qqueue, sizeOnDiskMax, int64); +PROTOTYPEpropSetMeth(qqueue, sizeOnDiskMrk, int64); PROTOTYPEpropSetMeth(qqueue, iDeqBatchSize, int); #define qqueueGetID(pThis) ((unsigned long) pThis) -- 2.23.0