[gjs] dbus: Do connection processing in a high priority timeout



commit f974130db3a12cc7f8b1899880616267e60f5ed3
Author: Colin Walters <walters verbum org>
Date:   Fri Apr 1 15:19:43 2011 -0400

    dbus: Do connection processing in a high priority timeout
    
    Otherwise, we risk race conditions if dbus-glib processes
    messages before we've had a chance to set up our exports.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=646246

 gjs-dbus/dbus.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/gjs-dbus/dbus.c b/gjs-dbus/dbus.c
index 4b526f3..2cb2639 100644
--- a/gjs-dbus/dbus.c
+++ b/gjs-dbus/dbus.c
@@ -349,11 +349,19 @@ _gjs_dbus_ensure_connect_idle(DBusBusType bus_type)
 {
     if (bus_type == DBUS_BUS_SESSION) {
         if (session_connect_idle_id == 0) {
-            session_connect_idle_id = g_idle_add(connect_idle, GINT_TO_POINTER(bus_type));
+            /* We use G_PRIORITY_HIGH to ensure that any deferred
+             * work (such as setting up exports) happens *before*
+             * potentially reading any messages from the socket.  If we
+             * didn't, this could lead to race conditions.  See
+             * https://bugzilla.gnome.org/show_bug.cgi?id=646246
+             */
+            session_connect_idle_id = g_timeout_add_full(G_PRIORITY_HIGH, 0, connect_idle,
+                                                         GINT_TO_POINTER(bus_type), NULL);
         }
     } else if (bus_type == DBUS_BUS_SYSTEM) {
         if (system_connect_idle_id == 0) {
-            system_connect_idle_id = g_idle_add(connect_idle, GINT_TO_POINTER(bus_type));
+            system_connect_idle_id = g_timeout_add_full(G_PRIORITY_HIGH, 0, connect_idle,
+                                                        GINT_TO_POINTER(bus_type), NULL);
         }
     } else {
         g_assert_not_reached();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]