Description: Initialise DBus threading support
 colord itself uses GDBus, which is threadsafely implemented on top of libdbus.
 .
 However, colord links to other libraries which use libdbus directly, and do so
 from multiple threads.
 .
 Explicitly initialise dbus threading support to avoid weird and wonderful dbus
 crashes inside avahi.
Author: Christopher James Halse Rogers <raof@ubuntu.com>

--- colord-0.1.16.orig/configure.ac
+++ colord-0.1.16/configure.ac
@@ -127,6 +127,8 @@ dnl - Check library dependencies
 dnl ---------------------------------------------------------------------------
 PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.28.0 gobject-2.0 gthread-2.0 gio-2.0 >= 2.25.9 gio-unix-2.0 gmodule-2.0)
 PKG_CHECK_MODULES(GUSB, gusb >= 0.1.1, have_gusb=yes, have_gusb=no)
+PKG_CHECK_MODULES(DBUS, dbus-1)
+
 if test x$have_gusb = xyes; then
 	AC_DEFINE(HAVE_GUSB,1,[whether gusb is available])
 fi
@@ -187,9 +189,6 @@ dnl ------------------------------------
 AC_ARG_ENABLE(examples, AS_HELP_STRING([--enable-examples],[enable DBus example code]),
 	      enable_examples=$enableval,enable_examples=yes)
 AM_CONDITIONAL(CD_BUILD_EXAMPLES, test x$enable_examples = xyes)
-if test x$enable_examples = xyes; then
-	PKG_CHECK_MODULES(DBUS, dbus-1)
-fi
 
 dnl ---------------------------------------------------------------------------
 dnl - Build reverse engineering
--- colord-0.1.16.orig/src/Makefile.am
+++ colord-0.1.16/src/Makefile.am
@@ -15,6 +15,7 @@ INCLUDES =						\
 	$(GUDEV_CFLAGS)					\
 	$(SANE_CFLAGS)					\
 	$(SQLITE_CFLAGS)				\
+	$(DBUS_CFLAGS)					\
 	-I$(top_srcdir)/libcolord			\
 	-DG_LOG_DOMAIN=\"Cd\"				\
 	-DLIBEXECDIR=\"$(libexecdir)\"			\
@@ -80,7 +81,8 @@ colord_LDADD =						\
 	$(LCMS_LIBS)					\
 	$(GUDEV_LIBS)					\
 	$(SANE_LIBS)					\
-	$(GLIB_LIBS)
+	$(GLIB_LIBS)					\
+	$(DBUS_LIBS)
 
 colord_CFLAGS =						\
 	$(WARNINGFLAGS_C)
--- colord-0.1.16.orig/src/cd-main.c
+++ colord-0.1.16/src/cd-main.c
@@ -24,6 +24,7 @@
 #include <gio/gio.h>
 #include <gio/gunixfdlist.h>
 #include <glib/gi18n.h>
+#include <dbus/dbus.h>
 #include <locale.h>
 
 #include "cd-debug.h"
@@ -1783,6 +1784,15 @@ main (int argc, char *argv[])
 
 	g_type_init ();
 
+	/* GDBus is implemented on top of libdbus in a thread-safe manner but
+	 * does *not* initialise libdbus' threadsafety.
+	 *
+	 * Since we link to libraries that use libdbus directly, and spawn
+	 * threads, we should initialise dbus threadsafety so we don't get
+	 * fun random crashes in dbus.
+	 */
+	dbus_threads_init_default ();
+
 	/* TRANSLATORS: program name */
 	g_set_application_name (_("Color Management"));
 	context = g_option_context_new (NULL);
