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
This commit is contained 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
|
||||
|
||||
|
@@ -137,9 +137,13 @@
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><option>--no-daemon</option></term>
|
||||
<listitem><para>Do not daemonize. This is useful for
|
||||
debugging, and directs log output to the controlling terminal
|
||||
in addition to syslog.
|
||||
<listitem><para>Do not daemonize.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><option>--debug</option></term>
|
||||
<listitem><para>Do not daemonize, and direct log output to the
|
||||
controlling terminal in addition to syslog.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
|
@@ -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,
|
||||
|
@@ -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 */
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user