[gdm] greeter: use org.freedesktop.login1 to shutdown



commit 67d91afb77a162961c1dd86634a6ebe0136ac7a2
Author: Edward Sheldrake <ejsheldrake gmail com>
Date:   Wed Apr 25 09:29:46 2012 +0100

    greeter: use org.freedesktop.login1 to shutdown
    
    To make the restart and shutdown menu items in the fallback greeter
    function without ConsoleKit, try the org.freedesktop.login1.Manager dbus
    interface first. If that interface is not present, fallback to ConsoleKit.
    
    Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=674741

 gui/simple-greeter/gdm-greeter-panel.c |   91 +++++++++++++++++++++++--------
 1 files changed, 67 insertions(+), 24 deletions(-)
---
diff --git a/gui/simple-greeter/gdm-greeter-panel.c b/gui/simple-greeter/gdm-greeter-panel.c
index 552e6fa..ba6f810 100644
--- a/gui/simple-greeter/gdm-greeter-panel.c
+++ b/gui/simple-greeter/gdm-greeter-panel.c
@@ -56,6 +56,10 @@
 #define CK_MANAGER_PATH      "/org/freedesktop/ConsoleKit/Manager"
 #define CK_MANAGER_INTERFACE "org.freedesktop.ConsoleKit.Manager"
 
+#define LOGIN1_NAME      "org.freedesktop.login1"
+#define LOGIN1_PATH      "/org/freedesktop/login1"
+#define LOGIN1_INTERFACE "org.freedesktop.login1.Manager"
+
 #define GPM_DBUS_NAME      "org.gnome.SettingsDaemon"
 #define GPM_DBUS_PATH      "/org/gnome/SettingsDaemon/Power"
 #define GPM_DBUS_INTERFACE "org.gnome.SettingsDaemon.Power"
@@ -630,18 +634,38 @@ try_system_stop (DBusGConnection *connection,
 
         g_debug ("GdmGreeterPanel: trying to stop system");
 
-        proxy = dbus_g_proxy_new_for_name (connection,
-                                           CK_NAME,
-                                           CK_MANAGER_PATH,
-                                           CK_MANAGER_INTERFACE);
-        res = dbus_g_proxy_call_with_timeout (proxy,
-                                              "Stop",
-                                              INT_MAX,
-                                              error,
-                                              /* parameters: */
-                                              G_TYPE_INVALID,
-                                              /* return values: */
-                                              G_TYPE_INVALID);
+        /* try systemd first */
+        proxy = dbus_g_proxy_new_for_name_owner (connection,
+                                                 LOGIN1_NAME,
+                                                 LOGIN1_PATH,
+                                                 LOGIN1_INTERFACE,
+                                                 error);
+        if (proxy) {
+                res = dbus_g_proxy_call_with_timeout (proxy,
+                                                      "PowerOff",
+                                                      INT_MAX,
+                                                      error,
+                                                      /* parameters: */
+                                                      G_TYPE_BOOLEAN,
+                                                      TRUE,
+                                                      G_TYPE_INVALID,
+                                                      /* return values: */
+                                                      G_TYPE_INVALID);
+        } else {
+                proxy = dbus_g_proxy_new_for_name (connection,
+                                                   CK_NAME,
+                                                   CK_MANAGER_PATH,
+                                                   CK_MANAGER_INTERFACE);
+                res = dbus_g_proxy_call_with_timeout (proxy,
+                                                      "Stop",
+                                                      INT_MAX,
+                                                      error,
+                                                      /* parameters: */
+                                                      G_TYPE_INVALID,
+                                                      /* return values: */
+                                                      G_TYPE_INVALID);
+        }
+
         return res;
 }
 
@@ -654,18 +678,37 @@ try_system_restart (DBusGConnection *connection,
 
         g_debug ("GdmGreeterPanel: trying to restart system");
 
-        proxy = dbus_g_proxy_new_for_name (connection,
-                                           CK_NAME,
-                                           CK_MANAGER_PATH,
-                                           CK_MANAGER_INTERFACE);
-        res = dbus_g_proxy_call_with_timeout (proxy,
-                                              "Restart",
-                                              INT_MAX,
-                                              error,
-                                              /* parameters: */
-                                              G_TYPE_INVALID,
-                                              /* return values: */
-                                              G_TYPE_INVALID);
+        /* try systemd first */
+        proxy = dbus_g_proxy_new_for_name_owner (connection,
+                                                 LOGIN1_NAME,
+                                                 LOGIN1_PATH,
+                                                 LOGIN1_INTERFACE,
+                                                 error);
+        if (proxy) {
+                res = dbus_g_proxy_call_with_timeout (proxy,
+                                                      "Reboot",
+                                                      INT_MAX,
+                                                      error,
+                                                      /* parameters: */
+                                                      G_TYPE_BOOLEAN,
+                                                      TRUE,
+                                                      G_TYPE_INVALID,
+                                                      /* return values: */
+                                                      G_TYPE_INVALID);
+        } else {
+                proxy = dbus_g_proxy_new_for_name (connection,
+                                                   CK_NAME,
+                                                   CK_MANAGER_PATH,
+                                                   CK_MANAGER_INTERFACE);
+                res = dbus_g_proxy_call_with_timeout (proxy,
+                                                      "Restart",
+                                                      INT_MAX,
+                                                      error,
+                                                      /* parameters: */
+                                                      G_TYPE_INVALID,
+                                                      /* return values: */
+                                                      G_TYPE_INVALID);
+        }
         return res;
 }
 



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