mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-20 23:58:54 +02:00
Avoid a race in application registration
We need to register the object before taking the name. Remove the workarounds for this race from the test suite.
This commit is contained in:
@@ -289,22 +289,6 @@ ensure_bus (GApplication *app)
|
|||||||
static void
|
static void
|
||||||
_g_application_platform_init (GApplication *app)
|
_g_application_platform_init (GApplication *app)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
|
||||||
guint registration_id;
|
|
||||||
|
|
||||||
ensure_bus (app);
|
|
||||||
|
|
||||||
registration_id = g_dbus_connection_register_object (app->priv->session_bus,
|
|
||||||
app->priv->dbus_path,
|
|
||||||
&application_dbus_interface_info,
|
|
||||||
&application_dbus_vtable,
|
|
||||||
app, NULL,
|
|
||||||
&error);
|
|
||||||
if (registration_id == 0)
|
|
||||||
{
|
|
||||||
g_error ("%s", error->message);
|
|
||||||
g_error_free (error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@@ -313,11 +297,24 @@ _g_application_platform_acquire_single_instance (GApplication *app,
|
|||||||
{
|
{
|
||||||
GVariant *request_result;
|
GVariant *request_result;
|
||||||
guint32 request_status;
|
guint32 request_status;
|
||||||
|
gboolean result;
|
||||||
|
guint registration_id;
|
||||||
|
|
||||||
ensure_bus (app);
|
ensure_bus (app);
|
||||||
|
|
||||||
if (app->priv->session_bus == NULL)
|
if (app->priv->session_bus == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
registration_id = g_dbus_connection_register_object (app->priv->session_bus,
|
||||||
|
app->priv->dbus_path,
|
||||||
|
&application_dbus_interface_info,
|
||||||
|
&application_dbus_vtable,
|
||||||
|
app,
|
||||||
|
NULL,
|
||||||
|
error);
|
||||||
|
if (registration_id == 0)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
request_result = g_dbus_connection_call_sync (app->priv->session_bus,
|
request_result = g_dbus_connection_call_sync (app->priv->session_bus,
|
||||||
"org.freedesktop.DBus",
|
"org.freedesktop.DBus",
|
||||||
"/org/freedesktop/DBus",
|
"/org/freedesktop/DBus",
|
||||||
@@ -327,7 +324,10 @@ _g_application_platform_acquire_single_instance (GApplication *app,
|
|||||||
NULL, 0, -1, NULL, error);
|
NULL, 0, -1, NULL, error);
|
||||||
|
|
||||||
if (request_result == NULL)
|
if (request_result == NULL)
|
||||||
return FALSE;
|
{
|
||||||
|
result = FALSE;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
if (g_variant_is_of_type (request_result, G_VARIANT_TYPE ("(u)")))
|
if (g_variant_is_of_type (request_result, G_VARIANT_TYPE ("(u)")))
|
||||||
g_variant_get (request_result, "(u)", &request_status);
|
g_variant_get (request_result, "(u)", &request_status);
|
||||||
@@ -343,10 +343,17 @@ _g_application_platform_acquire_single_instance (GApplication *app,
|
|||||||
else
|
else
|
||||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unknown error");
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unknown error");
|
||||||
|
|
||||||
return FALSE;
|
result = FALSE;
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
result = TRUE;
|
||||||
|
|
||||||
|
done:
|
||||||
|
if (!result)
|
||||||
|
g_dbus_connection_unregister_object (app->priv->session_bus, registration_id);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@@ -339,12 +339,7 @@ test_quit_on_app_appeared (void)
|
|||||||
on_name_disappeared_quit,
|
on_name_disappeared_quit,
|
||||||
loop,
|
loop,
|
||||||
NULL);
|
NULL);
|
||||||
|
call_quit (NULL);
|
||||||
/* We need a timeout here, since we may otherwise end up calling
|
|
||||||
* Quit after the application took the name, but before it registered
|
|
||||||
* the object.
|
|
||||||
*/
|
|
||||||
g_timeout_add (500, call_quit, NULL);
|
|
||||||
|
|
||||||
g_main_loop_run (loop);
|
g_main_loop_run (loop);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user