[Xfce4-commits] [xfce/xfce4-power-manager] 07/13: Don't allow systemd to handle suspend/hibernate events.

noreply at xfce.org noreply at xfce.org
Tue Apr 8 18:43:01 CEST 2014


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository xfce/xfce4-power-manager.

commit c8824f344e8523bc48990e584493b8a2ef590699
Author: Mikhail Efremov <sem at altlinux.org>
Date:   Thu Feb 21 15:03:44 2013 +0400

    Don't allow systemd to handle suspend/hibernate events.
    
    Signed-off-by: Eric Koegel <eric.koegel at gmail.com>
---
 src/xfpm-main.c |   87 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 85 insertions(+), 2 deletions(-)

diff --git a/src/xfpm-main.c b/src/xfpm-main.c
index 40959c8..24dacae 100644
--- a/src/xfpm-main.c
+++ b/src/xfpm-main.c
@@ -194,16 +194,96 @@ xfpm_dump_remote (DBusGConnection *bus)
     g_hash_table_destroy (hash);
 }
 
+static gint
+xfpm_inhibit_sleep_systemd (DBusGConnection *bus)
+{
+    DBusConnection *bus_connection;
+    DBusMessage *message = NULL, *reply = NULL;
+    DBusError error;
+    gint fd = -1;
+    const char *what = "handle-power-key:handle-suspend-key:handle-hibernate-key:handle-lid-switch";
+    const char *who = "xfce4-power-manager";
+    const char *why = "xfce4-power-manager handles these events";
+    const char *mode = "block";
+
+    bus_connection = dbus_g_connection_get_connection (bus);
+    if (!xfpm_dbus_name_has_owner (bus_connection, "org.freedesktop.login1"))
+        return -1;
+
+    dbus_error_init (&error);
+
+    message = dbus_message_new_method_call ("org.freedesktop.login1",
+                                            "/org/freedesktop/login1",
+                                            "org.freedesktop.login1.Manager",
+                                            "Inhibit");
+
+    if (!message)
+    {
+        g_warning ("Unable to call Inhibit()");
+        goto done;
+    }
+
+
+    if (!dbus_message_append_args (message,
+                            DBUS_TYPE_STRING, &what,
+                            DBUS_TYPE_STRING, &who,
+                            DBUS_TYPE_STRING, &why,
+                            DBUS_TYPE_STRING, &mode,
+                            DBUS_TYPE_INVALID))
+    {
+        g_warning ("Unable to call Inhibit()");
+        goto done;
+    }
+
+
+    reply = dbus_connection_send_with_reply_and_block (bus_connection, message, -1, &error);
+    if (!reply)
+    {
+        g_warning ("Unable to inhibit systemd sleep: %s", error.message);
+        goto done;
+    }
+
+    if (!dbus_message_get_args (reply, &error,
+                                DBUS_TYPE_UNIX_FD, &fd,
+                                DBUS_TYPE_INVALID))
+    {
+        g_warning ("Inhibit() reply parsing failed: %s", error.message);
+    }
+
+done:
+
+    if (message)
+        dbus_message_unref (message);
+    if (reply)
+        dbus_message_unref (reply);
+    dbus_error_free (&error);
+
+    return fd;
+}
+
 static void G_GNUC_NORETURN
 xfpm_start (DBusGConnection *bus, const gchar *client_id, gboolean dump)
 {
+    DBusGConnection *system_bus;
     XfpmManager *manager;
     GError *error = NULL;
+    gint inhibit_fd = -1;
     
     XFPM_DEBUG ("Starting the power manager");
     
     manager = xfpm_manager_new (bus, client_id);
-    
+
+    /* Don't allow systemd to handle power/suspend/hibernate buttons
+     * and lid-switch */
+    system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+    if (system_bus)
+        inhibit_fd = xfpm_inhibit_sleep_systemd (system_bus);
+    else
+    {
+        g_warning ("Unable connect to system bus: %s", error->message);
+        g_clear_error (&error);
+    }
+
     if ( xfce_posix_signal_handler_init (&error)) 
     {
         xfce_posix_signal_handler_set_handler (SIGHUP,
@@ -238,7 +318,10 @@ xfpm_start (DBusGConnection *bus, const gchar *client_id, gboolean dump)
     gtk_main ();
     
     g_object_unref (manager);
-    
+
+    if (inhibit_fd >= 0)
+        close (inhibit_fd);
+
     exit (EXIT_SUCCESS);
 }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list