]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
_dbus_warn, _dbus_warn_check_failed: unify with _dbus_logv
authorSimon McVittie <smcv@debian.org>
Wed, 20 Jul 2016 08:25:57 +0000 (09:25 +0100)
committerSimon McVittie <smcv@debian.org>
Fri, 30 Sep 2016 18:36:50 +0000 (19:36 +0100)
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 <smcv@debian.org>
dbus/dbus-internals.c

index 18db69ee8262d22441010e44e195c06e5aacfdb0..ae6b9a1354a300fad6f869fb761620b6243b3363 100644 (file)
@@ -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)