2022-02-17 15:55:22 +08:00
|
|
|
From 27ee1b988a465e5f89e8a9234f4a01c34cab4387 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: wangshouping <wangshouping@huawei.com>
|
|
|
|
|
Date: Mon, 27 Apr 2020 08:53:18 -0400
|
2023-10-11 18:05:44 +08:00
|
|
|
Subject: [PATCH] print main queue info to journal when receive USR1
|
|
|
|
|
signal
|
2022-12-27 16:24:40 +08:00
|
|
|
|
|
|
|
|
V-2: add macro control for systemd/sd-journal.h
|
2023-02-04 16:27:38 +08:00
|
|
|
V-3: adapt pMsgQueue to runConf->pMsgQueue
|
2023-10-11 18:05:44 +08:00
|
|
|
|
|
|
|
|
Signed-off-by: wangshouping <wangshouping@huawei.com>
|
2023-02-04 16:27:38 +08:00
|
|
|
Signed-off-by: pengyi37 <pengyi37@huawei.com>
|
2022-02-17 15:55:22 +08:00
|
|
|
---
|
2023-10-11 18:05:44 +08:00
|
|
|
tools/rsyslogd.c | 30 ++++++++++++++++++++++++++++++
|
|
|
|
|
1 file changed, 30 insertions(+)
|
2022-12-27 16:24:40 +08:00
|
|
|
|
2022-02-17 15:55:22 +08:00
|
|
|
diff --git a/tools/rsyslogd.c b/tools/rsyslogd.c
|
2023-10-11 18:05:44 +08:00
|
|
|
index 31b91a1..b92aca5 100644
|
2022-02-17 15:55:22 +08:00
|
|
|
--- a/tools/rsyslogd.c
|
|
|
|
|
+++ b/tools/rsyslogd.c
|
2022-12-27 16:24:40 +08:00
|
|
|
@@ -36,6 +36,7 @@
|
|
|
|
|
#endif
|
2022-02-17 15:55:22 +08:00
|
|
|
#ifdef HAVE_LIBSYSTEMD
|
|
|
|
|
# include <systemd/sd-daemon.h>
|
2023-10-11 18:05:44 +08:00
|
|
|
+#include <systemd/sd-journal.h>
|
2022-02-17 15:55:22 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "rsyslog.h"
|
2023-10-11 18:05:44 +08:00
|
|
|
@@ -182,6 +183,9 @@ static pthread_mutex_t mutChildDied;
|
2023-02-04 16:27:38 +08:00
|
|
|
static int bChildDied = 0;
|
|
|
|
|
static pthread_mutex_t mutHadHUP;
|
2022-02-17 15:55:22 +08:00
|
|
|
static int bHadHUP;
|
2023-10-11 18:05:44 +08:00
|
|
|
+#ifdef HAVE_LIBSYSTEMD
|
2022-02-17 15:55:22 +08:00
|
|
|
+static int g_bRecordQueue;
|
2023-10-11 18:05:44 +08:00
|
|
|
+#endif
|
2022-02-17 15:55:22 +08:00
|
|
|
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
|
2023-10-11 18:05:44 +08:00
|
|
|
@@ -1294,9 +1298,16 @@ rsyslogdDebugSwitch(void)
|
2022-02-17 15:55:22 +08:00
|
|
|
dbgprintf("\n");
|
|
|
|
|
debugging_on = 0;
|
|
|
|
|
}
|
|
|
|
|
+
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 18:05:44 +08:00
|
|
|
+#ifdef HAVE_LIBSYSTEMD
|
2022-02-17 15:55:22 +08:00
|
|
|
+static void RsyslogdDebugQueue(void)
|
|
|
|
|
+{
|
|
|
|
|
+ g_bRecordQueue = 1;
|
|
|
|
|
+}
|
|
|
|
|
|
2023-10-11 18:05:44 +08:00
|
|
|
+#endif
|
2022-02-17 15:55:22 +08:00
|
|
|
/* This is the main entry point into rsyslogd. Over time, we should try to
|
|
|
|
|
* modularize it a bit more...
|
2023-10-11 18:05:44 +08:00
|
|
|
*
|
|
|
|
|
@@ -1629,7 +1640,11 @@ initAll(int argc, char **argv)
|
2022-02-17 15:55:22 +08:00
|
|
|
hdlr_enable(SIGINT, rsyslogdDoDie);
|
|
|
|
|
hdlr_enable(SIGQUIT, rsyslogdDoDie);
|
|
|
|
|
} else {
|
2023-10-11 18:05:44 +08:00
|
|
|
+#ifdef HAVE_LIBSYSTEMD
|
2022-02-17 15:55:22 +08:00
|
|
|
+ hdlr_enable(SIGUSR1, RsyslogdDebugQueue);
|
2023-10-11 18:05:44 +08:00
|
|
|
+#else
|
|
|
|
|
hdlr_enable(SIGUSR1, SIG_IGN);
|
|
|
|
|
+#endif
|
2022-02-17 15:55:22 +08:00
|
|
|
hdlr_enable(SIGINT, SIG_IGN);
|
|
|
|
|
hdlr_enable(SIGQUIT, SIG_IGN);
|
|
|
|
|
}
|
2023-10-11 18:05:44 +08:00
|
|
|
@@ -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)
|
2022-02-17 15:55:22 +08:00
|
|
|
|
2023-02-04 16:27:38 +08:00
|
|
|
processImInternal();
|
|
|
|
|
|
2023-10-11 18:05:44 +08:00
|
|
|
+#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 */
|
|
|
|
|
|
2022-02-17 15:55:22 +08:00
|
|
|
--
|
2023-10-11 18:05:44 +08:00
|
|
|
2.27.0
|
2022-12-27 16:24:40 +08:00
|
|
|
|