From: Adrian Szyndela Date: Mon, 5 Dec 2016 14:38:08 +0000 (+0100) Subject: fix for race condition in watching names X-Git-Tag: accepted/tizen/common/20161212.185410^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F92%2F102992%2F1;p=platform%2Fupstream%2Fglib.git fix for race condition in watching names Change-Id: I11fa92a6dae62cb3bdaa4159db0da160752063d1 (cherry picked from commit f1f2e5e4df63f06cac53148e5c91a27a56eea9ca) --- diff --git a/gio/gdbusnamewatching.c b/gio/gdbusnamewatching.c old mode 100644 new mode 100755 index 07713db..c2ed2aa --- a/gio/gdbusnamewatching.c +++ b/gio/gdbusnamewatching.c @@ -282,9 +282,6 @@ on_name_owner_changed (GDBusConnection *connection, const gchar *old_owner; const gchar *new_owner; - if (!client->initialized) - goto out; - if (g_strcmp0 (object_path, "/org/freedesktop/DBus") != 0 || g_strcmp0 (interface_name, "org.freedesktop.DBus") != 0 || g_strcmp0 (sender_name, "org.freedesktop.DBus") != 0) @@ -300,7 +297,7 @@ on_name_owner_changed (GDBusConnection *connection, if (g_strcmp0 (name, client->name) != 0) goto out; - if ((old_owner != NULL && strlen (old_owner) > 0) && client->name_owner != NULL) + if (old_owner != NULL && strlen (old_owner) > 0) { g_free (client->name_owner); client->name_owner = NULL; @@ -309,12 +306,18 @@ on_name_owner_changed (GDBusConnection *connection, if (new_owner != NULL && strlen (new_owner) > 0) { - g_warn_if_fail (client->name_owner == NULL); g_free (client->name_owner); client->name_owner = g_strdup (new_owner); call_appeared_handler (client); } + /* initialized set to TRUE means that signal was delivered and processed. + * Now, if we receive a reply to GetNameOwner call, we may just ignore it as it carries the same + * information as the current signal, or if something changed in the meantime we will + * get next signal very soon. + */ + client->initialized = TRUE; + out: ; } @@ -336,6 +339,13 @@ get_name_owner_cb (GObject *source_object, result = g_dbus_connection_call_finish (client->connection, res, NULL); + /* In case we already received NameOwnerChanged signal, we don't need to + * process GetNameOwner answer, because all the information we needed was already + * delivered with the signal and processed by the signal handler. + */ + if (client->initialized) + goto out; + if (result != NULL) { g_variant_get (result, "(&s)", &name_owner); @@ -352,10 +362,10 @@ get_name_owner_cb (GObject *source_object, call_vanished_handler (client, FALSE); } - client->initialized = TRUE; - + out: if (result != NULL) g_variant_unref (result); + client_unref (client); } @@ -410,7 +420,6 @@ start_service_by_name_cb (GObject *source_object, { g_warning ("Unexpected reply %d from StartServiceByName() method", start_service_result); call_vanished_handler (client, FALSE); - client->initialized = TRUE; } } else