From 85d22a5d784b2b8201054257f8696138de1e1b70 Mon Sep 17 00:00:00 2001 From: Marc Deslauriers Date: Wed, 16 Feb 2011 13:40:15 +0000 Subject: Make sure it cannot be running twice It is currently possible to start gnome-screensaver twice because of a race condition. This change makes sure that we bail out if we cannot become the primary owner of the bus name. https://bugzilla.gnome.org/show_bug.cgi?id=642462 --- diff --git a/src/gs-listener-dbus.c b/src/gs-listener-dbus.c index 6d0d4e5..e11c7fc 100644 --- a/src/gs-listener-dbus.c +++ b/src/gs-listener-dbus.c @@ -1169,7 +1169,7 @@ gboolean gs_listener_acquire (GSListener *listener, GError **error) { - gboolean acquired; + int res; DBusError buserror; gboolean is_connected; @@ -1213,9 +1213,10 @@ gs_listener_acquire (GSListener *listener, return FALSE; } - acquired = dbus_bus_request_name (listener->priv->connection, - GS_LISTENER_SERVICE, - 0, &buserror) != -1; + res = dbus_bus_request_name (listener->priv->connection, + GS_LISTENER_SERVICE, + DBUS_NAME_FLAG_DO_NOT_QUEUE, + &buserror); if (dbus_error_is_set (&buserror)) { g_set_error (error, GS_LISTENER_ERROR, @@ -1223,6 +1224,14 @@ gs_listener_acquire (GSListener *listener, "%s", buserror.message); } + if (res == DBUS_REQUEST_NAME_REPLY_EXISTS) { + g_set_error (error, + GS_LISTENER_ERROR, + GS_LISTENER_ERROR_ACQUISITION_FAILURE, + "%s", + _("screensaver already running in this session")); + return FALSE; + } dbus_error_free (&buserror); @@ -1263,7 +1272,7 @@ gs_listener_acquire (GSListener *listener, NULL); } - return acquired; + return (res != -1); } static char * -- cgit v0.8.3.4