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

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