From 8d44136dce3de1becd11e798edfc3f1eb3f4a36f Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Fri, 17 May 2013 15:18:03 -0400 Subject: [PATCH] main: add --debug, fix logging under systemd When run with --no-daemon, NM used to duplicate all syslog output to stderr, for ease of debugging. But this meant it had to tell systemd to ignore stderr, so you wouldn't get duplicated log entries. But that meant we lost error messages that didn't go through nm_log. (eg, g_warning()s and g_return_if_fail()s). Fix this by making --no-daemon no longer duplicate syslog output to stderr, and removing the "StandardError=null" from the systemd service file. To get the old behavior, you can use --debug instead of --no-daemon. https://bugzilla.gnome.org/show_bug.cgi?id=700550 --- data/NetworkManager.service.in | 4 ---- man/NetworkManager.xml | 10 +++++++--- src/logging/nm-logging.c | 8 ++++---- src/logging/nm-logging.h | 2 +- src/main.c | 6 ++++-- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/data/NetworkManager.service.in b/data/NetworkManager.service.in index 16b53b68f..f1a2b09b1 100644 --- a/data/NetworkManager.service.in +++ b/data/NetworkManager.service.in @@ -8,10 +8,6 @@ Before=network.target Type=dbus BusName=org.freedesktop.NetworkManager ExecStart=@sbindir@/NetworkManager --no-daemon -# Suppress stderr to eliminate duplicated messages in syslog. NM calls openlog() -# with LOG_PERROR when run in foreground. But systemd redirects stderr to -# syslog by default, which results in logging each message twice. -StandardError=null # NM doesn't want systemd to kill its children for it KillMode=process diff --git a/man/NetworkManager.xml b/man/NetworkManager.xml index da4e99ddb..0b34cd23e 100644 --- a/man/NetworkManager.xml +++ b/man/NetworkManager.xml @@ -137,9 +137,13 @@ - Do not daemonize. This is useful for - debugging, and directs log output to the controlling terminal - in addition to syslog. + Do not daemonize. + + + + + Do not daemonize, and direct log output to the + controlling terminal in addition to syslog. diff --git a/src/logging/nm-logging.c b/src/logging/nm-logging.c index e087fa9de..509d1cf22 100644 --- a/src/logging/nm-logging.c +++ b/src/logging/nm-logging.c @@ -349,12 +349,12 @@ nm_log_handler (const gchar *log_domain, } void -nm_logging_start (gboolean become_daemon) +nm_logging_start (gboolean debug) { - if (become_daemon) - openlog (G_LOG_DOMAIN, LOG_PID, LOG_DAEMON); - else + if (debug) openlog (G_LOG_DOMAIN, LOG_CONS | LOG_PERROR | LOG_PID, LOG_USER); + else + openlog (G_LOG_DOMAIN, LOG_PID, LOG_DAEMON); g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, diff --git a/src/logging/nm-logging.h b/src/logging/nm-logging.h index 00a92f5aa..d26c81aed 100644 --- a/src/logging/nm-logging.h +++ b/src/logging/nm-logging.h @@ -123,7 +123,7 @@ const char *nm_logging_all_domains_to_string (void); #undef nm_error_str gboolean nm_logging_setup (const char *level, const char *domains, GError **error); -void nm_logging_start (gboolean become_daemon); +void nm_logging_start (gboolean debug); void nm_logging_shutdown (void); #endif /* NM_LOGGING_H */ diff --git a/src/main.c b/src/main.c index 833effd1f..3b5f9663a 100644 --- a/src/main.c +++ b/src/main.c @@ -305,6 +305,7 @@ main (int argc, char *argv[]) { GOptionContext *opt_ctx = NULL; gboolean become_daemon = FALSE; + gboolean debug = FALSE; gboolean g_fatal_warnings = FALSE; gs_free char *pidfile = NULL; gs_free char *state_file = NULL; @@ -325,6 +326,7 @@ main (int argc, char *argv[]) GOptionEntry options[] = { { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Print NetworkManager version and exit"), NULL }, { "no-daemon", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &become_daemon, N_("Don't become a daemon"), NULL }, + { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Don't become a daemon, and log to stderr"), NULL }, { "g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &g_fatal_warnings, N_("Make all warnings fatal"), NULL }, { "pid-file", 0, 0, G_OPTION_ARG_FILENAME, &pidfile, N_("Specify the location of a PID file"), N_("filename") }, { "state-file", 0, 0, G_OPTION_ARG_FILENAME, &state_file, N_("State file location"), N_("/path/to/state.file") }, @@ -426,7 +428,7 @@ main (int argc, char *argv[]) } g_clear_error (&error); - if (become_daemon) { + if (become_daemon && !debug) { if (daemon (0, 0) < 0) { int saved_errno; @@ -467,7 +469,7 @@ main (int argc, char *argv[]) */ dbus_glib_global_set_disable_legacy_property_access (); - nm_logging_start (become_daemon); + nm_logging_start (debug); nm_log_info (LOGD_CORE, "NetworkManager (version " NM_DIST_VERSION ") is starting..."); success = FALSE;