core: UserConfig doesn't bail-out on D-Bus unavailability
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 30 Sep 2009 12:39:32 +0000 (15:39 +0300)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 30 Sep 2009 12:42:45 +0000 (15:42 +0300)
src/rygel/rygel-user-config.vala

index 2902d0d..8ea5a1b 100644 (file)
@@ -147,16 +147,20 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
                                       KeyFileFlags.KEEP_TRANSLATIONS);
         debug ("Loaded user configuration from file '%s'", path);
 
-        DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION);
-
-        // Create proxy to Rygel
-        this.rygel_obj = connection.get_object (RYGEL_SERVICE,
-                                                RYGEL_PATH,
-                                                RYGEL_INTERFACE);
-        // and DBus
-        this.dbus_obj = connection.get_object (DBUS_SERVICE,
-                                               DBUS_PATH,
-                                               DBUS_INTERFACE);
+        try {
+            DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION);
+
+            // Create proxy to Rygel
+            this.rygel_obj = connection.get_object (RYGEL_SERVICE,
+                                                    RYGEL_PATH,
+                                                    RYGEL_INTERFACE);
+            // and DBus
+            this.dbus_obj = connection.get_object (DBUS_SERVICE,
+                                                   DBUS_PATH,
+                                                   DBUS_INTERFACE);
+        } catch (DBus.Error err) {
+            debug ("Failed to connect to session bus: %s", err.message);
+        }
     }
 
     public void save () {
@@ -290,9 +294,11 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
                 uint32 res;
 
                 // Start service first
-                this.dbus_obj.StartServiceByName (RYGEL_SERVICE,
-                                                  (uint32) 0,
-                                                  out res);
+                if (this.dbus_obj != null) {
+                    this.dbus_obj.StartServiceByName (RYGEL_SERVICE,
+                                                      (uint32) 0,
+                                                      out res);
+                }
 
                 // Then symlink the desktop file to user's autostart dir
                 var source_path = Path.build_filename (BuildConfig.DESKTOP_DIR,
@@ -304,7 +310,9 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
                 this.set_bool ("general", ENABLED_KEY, true);
             } else {
                 // Stop service first
-                this.rygel_obj.Shutdown ();
+                if (this.rygel_obj != null) {
+                    this.rygel_obj.Shutdown ();
+                }
 
                 // Then delete the symlink from user's autostart dir
                 try {