Commit 2ccf6168 authored by Thomas Haller's avatar Thomas Haller

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.
parent 504ad2ae
......@@ -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=''
......
......@@ -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 unspecified, the default is "<literal>&NM_CONFIG_DEFAULT_LOGGING_BACKEND_TEXT;</literal>".
</para></listitem>
</varlistentry>
<varlistentry>
......
......@@ -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')
......
......@@ -13790,12 +13790,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);
......
......@@ -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
);
}
}
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment