From 062ea3c4181ef158620556bbab2358bc76eeab90 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Mon, 11 Oct 2021 17:08:05 -0500
Subject: [PATCH] fix syslog setting

Just setting lvm.conf level=N should not send messages to
syslog (now the journal by default.)

Sending messages to syslog should require setting lvm.conf
log { syslog=1 level=N }.

---
 lib/commands/toolcontext.c | 9 +++------
 lib/config/defaults.h      | 2 +-
 lib/log/log.c              | 6 +++++-
 lib/log/lvm-logging.h      | 2 +-
 4 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 894c91d..981c025 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -331,12 +331,11 @@ static void _init_logging(struct cmd_context *cmd)
 
 	/* Syslog */
 	cmd->default_settings.syslog = find_config_tree_bool(cmd, log_syslog_CFG, NULL);
-	if (cmd->default_settings.syslog != 1)
+	if (cmd->default_settings.syslog)
+		init_syslog(1, DEFAULT_LOG_FACILITY);
+	else
 		fin_syslog();
 
-	if (cmd->default_settings.syslog > 1)
-		init_syslog(cmd->default_settings.syslog);
-
 	/* Debug level for log file output */
 	cmd->default_settings.debug = find_config_tree_int(cmd, log_level_CFG, NULL);
 	init_debug(cmd->default_settings.debug);
@@ -1582,8 +1581,6 @@ struct cmd_context *create_toolcontext(unsigned is_clvmd,
 	bindtextdomain(INTL_PACKAGE, LOCALEDIR);
 #endif
 
-	init_syslog(DEFAULT_LOG_FACILITY);
-
 	if (!(cmd = zalloc(sizeof(*cmd)))) {
 		log_error("Failed to allocate command context");
 		return NULL;
diff --git a/lib/config/defaults.h b/lib/config/defaults.h
index 3f0539e..7e391ab 100644
--- a/lib/config/defaults.h
+++ b/lib/config/defaults.h
@@ -219,7 +219,7 @@
 #endif
 
 #define DEFAULT_COMMAND_LOG_REPORT 0
-#define DEFAULT_SYSLOG 1
+#define DEFAULT_SYSLOG 0
 #define DEFAULT_VERBOSE 0
 #define DEFAULT_SILENT 0
 #define DEFAULT_LOGLEVEL 0
diff --git a/lib/log/log.c b/lib/log/log.c
index 15ffb69..700be5e 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -311,8 +311,12 @@ void init_log_while_suspended(int log_while_suspended)
 	_log_while_suspended = log_while_suspended;
 }
 
-void init_syslog(int facility)
+void init_syslog(int enable, int facility)
 {
+	if (!enable) {
+		_syslog = 0;
+		return;
+	}
 	if (getenv("LVM_SUPPRESS_SYSLOG"))
 		return;
 
diff --git a/lib/log/lvm-logging.h b/lib/log/lvm-logging.h
index 39108fc..1be8f8f 100644
--- a/lib/log/lvm-logging.h
+++ b/lib/log/lvm-logging.h
@@ -59,7 +59,7 @@ void init_abort_on_internal_errors(int fatal);
 void fin_log(void);
 void reset_log_duplicated(void);
 
-void init_syslog(int facility);
+void init_syslog(int enable, int facility);
 void fin_syslog(void);
 
 int error_message_produced(void);
-- 
2.27.0

