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>
Date: Mon, 27 Apr 2020 08:53:18 -0400
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
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 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
runtime/queue.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/runtime/queue.c b/runtime/queue.c
index 3083fb9..b3fdd51 100644
index 3083fb9..6974173 100644
--- a/runtime/queue.c
+++ b/runtime/queue.c
@@ -47,6 +47,9 @@
@ -20,15 +20,16 @@ index 3083fb9..b3fdd51 100644
#include <inttypes.h>
#include <sys/vfs.h>
+#ifdef HAVE_LIBSYSTEMD
+# include <systemd/sd-journal.h>
+#include <systemd/sd-journal.h>
+#endif
#include "rsyslog.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 () */
#define QUEUE_CHECKPOINT 1
#define QUEUE_NO_CHECKPOINT 0
+#ifdef HAVE_LIBSYSTEMD
+#define TIME_OUT 300
+#define TIMEOUT_ENQUEUE_ZERO 1
+#define TIMEOUT_ENQUEUE_NONZERO 2
@ -37,13 +38,15 @@ index 3083fb9..b3fdd51 100644
+ .tv_sec = 0,
+ .tv_nsec = 0,
+};
+#endif
/* tables for interfacing with the v6 config system */
static struct cnfparamdescr cnfpdescr[] = {
@@ -3008,6 +3019,24 @@ finalize_it:
@@ -3008,7 +3021,27 @@ finalize_it:
RETiRet;
}
+#ifdef HAVE_LIBSYSTEMD
+void PrintQueueFullLog(qqueue_t *pThis, int flag)
+{
+ struct timespec timeNow;
@ -63,23 +66,29 @@ index 3083fb9..b3fdd51 100644
+ }
+}
+#endif
/* enqueue a single data object.
* 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 "
"sizeOnDiskMax=%lld\n", pThis->iQueueSize, pThis->iMaxQueueSize,
pThis->tVars.disk.sizeOnDisk, pThis->sizeOnDiskMax);
+#ifdef HAVE_LIBSYSTEMD
+ PrintQueueFullLog(pThis, TIMEOUT_ENQUEUE_ZERO);
+#endif
STATSCOUNTER_INC(pThis->ctrFDscrd, pThis->mutCtrFDscrd);
msgDestruct(&pMsg);
ABORT_FINALIZE(RS_RET_QUEUE_FULL);
} else {
DBGOPRINT((obj_t*) pThis, "doEnqSingleObject: queue FULL - waiting %dms to drain.\n",
pThis->toEnq);
+#ifdef HAVE_LIBSYSTEMD
+ PrintQueueFullLog(pThis, TIMEOUT_ENQUEUE_NONZERO);
+#endif
if(glbl.GetGlobalInputTermState()) {
DBGOPRINT((obj_t*) pThis, "doEnqSingleObject: queue FULL, discard due to "
"FORCE_TERM.\n");
--
2.23.0
2.19.1

View File

@ -1,77 +1,98 @@
From 27ee1b988a465e5f89e8a9234f4a01c34cab4387 Mon Sep 17 00:00:00 2001
From: wangshouping <wangshouping@huawei.com>
Date: Mon, 27 Apr 2020 08:53:18 -0400
Subject: [PATCH] print main queue info to journal when receive USR1 signal
Signed-off-by: wangshouping <wangshouping@huawei.com>
Subject: [PATCH] print main queue info to journal when receive USR1
signal
V-2: add macro control for systemd/sd-journal.h
Signed-off-by: pengyi37 <pengyi37@huawei.com>
V-3: adapt pMsgQueue to runConf->pMsgQueue
Signed-off-by: wangshouping <wangshouping@huawei.com>
Signed-off-by: pengyi37 <pengyi37@huawei.com>
---
tools/rsyslogd.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
tools/rsyslogd.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/tools/rsyslogd.c b/tools/rsyslogd.c
index 31b91a1..8be2032 100644
index 31b91a1..b92aca5 100644
--- a/tools/rsyslogd.c
+++ b/tools/rsyslogd.c
@@ -36,6 +36,7 @@
#endif
#ifdef HAVE_LIBSYSTEMD
# include <systemd/sd-daemon.h>
+# include <systemd/sd-journal.h>
+#include <systemd/sd-journal.h>
#endif
#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 pthread_mutex_t mutHadHUP;
static int bHadHUP;
+#ifdef HAVE_LIBSYSTEMD
+static int g_bRecordQueue;
+#endif
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
* 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");
debugging_on = 0;
}
+
}
+#ifdef HAVE_LIBSYSTEMD
+static void RsyslogdDebugQueue(void)
+{
+ g_bRecordQueue = 1;
+}
+#endif
/* This is the main entry point into rsyslogd. Over time, we should try to
* 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(SIGQUIT, rsyslogdDoDie);
} else {
- hdlr_enable(SIGUSR1, SIG_IGN);
+#ifdef HAVE_LIBSYSTEMD
+ hdlr_enable(SIGUSR1, RsyslogdDebugQueue);
+#else
hdlr_enable(SIGUSR1, SIG_IGN);
+#endif
hdlr_enable(SIGINT, SIG_IGN);
hdlr_enable(SIGQUIT, SIG_IGN);
}
@@ -1997,6 +2004,15 @@ mainloop(void)
if(need_free_mutex) {
pthread_mutex_unlock(&mutHadHUP);
}
+ if (g_bRecordQueue) {
+ if(runConf->pMsgQueue != NULL) {
+ sd_journal_print(LOG_NOTICE, "main queue size information: current QueueSize=%d MaxQueueSize=%d\n",
+ runConf->pMsgQueue->iQueueSize, runConf->pMsgQueue->iMaxQueueSize);
+ } else {
+ sd_journal_print(LOG_NOTICE, "main queue size information: pMsgQueue is NULL!\n");
+ }
+ g_bRecordQueue = 0;
+ }
@@ -1971,6 +1986,9 @@ mainloop(void)
sigaddset(&sigblockset, SIGTERM);
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 (runConf->pMsgQueue != NULL) {
+ sd_journal_print(LOG_NOTICE, "main queue size information: current QueueSize=%d MaxQeueSize=%d\n",
+ runConf->pMsgQueue->iQueueSize, runConf->pMsgQueue->iMaxQueueSize);
+ } else {
+ sd_journal_print(LOG_NOTICE, "main queue size information: pMsgQueue is NULL!\n");
+ }
+ g_bRecordQueue = 0;
+ }
+#endif
+
if(bFinished)
break; /* exit as quickly as possible */
--
2.23.0
2.27.0

View File

@ -7,7 +7,7 @@
Name: rsyslog
Version: 8.2210.0
Release: 5
Release: 6
Summary: The rocket-fast system for log processing
License: (GPLv3+ and ASL 2.0)
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
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
%if %{systemd_lived} == 1
Patch9004: print-main-queue-info-to-journal-when-queue-full.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
Patch6001: backport-imtcp-bugfix-legacy-config-directives-did-no-longer-work.patch
@ -514,6 +512,12 @@ done
%{_mandir}/man1/rscryutil.1.gz
%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
- Type:NA
- ID:NA