Description: Allow the dbus service to be replaced, so that other implementations of the interface (e.g. Unity) can take the service over.
 We quit if someone else claims the name, as D-Bus activation will restart us if that owner then goes away.
Author: Iain Lane <iain.lane@canonical.com>
Forwared: not-needed

Index: b/src/gs-listener-dbus.c
===================================================================
--- a/src/gs-listener-dbus.c
+++ b/src/gs-listener-dbus.c
@@ -28,6 +28,7 @@
 #include <unistd.h>
 
 #include <glib/gi18n.h>
+#include <gtk/gtk.h>
 
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib.h>
@@ -1092,7 +1093,24 @@
                 g_timeout_add (10000, (GSourceFunc)reinit_dbus, listener);
         } else if (dbus_message_is_signal (message,
                                            DBUS_INTERFACE_DBUS,
-                                           "NameOwnerChanged")) {
+                                           "NameLost")) {
+                const char *name;
+                DBusError error;
+                dbus_error_init (&error);
+
+                if (!dbus_message_get_args (message, &error,
+                                            DBUS_TYPE_STRING, &name,
+                                            DBUS_TYPE_INVALID)) {
+                    g_warning("Got NameLost, but couldn't read name");
+                    dbus_error_free (&error);
+                } else {
+                    if (strcmp (name, GS_INTERFACE) == 0) { // We've been replaced
+                        g_message ("Lost the name, shutting down.");
+                        dbus_connection_unref (connection);
+                        listener->priv->connection = NULL;
+                        gtk_main_quit ();
+                    }
+                }
         } else {
                 return listener_dbus_handle_session_message (connection, message, user_data, FALSE);
         }
@@ -1317,7 +1335,6 @@
                              _("not connected to the message bus"));
                 return FALSE;
         }
-
         if (screensaver_is_running (listener->priv->connection)) {
                 g_set_error (error,
                              GS_LISTENER_ERROR,
@@ -1339,7 +1356,7 @@
 
         res = dbus_bus_request_name (listener->priv->connection,
                                      GS_SERVICE,
-                                     DBUS_NAME_FLAG_DO_NOT_QUEUE,
+                                     DBUS_NAME_FLAG_DO_NOT_QUEUE | DBUS_NAME_FLAG_ALLOW_REPLACEMENT,
                                      &buserror);
         if (dbus_error_is_set (&buserror)) {
                 g_set_error (error,
@@ -1365,7 +1382,7 @@
                             "type='signal'"
                             ",interface='"DBUS_INTERFACE_DBUS"'"
                             ",sender='"DBUS_SERVICE_DBUS"'"
-                            ",member='NameOwnerChanged'",
+                            ",member='NameLost'",
                             NULL);
 
         if (listener->priv->system_connection != NULL) {
