summaryrefslogtreecommitdiff
path: root/src/nm-logging.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-06-21 09:21:57 +0200
committerThomas Haller <thaller@redhat.com>2018-06-27 09:21:33 +0200
commitdbd48f260ee2cb19329158c85e4a4a032538845c (patch)
treeafa093ddec14ceaf4b6d2bde94b50e992cab9395 /src/nm-logging.c
parenta64b424da392e75f0a636e1f0d9029beddf771c2 (diff)
downloadNetworkManager-dbd48f260ee2cb19329158c85e4a4a032538845c.tar.gz
logging: warn about invalid logging backends and drop "debug" backend
"debug" was documentation in `man NetworkManager.conf` as a valid logging backend. However, it was completely ignored by nm_logging_syslog_openlog(). In fact, it makes not sense. Passing debug = TRUE to nm_logging_syslog_openlog(), means that all messages will be printed to stderr in addition to syslog/journal. However, when NetworkManager is daemonizing, stderr is closed. Whether NetworkManager is daemonizing depends entirely on command line options --no-daemon and --debug. Hence, the logging backend "debug" from the configuration file either conflicts or is redundant. Also, adjust logging backend description in `man NetworkManager.conf`. Also, log a warning about invalid/unsupported logging backend. (cherry picked from commit 2ccf6168dc1c54fde350ec669b777c29d566fb4a)
Diffstat (limited to 'src/nm-logging.c')
-rw-r--r--src/nm-logging.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/nm-logging.c b/src/nm-logging.c
index 2eab3e6014..c55537910a 100644
--- a/src/nm-logging.c
+++ b/src/nm-logging.c
@@ -839,6 +839,11 @@ void
nm_logging_syslog_openlog (const char *logging_backend, gboolean debug)
{
gboolean fetch_monotonic_timestamp = FALSE;
+ gboolean obsolete_debug_backend = FALSE;
+
+ nm_assert (NM_IN_STRSET (""NM_CONFIG_DEFAULT_LOGGING_BACKEND,
+ NM_LOG_CONFIG_BACKEND_JOURNAL,
+ NM_LOG_CONFIG_BACKEND_SYSLOG));
if (global.log_backend != LOG_BACKEND_GLIB)
g_return_if_reached ();
@@ -846,8 +851,19 @@ nm_logging_syslog_openlog (const char *logging_backend, gboolean debug)
if (!logging_backend)
logging_backend = ""NM_CONFIG_DEFAULT_LOGGING_BACKEND;
+ if (nm_streq (logging_backend, NM_LOG_CONFIG_BACKEND_DEBUG)) {
+ /* "debug" was wrongly documented as a valid logging backend. It makes no sense however,
+ * because printing to stderr only makes sense when not demonizing. Whether to daemonize
+ * is only controlled via command line arguments (--no-daemon, --debug) and not via the
+ * logging backend from configuration.
+ *
+ * Fall back to the default. */
+ logging_backend = ""NM_CONFIG_DEFAULT_LOGGING_BACKEND;
+ obsolete_debug_backend = TRUE;
+ }
+
#if SYSTEMD_JOURNAL
- if (strcmp (logging_backend, "syslog") != 0) {
+ if (!nm_streq (logging_backend, NM_LOG_CONFIG_BACKEND_SYSLOG)) {
global.log_backend = LOG_BACKEND_JOURNAL;
global.uses_syslog = TRUE;
global.debug_stderr = debug;
@@ -871,4 +887,24 @@ nm_logging_syslog_openlog (const char *logging_backend, gboolean debug)
* time causes a logging message. We don't want to do that during _nm_log_impl. */
nm_utils_get_monotonic_timestamp_ns ();
}
+
+ if (obsolete_debug_backend)
+ nm_log_dbg (LOGD_CORE, "config: ignore deprecated logging backend 'debug', fallback to '%s'", logging_backend);
+
+ if (nm_streq (logging_backend, NM_LOG_CONFIG_BACKEND_SYSLOG)) {
+ /* good */
+ } else if (nm_streq (logging_backend, NM_LOG_CONFIG_BACKEND_JOURNAL)) {
+#if !SYSTEMD_JOURNAL
+ nm_log_warn (LOGD_CORE, "config: logging backend 'journal' is not available, fallback to 'syslog'");
+#endif
+ } else {
+ nm_log_warn (LOGD_CORE, "config: invalid logging backend '%s', fallback to '%s'",
+ logging_backend,
+#if SYSTEMD_JOURNAL
+ NM_LOG_CONFIG_BACKEND_JOURNAL
+#else
+ NM_LOG_CONFIG_BACKEND_SYSLOG
+#endif
+ );
+ }
}