From d30dbe6615bcd1e322a82f30d27c52c7bca1c77b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 20 Jul 2016 09:25:57 +0100 Subject: [PATCH] _dbus_warn, _dbus_warn_check_failed: unify with _dbus_logv This means that dbus-daemon will log something like dbus-daemon[123]: Unable to add reload watch to main loop to syslog and/or stderr according to its configuration, while other libdbus users will print something like this to stderr: dbus[4567]: arguments to dbus_foo() were incorrect, assertion "connection != NULL" failed at file dbus-foo.c line 123. This is normally a bug in some application using the D-Bus library. This slightly changes the meaning of the argument to _dbus_warn() and _dbus_warn_check_failed. Previously, a trailing newline was expected, and a missing newline would have resulted in incorrect output. Now, a newline is supplied automatically by the library (like g_warning()), and messages that end with a newline will result in an unnecessary extra newline in output. This extra newline is harmless, so I'm not going to change all the callers immediately. Signed-off-by: Simon McVittie --- dbus/dbus-internals.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index 18db69e..ae6b9a1 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -230,13 +230,17 @@ void _dbus_warn (const char *format, ...) { + DBusSystemLogSeverity severity = DBUS_SYSTEM_LOG_WARNING; va_list args; if (!warn_initted) init_warnings (); - + + if (fatal_warnings) + severity = DBUS_SYSTEM_LOG_FATAL; + va_start (args, format); - vfprintf (stderr, format, args); + _dbus_logv (severity, format, args); va_end (args); if (fatal_warnings) @@ -248,7 +252,7 @@ _dbus_warn (const char *format, /** * Prints a "critical" warning to stderr when an assertion fails; - * differs from _dbus_warn primarily in that it prefixes the pid and + * differs from _dbus_warn primarily in that it * defaults to fatal. This should be used only when a programming * error has been detected. (NOT for unavoidable errors that an app * might handle - those should be returned as DBusError.) Calling this @@ -258,15 +262,17 @@ void _dbus_warn_check_failed(const char *format, ...) { + DBusSystemLogSeverity severity = DBUS_SYSTEM_LOG_WARNING; va_list args; if (!warn_initted) init_warnings (); - fprintf (stderr, "process %lu: ", _dbus_pid_for_log ()); - + if (fatal_warnings_on_check_failed) + severity = DBUS_SYSTEM_LOG_FATAL; + va_start (args, format); - vfprintf (stderr, format, args); + _dbus_logv (severity, format, args); va_end (args); if (fatal_warnings_on_check_failed) -- 2.8.1