summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-06-21 09:21:57 +0200
committerThomas Haller <thaller@redhat.com>2018-06-24 14:18:05 +0200
commit6aad37a05c2a1eaa5de31d3c8a63c625ce87ef96 (patch)
treed1b2fa12d38f36e88b778335b9b89106802fc189
parent10a9b8643cb2956313a54bf44bddd5fc1cc11ffe (diff)
downloadNetworkManager-th/logging-rh1593519.tar.gz
logging: warn about invalid logging backends and drop "debug" backendth/logging-rh1593519
"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 setting 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.
-rw-r--r--configure.ac6
-rw-r--r--man/NetworkManager.conf.xml10
-rw-r--r--meson_options.txt2
-rw-r--r--src/devices/nm-device.c10
-rw-r--r--src/nm-logging.c38
-rw-r--r--src/nm-logging.h4
6 files changed, 52 insertions, 18 deletions
diff --git a/configure.ac b/configure.ac
index 2812a19f07..f562b59b85 100644
--- a/configure.ac
+++ b/configure.ac
@@ -391,10 +391,8 @@ AC_ARG_WITH(config-logging-backend-default,
nm_config_logging_backend_default="$withval",
nm_config_logging_backend_default="")
-if test "$nm_config_logging_backend_default" != 'debug' \
- -a "$nm_config_logging_backend_default" != 'syslog' \
- -a "$nm_config_logging_backend_default" != 'journal' \
- -a "$nm_config_logging_backend_default" != 'journal-syslog-style'; then
+if test "$nm_config_logging_backend_default" != 'syslog' \
+ -a "$nm_config_logging_backend_default" != 'journal'; then
# unknown backend. Reset to default. Silently accept the invalid value to
# be future proof.
nm_config_logging_backend_default=''
diff --git a/man/NetworkManager.conf.xml b/man/NetworkManager.conf.xml
index e2c6562bc6..433a8b4bfe 100644
--- a/man/NetworkManager.conf.xml
+++ b/man/NetworkManager.conf.xml
@@ -603,12 +603,10 @@ unmanaged-devices=mac:00:22:68:1c:59:b1;mac:00:1E:65:30:D1:C4;interface-name:eth
<varlistentry>
<term><varname>backend</varname></term>
<listitem><para>The logging backend. Supported values
- are "<literal>debug</literal>", "<literal>syslog</literal>",
- "<literal>journal</literal>".
- "<literal>debug</literal>" uses syslog and logs to standard error.
- If NetworkManager is started in debug mode (<literal>--debug</literal>)
- this option is ignored and "<literal>debug</literal>" is always used.
- Otherwise, the default is "<literal>&NM_CONFIG_DEFAULT_LOGGING_BACKEND_TEXT;</literal>".
+ are "<literal>syslog</literal>" and "<literal>journal</literal>".
+ When NetworkManager is started with "<literal>--debug</literal>"
+ in addition all messages will be printed to stderr.
+ If unspecifid, the default is "<literal>&NM_CONFIG_DEFAULT_LOGGING_BACKEND_TEXT;</literal>".
</para></listitem>
</varlistentry>
<varlistentry>
diff --git a/meson_options.txt b/meson_options.txt
index bafc676911..e97a773ac6 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -21,7 +21,7 @@ option('modify_system', type: 'boolean', value: false, description: 'Allow users
option('polkit_agent', type: 'boolean', value: false, description: 'enable polkit agent for clients')
option('selinux', type: 'boolean', value: true, description: 'Build with SELinux')
option('systemd_journal', type: 'boolean', value: true, description: 'Use systemd journal for logging')
-option('config_logging_backend_default', type: 'combo', choices: ['default', 'debug', 'syslog', 'journal', 'journal-syslog-style'], value: 'default', description: 'Default value for logging.backend')
+option('config_logging_backend_default', type: 'combo', choices: ['default', 'syslog', 'journal'], value: 'default', description: 'Default value for logging.backend')
option('hostname_persist', type: 'combo', choices: ['default', 'suse', 'gentoo', 'slackware'], value: 'default', description: 'Hostname persist method')
option('libaudit', type: 'combo', choices: ['yes', 'yes-disabled-by-default', 'no'], value: 'yes', description: 'Build with audit daemon support. yes-disabled-by-default enables support, but disables it unless explicitly configured via NetworkManager.conf')
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index c680acc355..6486404698 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -13756,12 +13756,10 @@ nm_device_spawn_iface_helper (NMDevice *self)
g_ptr_array_add (argv, g_strdup_printf ("%d %s", (int) stable_type, stable_id));
}
- logging_backend = nm_config_get_is_debug (nm_config_get ())
- ? g_strdup ("debug")
- : nm_config_data_get_value (NM_CONFIG_GET_DATA_ORIG,
- NM_CONFIG_KEYFILE_GROUP_LOGGING,
- NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND,
- NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY);
+ logging_backend = nm_config_data_get_value (NM_CONFIG_GET_DATA_ORIG,
+ NM_CONFIG_KEYFILE_GROUP_LOGGING,
+ NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND,
+ NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY);
if (logging_backend) {
g_ptr_array_add (argv, g_strdup ("--logging-backend"));
g_ptr_array_add (argv, logging_backend);
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
+ );
+ }
}
diff --git a/src/nm-logging.h b/src/nm-logging.h
index 069d1d0d1c..70c14a5e04 100644
--- a/src/nm-logging.h
+++ b/src/nm-logging.h
@@ -28,6 +28,10 @@
#error nm-test-utils.h must be included as last header
#endif
+#define NM_LOG_CONFIG_BACKEND_DEBUG "debug"
+#define NM_LOG_CONFIG_BACKEND_SYSLOG "syslog"
+#define NM_LOG_CONFIG_BACKEND_JOURNAL "journal"
+
/* Log domains */
typedef enum { /*< skip >*/
LOGD_NONE = 0LL,