1 Star 0 Fork 38

konglidong/rsyslog

forked from src-openEuler/rsyslog 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
bugfix-rsyslog-7.4.7-add-configuration-to-avoid-memory-leak.patch 7.68 KB
一键复制 编辑 原始数据 按行查看 历史
hexiaowen 提交于 2019-09-30 11:16 . Package init
From 71e9b4eda329fc9e59fbbcdc86353a7609f8d383 Mon Sep 17 00:00:00 2001
From: guoxiaoqi <guoxiaoqi2@huawei.com>
Date: Tue, 26 Feb 2019 23:33:08 +0000
Subject: [PATCH] add configuration to avoid memory leak for bugfix of rsyslog-7.4.7
reason: add configuration to avoid memory leak for bugfix of rsyslog-7.4.7
Signed-off-by: guoxiaoqi <guoxiaoqi2@huawei.com>
---
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 1bc0ad2..e973f72 100644
--- a/action.c
+++ b/action.c
@@ -174,6 +174,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 */
@@ -309,7 +310,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 */
@@ -543,6 +545,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);
@@ -2229,6 +2232,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 23de366..0c2485c 100644
--- a/runtime/queue.c
+++ b/runtime/queue.c
@@ -46,6 +46,7 @@
#include <time.h>
#include <errno.h>
#include <inttypes.h>
+#include <sys/vfs.h>
#include "rsyslog.h"
#include "queue.h"
@@ -125,6 +126,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 },
@@ -472,6 +474,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));
@@ -1016,6 +1019,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));
@@ -1047,6 +1064,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;
}
@@ -1544,7 +1568,8 @@ qqueueSetDefaultsActionQueue(qqueue_t *pThis)
pThis->toWrkShutdown = 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 */
@@ -3355,6 +3380,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")) {
@@ -3455,6 +3482,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 5f91c58..f01c325 100644
--- a/runtime/queue.h
+++ b/runtime/queue.h
@@ -143,6 +143,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? */
@@ -233,6 +234,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.19.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/konglidong/rsyslog.git
git@gitee.com:konglidong/rsyslog.git
konglidong
rsyslog
rsyslog
master

搜索帮助