From f55a6f37d0805fd9f8270903929cdf08fda55e39 Mon Sep 17 00:00:00 2001 From: William Brown Date: Sun, 18 Nov 2012 12:06:34 +1030 Subject: Current work on systemd-inhibit support in mpm. DOES NOT WORK YET. See https://bugzilla.redhat.com/show_bug.cgi?id=876396 and https://bugzilla.redhat.com/show_bug.cgi?id=876782 --- src/gpm-manager.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'src/gpm-manager.c') diff --git a/src/gpm-manager.c b/src/gpm-manager.c index 9ee8781..150379d 100644 --- a/src/gpm-manager.c +++ b/src/gpm-manager.c @@ -100,6 +100,8 @@ struct GpmManagerPrivate NotifyNotification *notification_warning_low; NotifyNotification *notification_discharging; NotifyNotification *notification_fully_charged; + gint32 systemd_inhibit; + GDBusProxy *systemd_inhibit_proxy; }; typedef enum { @@ -1840,6 +1842,60 @@ gpm_manager_control_resume_cb (GpmControl *control, GpmControlAction action, Gpm g_timeout_add_seconds (1, gpm_manager_reset_just_resumed_cb, manager); } +/** + * gpm_main_system_inhibit: + **/ +static gint32 +gpm_manager_systemd_inhibit (GDBusProxy *proxy) { + /* Return a fd to the to the inhibitor, that we can close on exit. */ + //GDBusProxy *proxy; + GError *error = NULL; + gint32 r = -1; + + proxy == NULL; + /* Should we define these elsewhere? */ + const char* arg_what = "handle-power-key:handle-suspend-key:handle-lid-switch"; + const char* arg_who = "mate-power-manager"; + const char* arg_why = "Mate power manager handles these events"; + const char* arg_mode = "block"; + + egg_debug ("Inhibiting systemd sleep"); + proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, + "org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + NULL, + &error ); + //append all our arguments + if (proxy == NULL) { + egg_error("Error connecting to dbus - %s", error->message); + g_error_free (error); + return -1; + } + r = g_dbus_proxy_call_sync (proxy, "Inhibit", + g_variant_new( "(ssss)", + arg_what, + arg_who, + arg_why, + arg_mode + ), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error + ); + egg_debug ("Inhibiting systemd sleep - fd = %i", r); + if (r < 1) { + egg_error ("Error in dbus - %s", error->message); + g_error_free (error); + return -EIO; + } + egg_debug ("Inhibiting systemd sleep - success"); + return r; +} + /** * gpm_manager_init: * @manager: This class instance @@ -1857,6 +1913,9 @@ gpm_manager_init (GpmManager *manager) connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); g_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); + /* We want to inhibit the systemd suspend options, and take care of them ourselves */ + manager->priv->systemd_inhibit = gpm_manager_systemd_inhibit (manager->priv->systemd_inhibit_proxy); + /* init to unthrottled */ manager->priv->screensaver_ac_throttle_id = 0; manager->priv->screensaver_dpms_throttle_id = 0; @@ -2014,6 +2073,15 @@ gpm_manager_finalize (GObject *object) g_object_unref (manager->priv->client); g_object_unref (manager->priv->status_icon); + /* Let systemd take over again ... */ + if (manager->priv->systemd_inhibit > 0) { + close(manager->priv->systemd_inhibit); + } + if (manager->priv->systemd_inhibit_proxy != NULL) { + g_object_unref (manager->priv->systemd_inhibit_proxy); + } + //g_object_unref (manager->priv->systemd_inhibit); + G_OBJECT_CLASS (gpm_manager_parent_class)->finalize (object); } -- cgit v1.2.1 From d0eea338cc627b3083e16669a7f3e7a738410818 Mon Sep 17 00:00:00 2001 From: William Brown Date: Sun, 18 Nov 2012 12:06:34 +1030 Subject: Current work on systemd-inhibit support in mpm. DOES NOT WORK YET. See https://bugzilla.redhat.com/show_bug.cgi?id=876396 and https://bugzilla.redhat.com/show_bug.cgi?id=876782 --- src/gpm-manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gpm-manager.c') diff --git a/src/gpm-manager.c b/src/gpm-manager.c index 150379d..3236406 100644 --- a/src/gpm-manager.c +++ b/src/gpm-manager.c @@ -1852,7 +1852,7 @@ gpm_manager_systemd_inhibit (GDBusProxy *proxy) { GError *error = NULL; gint32 r = -1; - proxy == NULL; + //proxy == NULL; /* Should we define these elsewhere? */ const char* arg_what = "handle-power-key:handle-suspend-key:handle-lid-switch"; const char* arg_who = "mate-power-manager"; -- cgit v1.2.1 From bb165fa927540f40b2b2afce1b4703f6e2cffbb1 Mon Sep 17 00:00:00 2001 From: William Brown Date: Tue, 20 Nov 2012 00:08:50 +1030 Subject: This now uses the gvariant, and fixes some code logic issues --- src/gpm-manager.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/gpm-manager.c') diff --git a/src/gpm-manager.c b/src/gpm-manager.c index 3236406..dc838c5 100644 --- a/src/gpm-manager.c +++ b/src/gpm-manager.c @@ -1851,7 +1851,7 @@ gpm_manager_systemd_inhibit (GDBusProxy *proxy) { //GDBusProxy *proxy; GError *error = NULL; gint32 r = -1; - + GVariant *res; //proxy == NULL; /* Should we define these elsewhere? */ const char* arg_what = "handle-power-key:handle-suspend-key:handle-lid-switch"; @@ -1874,7 +1874,7 @@ gpm_manager_systemd_inhibit (GDBusProxy *proxy) { g_error_free (error); return -1; } - r = g_dbus_proxy_call_sync (proxy, "Inhibit", + res = g_dbus_proxy_call_sync (proxy, "Inhibit", g_variant_new( "(ssss)", arg_what, arg_who, @@ -1886,11 +1886,17 @@ gpm_manager_systemd_inhibit (GDBusProxy *proxy) { NULL, &error ); - egg_debug ("Inhibiting systemd sleep - fd = %i", r); - if (r < 1) { + if (error == NULL) { + g_variant_get(res, "(h)", &r); + egg_debug ("Inhibiting systemd sleep - fd = %i", r); + } else if (error != NULL) { egg_error ("Error in dbus - %s", error->message); g_error_free (error); - return -EIO; + return -EIO; + } + if (r < 1) { + egg_error ("Error in FD was less than or 0 - %i", r); + return -EIO; } egg_debug ("Inhibiting systemd sleep - success"); return r; -- cgit v1.2.1 From c5c3b2a3d755e32a851bf7b3c7ef92a056b5bdef Mon Sep 17 00:00:00 2001 From: William Brown Date: Wed, 21 Nov 2012 09:06:22 +1030 Subject: Initial working support for systemd inhibition --- src/gpm-manager.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'src/gpm-manager.c') diff --git a/src/gpm-manager.c b/src/gpm-manager.c index dc838c5..34d8e9a 100644 --- a/src/gpm-manager.c +++ b/src/gpm-manager.c @@ -1851,11 +1851,13 @@ gpm_manager_systemd_inhibit (GDBusProxy *proxy) { //GDBusProxy *proxy; GError *error = NULL; gint32 r = -1; + gint32 fd = -1; GVariant *res; + GUnixFDList *fd_list = NULL; //proxy == NULL; /* Should we define these elsewhere? */ const char* arg_what = "handle-power-key:handle-suspend-key:handle-lid-switch"; - const char* arg_who = "mate-power-manager"; + const char* arg_who = g_get_user_name (); const char* arg_why = "Mate power manager handles these events"; const char* arg_mode = "block"; @@ -1874,7 +1876,7 @@ gpm_manager_systemd_inhibit (GDBusProxy *proxy) { g_error_free (error); return -1; } - res = g_dbus_proxy_call_sync (proxy, "Inhibit", + res = g_dbus_proxy_call_with_unix_fd_list_sync (proxy, "Inhibit", g_variant_new( "(ssss)", arg_what, arg_who, @@ -1884,20 +1886,26 @@ gpm_manager_systemd_inhibit (GDBusProxy *proxy) { G_DBUS_CALL_FLAGS_NONE, -1, NULL, + &fd_list, + NULL, &error ); - if (error == NULL) { + if (error == NULL && res != NULL) { g_variant_get(res, "(h)", &r); - egg_debug ("Inhibiting systemd sleep - fd = %i", r); - } else if (error != NULL) { + egg_debug ("Inhibiting systemd sleep res = %i", r); + fd = g_unix_fd_list_get (fd_list, r, &error); + if (fd == -1) { + egg_debug("Failed to get systemd inhibitor"); + return r; + } + egg_debug ("System inhibitor fd is %d", fd); + g_object_unref (fd_list); + g_variant_unref (res); + } else if (error != NULL || res == NULL) { egg_error ("Error in dbus - %s", error->message); g_error_free (error); return -EIO; } - if (r < 1) { - egg_error ("Error in FD was less than or 0 - %i", r); - return -EIO; - } egg_debug ("Inhibiting systemd sleep - success"); return r; } -- cgit v1.2.1 From 30eed18125a03a0bede7f5e560f8f031db70dcbe Mon Sep 17 00:00:00 2001 From: William Brown Date: Wed, 21 Nov 2012 09:15:29 +1030 Subject: Adds a systemdinhibit configure flag --- src/gpm-manager.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/gpm-manager.c') diff --git a/src/gpm-manager.c b/src/gpm-manager.c index 34d8e9a..c6f4d79 100644 --- a/src/gpm-manager.c +++ b/src/gpm-manager.c @@ -1842,6 +1842,7 @@ gpm_manager_control_resume_cb (GpmControl *control, GpmControlAction action, Gpm g_timeout_add_seconds (1, gpm_manager_reset_just_resumed_cb, manager); } +#ifdef WITH_SYSTEMD_INHIBIT /** * gpm_main_system_inhibit: **/ @@ -1909,6 +1910,7 @@ gpm_manager_systemd_inhibit (GDBusProxy *proxy) { egg_debug ("Inhibiting systemd sleep - success"); return r; } +#endif /** * gpm_manager_init: @@ -1927,8 +1929,10 @@ gpm_manager_init (GpmManager *manager) connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); g_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); +#ifdef WITH_SYSTEMD_INHIBIT /* We want to inhibit the systemd suspend options, and take care of them ourselves */ manager->priv->systemd_inhibit = gpm_manager_systemd_inhibit (manager->priv->systemd_inhibit_proxy); +#endif /* init to unthrottled */ manager->priv->screensaver_ac_throttle_id = 0; @@ -2087,6 +2091,7 @@ gpm_manager_finalize (GObject *object) g_object_unref (manager->priv->client); g_object_unref (manager->priv->status_icon); +#ifdef WITH_SYSTEMD_INHIBIT /* Let systemd take over again ... */ if (manager->priv->systemd_inhibit > 0) { close(manager->priv->systemd_inhibit); @@ -2095,6 +2100,7 @@ gpm_manager_finalize (GObject *object) g_object_unref (manager->priv->systemd_inhibit_proxy); } //g_object_unref (manager->priv->systemd_inhibit); +#endif G_OBJECT_CLASS (gpm_manager_parent_class)->finalize (object); } -- cgit v1.2.1