Hi,
This is my first post to this list, so allow me to introduce myself. I am a
Physics professor at the University of Toulouse in France, so rather amateur
in computer science. I contribute to the edition of the LFS and BLFS books
(http://www.linuxfromscratch.org). We have two editions of the books, one with
systemd and the other with sysvinit.
For the latter, we cannot use logind for suspend hibernate, but newer versions
of UPower cannot be used either since upstream has dropped suspend/hibernate
support in recent versions (0.99.x). On the other hand, recent versions of
ConsoleKit2 have implemented the same interface as logind for Shutdown,
Reboot, Suspend and Hibernate. The attached patch allows using this interface
in lxsession-logout.
The patch is against version 0.5.2 of lxsession. I have mainly copied the code
for systemd. I have tested it on an lxde desktop built according to
http://www.linuxfromscratch.org/blfs/view/svn/lxde/lxde-desktop.html.
Please let me know if you prefer another type of submission (feature request,
pull request...). But you might just tell me you are not interested, so I do
not want to invest too much in git forking yet.
Regards,
Pierre
diff -Naur lxsession-0.5.2-old/lxlock/lxlock lxsession-0.5.2-new/lxlock/lxlock
--- lxsession-0.5.2-old/lxlock/lxlock 2014-11-29 15:43:14.000000000 +0100
+++ lxsession-0.5.2-new/lxlock/lxlock 2016-04-09 19:11:24.317005824 +0200
@@ -29,11 +29,11 @@
xscreensaver-command -lock >/dev/null 2>&1
elif pidof gnome-screensaver >/dev/null; then
gnome-screensaver-command --lock
-elif which slock >/dev/null; then
+elif which slock >/dev/null 2>&1; then
slock &
-elif which xlock 2>/dev/null; then
+elif which xlock >/dev/null 2>&1; then
xlock $*
-elif which i3lock >/dev/null; then
+elif which i3lock >/dev/null 2>&1; then
i3lock -d
else
# In the end, try to fallback to xscreensaver
diff -Naur lxsession-0.5.2-old/lxsession-logout/lxsession-logout.c lxsession-0.5.2-new/lxsession-logout/lxsession-logout.c
--- lxsession-0.5.2-old/lxsession-logout/lxsession-logout.c 2014-11-29 15:43:14.000000000 +0100
+++ lxsession-0.5.2-new/lxsession-logout/lxsession-logout.c 2016-04-09 21:02:25.035056912 +0200
@@ -69,6 +69,8 @@
int hibernate_systemd : 1; /* Hibernate is available via systemd */
int shutdown_ConsoleKit : 1; /* Shutdown is available via ConsoleKit */
int reboot_ConsoleKit : 1; /* Reboot is available via ConsoleKit */
+ int suspend_ConsoleKit : 1; /* Suspend is available via ConsoleKit */
+ int hibernate_ConsoleKit : 1; /* Hibernate is available via ConsoleKit */
int suspend_UPower : 1; /* Suspend is available via UPower */
int hibernate_UPower : 1; /* Hibernate is available via UPower */
int switch_user_GDM : 1; /* Switch User is available via GDM */
@@ -222,7 +224,7 @@
}
}
else if (handler_context->shutdown_ConsoleKit)
- dbus_ConsoleKit_Stop(&err);
+ dbus_ConsoleKit_PowerOff(&err);
else if (handler_context->shutdown_systemd)
dbus_systemd_PowerOff(&err);
@@ -252,7 +254,7 @@
}
}
else if (handler_context->reboot_ConsoleKit)
- dbus_ConsoleKit_Restart(&err);
+ dbus_ConsoleKit_Reboot(&err);
else if (handler_context->reboot_systemd)
dbus_systemd_Reboot(&err);
@@ -276,6 +278,8 @@
lock_screen();
if (handler_context->suspend_UPower)
dbus_UPower_Suspend(&err);
+ else if (handler_context->suspend_ConsoleKit)
+ dbus_ConsoleKit_Suspend(&err);
else if (handler_context->suspend_systemd)
dbus_systemd_Suspend(&err);
@@ -299,6 +303,8 @@
lock_screen();
if (handler_context->hibernate_UPower)
dbus_UPower_Hibernate(&err);
+ else if (handler_context->hibernate_ConsoleKit)
+ dbus_ConsoleKit_Hibernate(&err);
else if (handler_context->hibernate_systemd)
dbus_systemd_Hibernate(&err);
@@ -515,16 +521,26 @@
}
/* Initialize capabilities of the ConsoleKit mechanism. */
- if (!handler_context.shutdown_available && dbus_ConsoleKit_CanStop())
+ if (!handler_context.shutdown_available && dbus_ConsoleKit_CanPowerOff())
{
handler_context.shutdown_available = TRUE;
handler_context.shutdown_ConsoleKit = TRUE;
}
- if (!handler_context.reboot_available && dbus_ConsoleKit_CanRestart())
+ if (!handler_context.reboot_available && dbus_ConsoleKit_CanReboot())
{
handler_context.reboot_available = TRUE;
handler_context.reboot_ConsoleKit = TRUE;
}
+ if (!handler_context.suspend_available && dbus_ConsoleKit_CanSuspend())
+ {
+ handler_context.suspend_available = TRUE;
+ handler_context.suspend_ConsoleKit = TRUE;
+ }
+ if (!handler_context.hibernate_available && dbus_ConsoleKit_CanHibernate())
+ {
+ handler_context.hibernate_available = TRUE;
+ handler_context.hibernate_ConsoleKit = TRUE;
+ }
/* Initialize capabilities of the UPower mechanism. */
if (!handler_context.suspend_available && dbus_UPower_CanSuspend())
diff -Naur lxsession-0.5.2-old/lxsession-logout/lxsession-logout-dbus-interface.c lxsession-0.5.2-new/lxsession-logout/lxsession-logout-dbus-interface.c
--- lxsession-0.5.2-old/lxsession-logout/lxsession-logout-dbus-interface.c 2014-11-29 15:43:14.000000000 +0100
+++ lxsession-0.5.2-new/lxsession-logout/lxsession-logout-dbus-interface.c 2016-04-09 19:25:46.704012439 +0200
@@ -93,10 +93,11 @@
/*** ConsoleKit mechanism ***/
static gboolean
-ck_call_function (const gchar *function, gboolean default_result, GError **error)
+ck_query (const gchar *function, gboolean default_result, GError **error)
{
GVariant *result;
gboolean function_result = FALSE;
+ const gchar *str;
if (!ck_proxy)
{
@@ -122,35 +123,95 @@
if (!result)
return default_result;
- if (g_variant_is_of_type (result, G_VARIANT_TYPE ("(b)")))
- g_variant_get (result, "(b)", &function_result);
+ if (g_variant_is_of_type (result, G_VARIANT_TYPE ("(s)")))
+ {
+ g_variant_get (result, "(s)", &str);
+ if ( g_strcmp0 (str, "yes") == 0 || g_strcmp0 (str, "challenge") == 0 )
+ function_result = TRUE;
+ else
+ function_result = default_result;
+ }
g_variant_unref (result);
return function_result;
}
+static void
+ck_call_function (const gchar *function, gboolean value, GError **error)
+{
+ GVariant *result;
+
+ if (!ck_proxy)
+ {
+ ck_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.ConsoleKit",
+ "/org/freedesktop/ConsoleKit",
+ "org.freedesktop.ConsoleKit.Manager",
+ NULL,
+ error);
+ if (!ck_proxy)
+ return;
+ }
+
+ result = g_dbus_proxy_call_sync (ck_proxy,
+ function,
+ g_variant_new ("(b)", value),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ error);
+ g_variant_unref (result);
+ return;
+}
+
gboolean
-dbus_ConsoleKit_CanRestart (void)
+dbus_ConsoleKit_CanPowerOff (void)
+{
+ return ck_query ("CanPowerOff", FALSE, NULL);
+}
+
+void
+dbus_ConsoleKit_PowerOff (GError **error)
{
- return ck_call_function ("CanRestart", FALSE, NULL);
+ ck_call_function ("PowerOff", TRUE, error);
}
gboolean
-dbus_ConsoleKit_Restart (GError **error)
+dbus_ConsoleKit_CanReboot (void)
{
- return ck_call_function ("Restart", TRUE, error);
+ return ck_query ("CanReboot", FALSE, NULL);
+}
+
+void
+dbus_ConsoleKit_Reboot (GError **error)
+{
+ ck_call_function ("Reboot", TRUE, error);
}
gboolean
-dbus_ConsoleKit_CanStop (void)
+dbus_ConsoleKit_CanSuspend (void)
{
- return ck_call_function ("CanStop", FALSE, NULL);
+ return ck_query ("CanSuspend", FALSE, NULL);
+}
+
+void
+dbus_ConsoleKit_Suspend (GError **error)
+{
+ ck_call_function ("Suspend", TRUE, error);
}
gboolean
-dbus_ConsoleKit_Stop (GError **error)
+dbus_ConsoleKit_CanHibernate (void)
+{
+ return ck_query ("CanHibernate", FALSE, NULL);
+}
+
+void
+dbus_ConsoleKit_Hibernate (GError **error)
{
- return ck_call_function ("Stop", TRUE, error);
+ ck_call_function ("Hibernate", TRUE, error);
}
/*** Systemd mechanism ***/
diff -Naur lxsession-0.5.2-old/lxsession-logout/lxsession-logout-dbus-interface.h lxsession-0.5.2-new/lxsession-logout/lxsession-logout-dbus-interface.h
--- lxsession-0.5.2-old/lxsession-logout/lxsession-logout-dbus-interface.h 2014-10-05 01:49:49.000000000 +0200
+++ lxsession-0.5.2-new/lxsession-logout/lxsession-logout-dbus-interface.h 2016-04-09 21:05:04.524058135 +0200
@@ -21,11 +21,15 @@
#include <glib.h>
-/* Interface to ConsoleKit for shutdown and reboot. */
-extern gboolean dbus_ConsoleKit_CanStop(void);
-extern gboolean dbus_ConsoleKit_CanRestart(void);
-extern gboolean dbus_ConsoleKit_Stop(GError **);
-extern gboolean dbus_ConsoleKit_Restart(GError **);
+/* Interface to ConsoleKit for suspend, hibernate, shutdown and reboot. */
+extern gboolean dbus_ConsoleKit_CanPowerOff(void);
+extern gboolean dbus_ConsoleKit_CanReboot(void);
+extern gboolean dbus_ConsoleKit_CanSuspend(void);
+extern gboolean dbus_ConsoleKit_CanHibernate(void);
+extern void dbus_ConsoleKit_PowerOff(GError **);
+extern void dbus_ConsoleKit_Reboot(GError **);
+extern void dbus_ConsoleKit_Suspend(GError **);
+extern void dbus_ConsoleKit_Hibernate(GError **);
/* Interface to UPower for suspend and hibernate. */
extern gboolean dbus_UPower_CanSuspend(void);
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial! http://pubads.g.doubleclick.net/
gampad/clk?id=1444514301&iu=/ca-pub-7940484522588532
_______________________________________________
Lxde-list mailing list
Lxde-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxde-list