Blame SOURCES/bz1977716-use-LOG_DAEMON-facility-by-default.patch

5789ae
From 75ea1d31c17f4bb3a73590167658310bc9f67149 Mon Sep 17 00:00:00 2001
5789ae
From: Quentin Armitage <quentin@armitage.org.uk>
5789ae
Date: Mon, 18 Jan 2021 14:57:30 +0000
5789ae
Subject: [PATCH 2/2] all: log to LOG_DAEMON facility by default
5789ae
5789ae
keepalived(8) man page states that the default log facility is LOG_DAEMON.
5789ae
Commit db3bcf7 - "Explicitly set LOG_USER log facility when syslogging"
5789ae
incorrectly set the facility to LOG_USER, and that has now been reverted.
5789ae
However, with that reverted, by default the VRRP process logs to LOG_LOCAL1
5789ae
and the checker and BFD processes log to LOG_LOCAL2, contrary to the
5789ae
documentation.
5789ae
5789ae
Since no-one has commented that logs were not going to LOG_LOCAL1/2 since
5789ae
commit db3bcf7 (April 28 2020), it is safe to assume that no-one was relying
5789ae
on that. This commit therefore reverts to the documentation and by default
5789ae
logs everything to the LOG_DAEMON facility.
5789ae
5789ae
Signed-off-by: Quentin Armitage <quentin@armitage.org.uk>
5789ae
---
5789ae
 keepalived/bfd/bfd_daemon.c     |  3 +--
5789ae
 keepalived/check/check_daemon.c |  3 +--
5789ae
 keepalived/core/main.c          |  7 +++----
5789ae
 keepalived/include/main.h       |  1 -
5789ae
 keepalived/vrrp/vrrp_daemon.c   |  3 +--
5789ae
 lib/logger.c                    |  2 ++
5789ae
 lib/logger.h                    | 10 ++++++++++
5789ae
 7 files changed, 18 insertions(+), 11 deletions(-)
5789ae
5789ae
diff --git a/keepalived/bfd/bfd_daemon.c b/keepalived/bfd/bfd_daemon.c
5789ae
index cf74eee3..47d87892 100644
5789ae
--- a/keepalived/bfd/bfd_daemon.c
5789ae
+++ b/keepalived/bfd/bfd_daemon.c
5789ae
@@ -396,8 +396,7 @@ start_bfd_child(void)
5789ae
 
5789ae
 	/* Opening local BFD syslog channel */
5789ae
 	if (!__test_bit(NO_SYSLOG_BIT, &debug))
5789ae
-		openlog(syslog_ident, LOG_PID | ((__test_bit(LOG_CONSOLE_BIT, &debug)) ? LOG_CONS : 0)
5789ae
-				    , (log_facility==LOG_DAEMON) ? LOG_LOCAL2 : log_facility);
5789ae
+		open_syslog(syslog_ident);
5789ae
 
5789ae
 #ifdef ENABLE_LOG_TO_FILE
5789ae
 	if (log_file_name)
5789ae
diff --git a/keepalived/check/check_daemon.c b/keepalived/check/check_daemon.c
5789ae
index 5e03cc4c..63bdf07b 100644
5789ae
--- a/keepalived/check/check_daemon.c
5789ae
+++ b/keepalived/check/check_daemon.c
5789ae
@@ -689,8 +689,7 @@ start_check_child(void)
5789ae
 
5789ae
 	/* Opening local CHECK syslog channel */
5789ae
 	if (!__test_bit(NO_SYSLOG_BIT, &debug))
5789ae
-		openlog(syslog_ident, LOG_PID | ((__test_bit(LOG_CONSOLE_BIT, &debug)) ? LOG_CONS : 0)
5789ae
-				    , (log_facility==LOG_DAEMON) ? LOG_LOCAL2 : log_facility);
5789ae
+		open_syslog(syslog_ident);
5789ae
 
5789ae
 #ifdef ENABLE_LOG_TO_FILE
5789ae
 	if (log_file_name)
5789ae
diff --git a/keepalived/core/main.c b/keepalived/core/main.c
5789ae
index be4488ea..756b2f12 100644
5789ae
--- a/keepalived/core/main.c
5789ae
+++ b/keepalived/core/main.c
5789ae
@@ -149,7 +149,6 @@ static const struct child_term children_term[] = {
5789ae
 /* global var */
5789ae
 const char *version_string = VERSION_STRING;		/* keepalived version */
5789ae
 const char *conf_file = KEEPALIVED_CONFIG_FILE;		/* Configuration file */
5789ae
-int log_facility = LOG_DAEMON;				/* Optional logging facilities */
5789ae
 bool reload;						/* Set during a reload */
5789ae
 const char *main_pidfile;				/* overrule default pidfile */
5789ae
 static bool free_main_pidfile;
5789ae
@@ -2087,7 +2086,7 @@ keepalived_main(int argc, char **argv)
5789ae
 	umask(umask_val);
5789ae
 
5789ae
 	/* Open log with default settings so we can log initially */
5789ae
-	openlog(PACKAGE_NAME, LOG_PID, log_facility);
5789ae
+	open_syslog(PACKAGE_NAME);
5789ae
 
5789ae
 #ifdef _MEM_CHECK_
5789ae
 	mem_log_init(PACKAGE_NAME, "Parent process");
5789ae
@@ -2128,7 +2127,7 @@ keepalived_main(int argc, char **argv)
5789ae
 	if (parse_cmdline(argc, argv)) {
5789ae
 		closelog();
5789ae
 		if (!__test_bit(NO_SYSLOG_BIT, &debug))
5789ae
-			openlog(PACKAGE_NAME, LOG_PID | ((__test_bit(LOG_CONSOLE_BIT, &debug)) ? LOG_CONS : 0) , log_facility);
5789ae
+			open_syslog(PACKAGE_NAME);
5789ae
 	}
5789ae
 
5789ae
 	if (__test_bit(LOG_CONSOLE_BIT, &debug))
5789ae
@@ -2212,7 +2211,7 @@ keepalived_main(int argc, char **argv)
5789ae
 		if ((syslog_ident = make_syslog_ident(PACKAGE_NAME))) {
5789ae
 			log_message(LOG_INFO, "Changing syslog ident to %s", syslog_ident);
5789ae
 			closelog();
5789ae
-			openlog(syslog_ident, LOG_PID | ((__test_bit(LOG_CONSOLE_BIT, &debug)) ? LOG_CONS : 0), log_facility);
5789ae
+			open_syslog(syslog_ident);
5789ae
 		}
5789ae
 		else
5789ae
 			log_message(LOG_INFO, "Unable to change syslog ident");
5789ae
diff --git a/keepalived/include/main.h b/keepalived/include/main.h
5789ae
index 3e013bb6..6a34797b 100644
5789ae
--- a/keepalived/include/main.h
5789ae
+++ b/keepalived/include/main.h
5789ae
@@ -51,7 +51,6 @@ enum daemon_bits {
5789ae
 extern const char *version_string;	/* keepalived version */
5789ae
 extern unsigned long daemon_mode;	/* Which child processes are run */
5789ae
 extern const char *conf_file;		/* Configuration file */
5789ae
-extern int log_facility;		/* Optional logging facilities */
5789ae
 #ifdef _WITH_VRRP_
5789ae
 extern pid_t vrrp_child;		/* VRRP child process ID */
5789ae
 extern const char *vrrp_pidfile;	/* overrule default pidfile */
5789ae
diff --git a/keepalived/vrrp/vrrp_daemon.c b/keepalived/vrrp/vrrp_daemon.c
5789ae
index baa5f5f2..e22f8a81 100644
5789ae
--- a/keepalived/vrrp/vrrp_daemon.c
5789ae
+++ b/keepalived/vrrp/vrrp_daemon.c
5789ae
@@ -974,8 +974,7 @@ start_vrrp_child(void)
5789ae
 		syslog_ident = PROG_VRRP;
5789ae
 
5789ae
 	if (!__test_bit(NO_SYSLOG_BIT, &debug))
5789ae
-		openlog(syslog_ident, LOG_PID | ((__test_bit(LOG_CONSOLE_BIT, &debug)) ? LOG_CONS : 0)
5789ae
-				    , (log_facility==LOG_DAEMON) ? LOG_LOCAL1 : log_facility);
5789ae
+		open_syslog(syslog_ident);
5789ae
 
5789ae
 #ifdef ENABLE_LOG_TO_FILE
5789ae
 	if (log_file_name)
5789ae
diff --git a/lib/logger.c b/lib/logger.c
5789ae
index 34c83f32..7fad8ac6 100644
5789ae
--- a/lib/logger.c
5789ae
+++ b/lib/logger.c
5789ae
@@ -40,6 +40,8 @@
5789ae
 /* Boolean flag - send messages to console as well as syslog */
5789ae
 static bool log_console = false;
5789ae
 
5789ae
+int log_facility = LOG_DAEMON;				/* Optional logging facilities */
5789ae
+
5789ae
 #ifdef ENABLE_LOG_TO_FILE
5789ae
 /* File to write log messages to */
5789ae
 const char *log_file_name;
5789ae
diff --git a/lib/logger.h b/lib/logger.h
5789ae
index 20b2a7e4..c6f29138 100644
5789ae
--- a/lib/logger.h
5789ae
+++ b/lib/logger.h
5789ae
@@ -30,8 +30,13 @@
5789ae
 #include <sys/stat.h>
5789ae
 #endif
5789ae
 
5789ae
+#include "bitops.h"
5789ae
+#include "utils.h"
5789ae
+
5789ae
 #define	MAX_LOG_MSG	255
5789ae
 
5789ae
+extern int log_facility;		/* Optional logging facilities */
5789ae
+
5789ae
 #ifdef ENABLE_LOG_TO_FILE
5789ae
 extern const char *log_file_name;
5789ae
 #endif
5789ae
@@ -51,4 +56,9 @@ extern void log_message(int priority, const char* format, ...)
5789ae
 extern void conf_write(FILE *fp, const char *format, ...)
5789ae
 	__attribute__ ((format (printf, 2, 3)));
5789ae
 
5789ae
+static inline void
5789ae
+open_syslog(const char *ident)
5789ae
+{
5789ae
+	openlog(ident, LOG_PID | ((__test_bit(LOG_CONSOLE_BIT, &debug)) ? LOG_CONS : 0), log_facility);
5789ae
+}
5789ae
 #endif
5789ae
-- 
5789ae
2.31.1
5789ae