adapt for non-systemd scenario

Signed-off-by: Qiumiao Zhang <zhangqiumiao1@huawei.com>
This commit is contained in:
Qiumiao Zhang 2023-10-11 18:05:44 +08:00
parent 6dd779d778
commit a668bfc087
3 changed files with 73 additions and 39 deletions

View File

@ -2,17 +2,17 @@ From 27ee1b988a465e5f89e8a9234f4a01c34cab4387 Mon Sep 17 00:00:00 2001
From: wangshouping <wangshouping@huawei.com> From: wangshouping <wangshouping@huawei.com>
Date: Mon, 27 Apr 2020 08:53:18 -0400 Date: Mon, 27 Apr 2020 08:53:18 -0400
Subject: [PATCH] print main queue info to journal when queue full Subject: [PATCH] print main queue info to journal when queue full
Signed-off-by: wangshouping <wangshouping@huawei.com>
V-2: add macro control for systemd/sd-journal.h V-2: add macro control for systemd/sd-journal.h
Signed-off-by: pengyi37 <pengyi37@huawei.com>
Signed-off-by: wangshouping <wangshouping@huawei.com>
Signed-off-by: pengyi37 <pengyi37@huawei.com>
--- ---
runtime/queue.c | 31 +++++++++++++++++++++++++++++++ runtime/queue.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+) 1 file changed, 39 insertions(+)
diff --git a/runtime/queue.c b/runtime/queue.c diff --git a/runtime/queue.c b/runtime/queue.c
index 3083fb9..b3fdd51 100644 index 3083fb9..6974173 100644
--- a/runtime/queue.c --- a/runtime/queue.c
+++ b/runtime/queue.c +++ b/runtime/queue.c
@@ -47,6 +47,9 @@ @@ -47,6 +47,9 @@
@ -25,10 +25,11 @@ index 3083fb9..b3fdd51 100644
#include "rsyslog.h" #include "rsyslog.h"
#include "queue.h" #include "queue.h"
@@ -116,6 +119,14 @@ rsRetVal qqueueSetSpoolDir(qqueue_t *pThis, uchar *pszSpoolDir, int lenSpoolDir) @@ -116,6 +119,16 @@ rsRetVal qqueueSetSpoolDir(qqueue_t *pThis, uchar *pszSpoolDir, int lenSpoolDir)
/* some constants for queuePersist () */ /* some constants for queuePersist () */
#define QUEUE_CHECKPOINT 1 #define QUEUE_CHECKPOINT 1
#define QUEUE_NO_CHECKPOINT 0 #define QUEUE_NO_CHECKPOINT 0
+#ifdef HAVE_LIBSYSTEMD
+#define TIME_OUT 300 +#define TIME_OUT 300
+#define TIMEOUT_ENQUEUE_ZERO 1 +#define TIMEOUT_ENQUEUE_ZERO 1
+#define TIMEOUT_ENQUEUE_NONZERO 2 +#define TIMEOUT_ENQUEUE_NONZERO 2
@ -37,13 +38,15 @@ index 3083fb9..b3fdd51 100644
+ .tv_sec = 0, + .tv_sec = 0,
+ .tv_nsec = 0, + .tv_nsec = 0,
+}; +};
+#endif
/* tables for interfacing with the v6 config system */ /* tables for interfacing with the v6 config system */
static struct cnfparamdescr cnfpdescr[] = { static struct cnfparamdescr cnfpdescr[] = {
@@ -3008,6 +3019,24 @@ finalize_it: @@ -3008,7 +3021,27 @@ finalize_it:
RETiRet; RETiRet;
} }
+#ifdef HAVE_LIBSYSTEMD
+void PrintQueueFullLog(qqueue_t *pThis, int flag) +void PrintQueueFullLog(qqueue_t *pThis, int flag)
+{ +{
+ struct timespec timeNow; + struct timespec timeNow;
@ -63,23 +66,29 @@ index 3083fb9..b3fdd51 100644
+ } + }
+} +}
+#endif
/* enqueue a single data object. /* enqueue a single data object.
* Note that the queue mutex MUST already be locked when this function is called. * Note that the queue mutex MUST already be locked when this function is called.
@@ -3105,12 +3134,14 @@ doEnqSingleObj(qqueue_t *pThis, flowControl_t flowCtlType, smsg_t *pMsg) * rgerhards, 2009-06-16
@@ -3105,12 +3138,18 @@ doEnqSingleObj(qqueue_t *pThis, flowControl_t flowCtlType, smsg_t *pMsg)
"discarding QueueSize=%d MaxQueueSize=%d sizeOnDisk=%lld " "discarding QueueSize=%d MaxQueueSize=%d sizeOnDisk=%lld "
"sizeOnDiskMax=%lld\n", pThis->iQueueSize, pThis->iMaxQueueSize, "sizeOnDiskMax=%lld\n", pThis->iQueueSize, pThis->iMaxQueueSize,
pThis->tVars.disk.sizeOnDisk, pThis->sizeOnDiskMax); pThis->tVars.disk.sizeOnDisk, pThis->sizeOnDiskMax);
+#ifdef HAVE_LIBSYSTEMD
+ PrintQueueFullLog(pThis, TIMEOUT_ENQUEUE_ZERO); + PrintQueueFullLog(pThis, TIMEOUT_ENQUEUE_ZERO);
+#endif
STATSCOUNTER_INC(pThis->ctrFDscrd, pThis->mutCtrFDscrd); STATSCOUNTER_INC(pThis->ctrFDscrd, pThis->mutCtrFDscrd);
msgDestruct(&pMsg); msgDestruct(&pMsg);
ABORT_FINALIZE(RS_RET_QUEUE_FULL); ABORT_FINALIZE(RS_RET_QUEUE_FULL);
} else { } else {
DBGOPRINT((obj_t*) pThis, "doEnqSingleObject: queue FULL - waiting %dms to drain.\n", DBGOPRINT((obj_t*) pThis, "doEnqSingleObject: queue FULL - waiting %dms to drain.\n",
pThis->toEnq); pThis->toEnq);
+#ifdef HAVE_LIBSYSTEMD
+ PrintQueueFullLog(pThis, TIMEOUT_ENQUEUE_NONZERO); + PrintQueueFullLog(pThis, TIMEOUT_ENQUEUE_NONZERO);
+#endif
if(glbl.GetGlobalInputTermState()) { if(glbl.GetGlobalInputTermState()) {
DBGOPRINT((obj_t*) pThis, "doEnqSingleObject: queue FULL, discard due to " DBGOPRINT((obj_t*) pThis, "doEnqSingleObject: queue FULL, discard due to "
"FORCE_TERM.\n"); "FORCE_TERM.\n");
-- --
2.23.0 2.19.1

View File

@ -1,20 +1,20 @@
From 27ee1b988a465e5f89e8a9234f4a01c34cab4387 Mon Sep 17 00:00:00 2001 From 27ee1b988a465e5f89e8a9234f4a01c34cab4387 Mon Sep 17 00:00:00 2001
From: wangshouping <wangshouping@huawei.com> From: wangshouping <wangshouping@huawei.com>
Date: Mon, 27 Apr 2020 08:53:18 -0400 Date: Mon, 27 Apr 2020 08:53:18 -0400
Subject: [PATCH] print main queue info to journal when receive USR1 signal Subject: [PATCH] print main queue info to journal when receive USR1
Signed-off-by: wangshouping <wangshouping@huawei.com> signal
V-2: add macro control for systemd/sd-journal.h V-2: add macro control for systemd/sd-journal.h
Signed-off-by: pengyi37 <pengyi37@huawei.com>
V-3: adapt pMsgQueue to runConf->pMsgQueue V-3: adapt pMsgQueue to runConf->pMsgQueue
Signed-off-by: wangshouping <wangshouping@huawei.com>
Signed-off-by: pengyi37 <pengyi37@huawei.com> Signed-off-by: pengyi37 <pengyi37@huawei.com>
--- ---
tools/rsyslogd.c | 18 +++++++++++++++++- tools/rsyslogd.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 17 insertions(+), 1 deletion(-) 1 file changed, 30 insertions(+)
diff --git a/tools/rsyslogd.c b/tools/rsyslogd.c diff --git a/tools/rsyslogd.c b/tools/rsyslogd.c
index 31b91a1..8be2032 100644 index 31b91a1..b92aca5 100644
--- a/tools/rsyslogd.c --- a/tools/rsyslogd.c
+++ b/tools/rsyslogd.c +++ b/tools/rsyslogd.c
@@ -36,6 +36,7 @@ @@ -36,6 +36,7 @@
@ -25,53 +25,74 @@ index 31b91a1..8be2032 100644
#endif #endif
#include "rsyslog.h" #include "rsyslog.h"
@@ -182,6 +183,7 @@ static pthread_mutex_t mutChildDied; @@ -182,6 +183,9 @@ static pthread_mutex_t mutChildDied;
static int bChildDied = 0; static int bChildDied = 0;
static pthread_mutex_t mutHadHUP; static pthread_mutex_t mutHadHUP;
static int bHadHUP; static int bHadHUP;
+#ifdef HAVE_LIBSYSTEMD
+static int g_bRecordQueue; +static int g_bRecordQueue;
+#endif
static int doFork = 1; /* fork - run in daemon mode - read-only after startup */ static int doFork = 1; /* fork - run in daemon mode - read-only after startup */
int bFinished = 0; /* used by termination signal handler, read-only except there int bFinished = 0; /* used by termination signal handler, read-only except there
* is either 0 or the number of the signal that requested the * is either 0 or the number of the signal that requested the
@@ -1294,8 +1296,13 @@ rsyslogdDebugSwitch(void) @@ -1294,9 +1298,16 @@ rsyslogdDebugSwitch(void)
dbgprintf("\n"); dbgprintf("\n");
debugging_on = 0; debugging_on = 0;
} }
+ +
} }
+#ifdef HAVE_LIBSYSTEMD
+static void RsyslogdDebugQueue(void) +static void RsyslogdDebugQueue(void)
+{ +{
+ g_bRecordQueue = 1; + g_bRecordQueue = 1;
+} +}
+#endif
/* This is the main entry point into rsyslogd. Over time, we should try to /* This is the main entry point into rsyslogd. Over time, we should try to
* modularize it a bit more... * modularize it a bit more...
@@ -1629,7 +1636,7 @@ initAll(int argc, char **argv) *
@@ -1629,7 +1640,11 @@ initAll(int argc, char **argv)
hdlr_enable(SIGINT, rsyslogdDoDie); hdlr_enable(SIGINT, rsyslogdDoDie);
hdlr_enable(SIGQUIT, rsyslogdDoDie); hdlr_enable(SIGQUIT, rsyslogdDoDie);
} else { } else {
- hdlr_enable(SIGUSR1, SIG_IGN); +#ifdef HAVE_LIBSYSTEMD
+ hdlr_enable(SIGUSR1, RsyslogdDebugQueue); + hdlr_enable(SIGUSR1, RsyslogdDebugQueue);
+#else
hdlr_enable(SIGUSR1, SIG_IGN);
+#endif
hdlr_enable(SIGINT, SIG_IGN); hdlr_enable(SIGINT, SIG_IGN);
hdlr_enable(SIGQUIT, SIG_IGN); hdlr_enable(SIGQUIT, SIG_IGN);
} }
@@ -1997,6 +2004,15 @@ mainloop(void) @@ -1971,6 +1986,9 @@ mainloop(void)
if(need_free_mutex) { sigaddset(&sigblockset, SIGTERM);
pthread_mutex_unlock(&mutHadHUP); sigaddset(&sigblockset, SIGCHLD);
} sigaddset(&sigblockset, SIGHUP);
+#ifdef HAVE_LIBSYSTEMD
+ sigaddset(&sigblockset, SIGUSR1);
+#endif
do {
pthread_sigmask(SIG_BLOCK, &sigblockset, &origmask);
@@ -2000,6 +2018,18 @@ mainloop(void)
processImInternal();
+#ifdef HAVE_LIBSYSTEMD
+ if (g_bRecordQueue) { + if (g_bRecordQueue) {
+ if (runConf->pMsgQueue != NULL) { + if (runConf->pMsgQueue != NULL) {
+ sd_journal_print(LOG_NOTICE, "main queue size information: current QueueSize=%d MaxQueueSize=%d\n", + sd_journal_print(LOG_NOTICE, "main queue size information: current QueueSize=%d MaxQeueSize=%d\n",
+ runConf->pMsgQueue->iQueueSize, runConf->pMsgQueue->iMaxQueueSize); + runConf->pMsgQueue->iQueueSize, runConf->pMsgQueue->iMaxQueueSize);
+ } else { + } else {
+ sd_journal_print(LOG_NOTICE, "main queue size information: pMsgQueue is NULL!\n"); + sd_journal_print(LOG_NOTICE, "main queue size information: pMsgQueue is NULL!\n");
+ } + }
+ g_bRecordQueue = 0; + g_bRecordQueue = 0;
+ } + }
+#endif
processImInternal(); +
if(bFinished)
break; /* exit as quickly as possible */
-- --
2.23.0 2.27.0

View File

@ -7,7 +7,7 @@
Name: rsyslog Name: rsyslog
Version: 8.2210.0 Version: 8.2210.0
Release: 5 Release: 6
Summary: The rocket-fast system for log processing Summary: The rocket-fast system for log processing
License: (GPLv3+ and ASL 2.0) License: (GPLv3+ and ASL 2.0)
URL: http://www.rsyslog.com/ URL: http://www.rsyslog.com/
@ -26,10 +26,8 @@ Patch9000: rsyslog-8.24.0-ensure-parent-dir-exists-when-writting-log-file.p
Patch9001: bugfix-rsyslog-7.4.7-imjournal-add-monotonic-timestamp.patch Patch9001: bugfix-rsyslog-7.4.7-imjournal-add-monotonic-timestamp.patch
Patch9002: bugfix-rsyslog-7.4.7-add-configuration-to-avoid-memory-leak.patch Patch9002: bugfix-rsyslog-7.4.7-add-configuration-to-avoid-memory-leak.patch
Patch9003: rsyslog-8.37.0-initialize-variables-and-check-return-value.patch Patch9003: rsyslog-8.37.0-initialize-variables-and-check-return-value.patch
%if %{systemd_lived} == 1
Patch9004: print-main-queue-info-to-journal-when-queue-full.patch Patch9004: print-main-queue-info-to-journal-when-queue-full.patch
Patch9005: print-main-queue-info-to-journal-when-receive-USR1-signal.patch Patch9005: print-main-queue-info-to-journal-when-receive-USR1-signal.patch
%endif
Patch6000: backport-core-bugfix-local-hostname-invalid-if-no-global-config-object-given.patch Patch6000: backport-core-bugfix-local-hostname-invalid-if-no-global-config-object-given.patch
Patch6001: backport-imtcp-bugfix-legacy-config-directives-did-no-longer-work.patch Patch6001: backport-imtcp-bugfix-legacy-config-directives-did-no-longer-work.patch
@ -514,6 +512,12 @@ done
%{_mandir}/man1/rscryutil.1.gz %{_mandir}/man1/rscryutil.1.gz
%changelog %changelog
* Sat Oct 7 2023 zhangqiumiao <zhangqiumiao1@huawei.com> - 8.2210.0-6
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:adapt for non-systemd scenario
* Wed Sep 27 2023 renyi <977713017@qq.com> - 8.2210.0-5 * Wed Sep 27 2023 renyi <977713017@qq.com> - 8.2210.0-5
- Type:NA - Type:NA
- ID:NA - ID:NA