[rygel] core: Shutdown other instance of rygel ourselves



commit a400775e80fcaa069f2387fe8fea2dc60a972135
Author: Jens Georg <mail jensge org>
Date:   Wed Jul 27 11:32:49 2011 +0300

    core: Shutdown other instance of rygel ourselves
    
    We need to wait for the other instance to be shut down, so we do it
    ourselves instead of using BusNameOwnerFlags.REPLACE.

 src/rygel/rygel-dbus-service.vala |   21 +++++++++++++--------
 src/rygel/rygel-main.vala         |    4 ++++
 2 files changed, 17 insertions(+), 8 deletions(-)
---
diff --git a/src/rygel/rygel-dbus-service.vala b/src/rygel/rygel-dbus-service.vala
index ebc7bbb..1cb352d 100644
--- a/src/rygel/rygel-dbus-service.vala
+++ b/src/rygel/rygel-dbus-service.vala
@@ -38,8 +38,7 @@ public class Rygel.DBusService : Object, DBusInterface {
     internal void publish () {
         this.name_id = Bus.own_name (BusType.SESSION,
                                      DBusInterface.SERVICE_NAME,
-                                     BusNameOwnerFlags.ALLOW_REPLACEMENT |
-                                     BusNameOwnerFlags.REPLACE,
+                                     BusNameOwnerFlags.NONE,
                                      this.on_bus_aquired,
                                      this.on_name_available,
                                      this.on_name_lost);
@@ -79,13 +78,19 @@ public class Rygel.DBusService : Object, DBusInterface {
             return;
         }
 
-        if (this.connection_id != 0) {
-            message (_("Another instance of Rygel is taking over. Exiting"));
-        } else {
-            message (_("Another instance of Rygel is already running."));
-        }
+        // Cleanly shutdown other instance.
+        try {
+            DBusInterface rygel = Bus.get_proxy_sync (BusType.SESSION,
+                                                      DBusInterface.SERVICE_NAME,
+                                                      DBusInterface.OBJECT_PATH,
+                                                      DBusProxyFlags.DO_NOT_LOAD_PROPERTIES);
+            rygel.shutdown ();
+        } catch (Error error) {
+            warning ("Failed to shut-down other rygel instance: %s",
+                     error.message);
 
-        this.main.exit (12);
+            this.main.exit (-12);
+        }
     }
 }
 
diff --git a/src/rygel/rygel-main.vala b/src/rygel/rygel-main.vala
index fa521d4..70a25a4 100644
--- a/src/rygel/rygel-main.vala
+++ b/src/rygel/rygel-main.vala
@@ -212,6 +212,10 @@ public class Rygel.Main : Object {
 
     private void on_plugin_active_notify (Object    obj,
                                           ParamSpec spec) {
+        if (unlikely (this.root_devices == null)) {
+            return;
+        }
+
         var plugin = obj as Plugin;
 
         foreach (var device in this.root_devices) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]