telepathy-gabble: Initialize libdbus for thread-safety

Simon McVittie smcv at kemper.freedesktop.org
Tue Jun 4 04:41:40 PDT 2013


Module: telepathy-gabble
Branch: master
Commit: 67d009ba2e6ac6d21c659d7586670e3e40b5ec3e
URL:    http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=67d009ba2e6ac6d21c659d7586670e3e40b5ec3e

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Tue Jun  4 12:40:45 2013 +0100

Initialize libdbus for thread-safety

libdbus is not thread-safe by default. This is a long-standing design
flaw (<https://bugs.freedesktop.org/show_bug.cgi?id=54972>).

We call into GIO, which calls into glib-networking, which can
(at least in recent versions) invoke libproxy in a thread. libproxy
apparently has a Network-Manager plugin, which uses libdbus in that
thread; meanwhile, we use libdbus in the main thread and everything
goes badly for us.

(It's possible that this crash is only reproducible with broken
connectivity: I wrote this patch on a train, with intermittent
mobile broadband coverage.)

In libdbus < 1.7.4, libraries cannot safely initialize libdbus for
multi-threading, because that initialization is not itself
thread-safe (!); in particular, glib-networking cannot safely initialize
libdbus. So, we have to do it.

I have written patches to make libdbus thread-safe-by-default, but
they haven't all been reviewed and merged yet, and in any case they
won't be in a stable libdbus until 1.8. Until then, each application
has to discover and fix this bug individually.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=65296
Reviewed-by: Xavier Claessens <xavier.claessens at collabora.co.uk>

---

 src/gabble.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/src/gabble.c b/src/gabble.c
index f6bbf2c..bd5056d 100644
--- a/src/gabble.c
+++ b/src/gabble.c
@@ -25,6 +25,8 @@
 # include <unistd.h>
 #endif
 
+#include <dbus/dbus.h>
+
 #include <glib/gstdio.h>
 
 #include <telepathy-glib/telepathy-glib.h>
@@ -113,6 +115,9 @@ gabble_init (void)
     g_thread_init (NULL);
 #endif
 
+  if (!dbus_threads_init_default ())
+    g_error ("Unable to initialize libdbus thread-safety (out of memory?)");
+
   g_type_init ();
   wocky_init ();
 }



More information about the telepathy-commits mailing list