telepathy-salut: Initialize libdbus for thread-safety

Simon McVittie smcv at kemper.freedesktop.org
Mon Sep 23 02:45:00 PDT 2013


Module: telepathy-salut
Branch: master
Commit: 46a2ca574fdb0121d27b6d148bed354061adf1d4
URL:    http://cgit.freedesktop.org/telepathy/telepathy-salut/commit/?id=46a2ca574fdb0121d27b6d148bed354061adf1d4

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Mon Sep 23 10:44:41 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.

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.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=65296
[copied from Gabble commit 83bb468e -smcv]
Signed-off-by: Simon McVittie <simon.mcvittie at collabora.co.uk>

---

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

diff --git a/src/salut.c b/src/salut.c
index 8b7f289..f61c29f 100644
--- a/src/salut.c
+++ b/src/salut.c
@@ -1,5 +1,7 @@
 #include "config.h"
 
+#include <dbus/dbus.h>
+
 #include <glib.h>
 
 #include <telepathy-glib/telepathy-glib.h>
@@ -45,6 +47,9 @@ main (int argc, char **argv)
   gint ret;
   SalutPluginLoader *loader;
 
+  if (!dbus_threads_init_default ())
+    g_error ("Unable to initialize libdbus thread-safety (out of memory?)");
+
   g_type_init ();
 
   salut_symbol_hacks ();



More information about the telepathy-commits mailing list