Merge branch '604-dbus-name-watching-simplification' into 'master'

gdbusnamewatching: Check cancellation of a watch before calling back

Closes #604

See merge request GNOME/glib!1336
This commit is contained in:
Philip Withnall 2020-01-21 11:15:36 +00:00
commit 5d32b99d0c

View File

@ -148,6 +148,11 @@ call_handler_data_free (CallHandlerData *data)
static void static void
actually_do_call (Client *client, GDBusConnection *connection, const gchar *name_owner, CallType call_type) actually_do_call (Client *client, GDBusConnection *connection, const gchar *name_owner, CallType call_type)
{ {
/* The client might have been cancelled (g_bus_unwatch_name()) while we were
* sitting in the #GMainContext dispatch queue. */
if (client->cancelled)
return;
switch (call_type) switch (call_type)
{ {
case CALL_TYPE_NAME_APPEARED: case CALL_TYPE_NAME_APPEARED:
@ -234,13 +239,12 @@ call_appeared_handler (Client *client)
} }
static void static void
call_vanished_handler (Client *client, call_vanished_handler (Client *client)
gboolean ignore_cancelled)
{ {
if (client->previous_call != PREVIOUS_CALL_VANISHED) if (client->previous_call != PREVIOUS_CALL_VANISHED)
{ {
client->previous_call = PREVIOUS_CALL_VANISHED; client->previous_call = PREVIOUS_CALL_VANISHED;
if (((!client->cancelled) || ignore_cancelled) && client->name_vanished_handler != NULL) if (!client->cancelled && client->name_vanished_handler != NULL)
{ {
do_call (client, CALL_TYPE_NAME_VANISHED); do_call (client, CALL_TYPE_NAME_VANISHED);
} }
@ -296,7 +300,7 @@ on_connection_disconnected (GDBusConnection *connection,
client->name_owner_changed_subscription_id = 0; client->name_owner_changed_subscription_id = 0;
client->connection = NULL; client->connection = NULL;
call_vanished_handler (client, FALSE); call_vanished_handler (client);
client_unref (client); client_unref (client);
} }
@ -345,7 +349,7 @@ on_name_owner_changed (GDBusConnection *connection,
{ {
g_free (client->name_owner); g_free (client->name_owner);
client->name_owner = NULL; client->name_owner = NULL;
call_vanished_handler (client, FALSE); call_vanished_handler (client);
} }
if (new_owner != NULL && strlen (new_owner) > 0) if (new_owner != NULL && strlen (new_owner) > 0)
@ -390,7 +394,7 @@ get_name_owner_cb (GObject *source_object,
} }
else else
{ {
call_vanished_handler (client, FALSE); call_vanished_handler (client);
} }
client->initialized = TRUE; client->initialized = TRUE;
@ -450,7 +454,7 @@ start_service_by_name_cb (GObject *source_object,
else else
{ {
g_warning ("Unexpected reply %d from StartServiceByName() method", start_service_result); g_warning ("Unexpected reply %d from StartServiceByName() method", start_service_result);
call_vanished_handler (client, FALSE); call_vanished_handler (client);
client->initialized = TRUE; client->initialized = TRUE;
} }
} }
@ -529,7 +533,7 @@ connection_get_cb (GObject *source_object,
client->connection = g_bus_get_finish (res, NULL); client->connection = g_bus_get_finish (res, NULL);
if (client->connection == NULL) if (client->connection == NULL)
{ {
call_vanished_handler (client, FALSE); call_vanished_handler (client);
goto out; goto out;
} }