summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2017-01-12 15:08:10 +1300
committerRobert Ancell <robert.ancell@canonical.com>2017-01-12 15:08:10 +1300
commit4e44053a34461520bc240ce73e87144a8822bd9f (patch)
tree2bd59b4f1d2311a4193f76c08cfa9476330eb749
parenta430eeeaa7fc67ce7548d4e05d797c4f53971974 (diff)
downloadlightdm-git-4e44053a34461520bc240ce73e87144a8822bd9f.tar.gz
Use power management functions from ConsoleKit2 if available.
Suspend and hibernate functionality was removed from upower 0.99.0, so systems not using systemd had now suspend/hibernate functionality. Support for this was added into ConsoleKit2. Most systems will either be systemd or ConsoleKit2 now, so we try the following: 1. Power management in logind 2. Power management in ConsoleKit 3. upower for suspend/resume (really only here to not break backwards compatibility) Based on a patch for Gentoo by Fitzcarraldo.
-rw-r--r--liblightdm-gobject/power.c102
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/scripts/power-no-login1-or-console-kit.conf65
-rw-r--r--tests/scripts/power-no-login1.conf8
-rw-r--r--tests/src/test-runner.c32
-rwxr-xr-xtests/test-power-no-login1-or-console-kit2
6 files changed, 169 insertions, 42 deletions
diff --git a/liblightdm-gobject/power.c b/liblightdm-gobject/power.c
index 9b2dc172..50ff5e82 100644
--- a/liblightdm-gobject/power.c
+++ b/liblightdm-gobject/power.c
@@ -75,6 +75,36 @@ login1_call_function (const gchar *function, GVariant *parameters, GError **erro
return r;
}
+static GVariant *
+ck_call_function (const gchar *function, GVariant *parameters, GError **error)
+{
+ GVariant *r;
+
+ 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/Manager",
+ "org.freedesktop.ConsoleKit.Manager",
+ NULL,
+ error);
+ if (!ck_proxy)
+ return FALSE;
+ }
+
+ r = g_dbus_proxy_call_sync (ck_proxy,
+ function,
+ parameters,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ error);
+
+ return r;
+}
+
/**
* lightdm_get_can_suspend:
*
@@ -98,7 +128,13 @@ lightdm_get_can_suspend (void)
can_suspend = g_strcmp0 (result, "yes") == 0;
}
}
- else
+ if (!r)
+ {
+ r = ck_call_function ("CanSuspend", NULL, NULL);
+ if (r && g_variant_is_of_type (r, G_VARIANT_TYPE ("(b)")))
+ g_variant_get (r, "(b)", &can_suspend);
+ }
+ if (!r)
{
r = upower_call_function ("SuspendAllowed", NULL);
if (r && g_variant_is_of_type (r, G_VARIANT_TYPE ("(b)")))
@@ -128,7 +164,14 @@ lightdm_suspend (GError **error)
if (!result)
{
if (error)
- g_debug ("Can't suspend using logind; falling back to UPower: %s", (*error)->message);
+ g_debug ("Can't suspend using logind; falling back to ConsoleKit: %s", (*error)->message);
+ g_clear_error (error);
+ result = ck_call_function ("Suspend", g_variant_new ("(b)", FALSE), error);
+ }
+ if (!result)
+ {
+ if (error)
+ g_debug ("Can't suspend using logind or ConsoleKit; falling back to UPower: %s", (*error)->message);
g_clear_error (error);
result = upower_call_function ("Suspend", error);
}
@@ -163,7 +206,13 @@ lightdm_get_can_hibernate (void)
can_hibernate = g_strcmp0 (result, "yes") == 0;
}
}
- else
+ if (!r)
+ {
+ r = ck_call_function ("CanHibernate", NULL, NULL);
+ if (r && g_variant_is_of_type (r, G_VARIANT_TYPE ("(b)")))
+ g_variant_get (r, "(b)", &can_hibernate);
+ }
+ if (!r)
{
r = upower_call_function ("HibernateAllowed", NULL);
if (r && g_variant_is_of_type (r, G_VARIANT_TYPE ("(b)")))
@@ -193,7 +242,14 @@ lightdm_hibernate (GError **error)
if (!result)
{
if (error)
- g_debug ("Can't hibernate using logind; falling back to UPower: %s", (*error)->message);
+ g_debug ("Can't hibernate using logind; falling back to ConsoleKit: %s", (*error)->message);
+ g_clear_error (error);
+ result = ck_call_function ("Hibernate", g_variant_new ("(b)", FALSE), error);
+ }
+ if (!result)
+ {
+ if (error)
+ g_debug ("Can't hibernate using logind or ConsoleKit; falling back to UPower: %s", (*error)->message);
g_clear_error (error);
result = upower_call_function ("Hibernate", error);
}
@@ -205,36 +261,6 @@ lightdm_hibernate (GError **error)
return hibernated;
}
-static GVariant *
-ck_call_function (const gchar *function, GError **error)
-{
- GVariant *r;
-
- 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/Manager",
- "org.freedesktop.ConsoleKit.Manager",
- NULL,
- error);
- if (!ck_proxy)
- return FALSE;
- }
-
- r = g_dbus_proxy_call_sync (ck_proxy,
- function,
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- error);
-
- return r;
-}
-
/**
* lightdm_get_can_restart:
*
@@ -260,7 +286,7 @@ lightdm_get_can_restart (void)
}
else
{
- r = ck_call_function ("CanRestart", NULL);
+ r = ck_call_function ("CanRestart", NULL, NULL);
if (r && g_variant_is_of_type (r, G_VARIANT_TYPE ("(b)")))
g_variant_get (r, "(b)", &can_restart);
}
@@ -288,7 +314,7 @@ lightdm_restart (GError **error)
if (!r)
{
g_clear_error (error);
- r = ck_call_function ("Restart", error);
+ r = ck_call_function ("Restart", NULL, error);
}
restarted = r != NULL;
if (r)
@@ -322,7 +348,7 @@ lightdm_get_can_shutdown (void)
}
else
{
- r = ck_call_function ("CanStop", NULL);
+ r = ck_call_function ("CanStop", NULL, NULL);
if (r && g_variant_is_of_type (r, G_VARIANT_TYPE ("(b)")))
g_variant_get (r, "(b)", &can_shutdown);
}
@@ -350,7 +376,7 @@ lightdm_shutdown (GError **error)
if (!r)
{
g_clear_error (error);
- r = ck_call_function ("Stop", error);
+ r = ck_call_function ("Stop", NULL, error);
}
shutdown = r != NULL;
if (r)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3973c94f..287b7dba 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -219,6 +219,7 @@ TESTS = \
test-power-gobject \
test-power-no-console-kit \
test-power-no-login1 \
+ test-power-no-login1-or-console-kit \
test-power-no-services \
test-open-file-descriptors \
test-xdmcp-server-open-file-descriptors \
@@ -531,6 +532,7 @@ EXTRA_DIST = \
scripts/power-no-console-kit.conf \
scripts/power-no-services.conf \
scripts/power-no-login1.conf \
+ scripts/power-no-login1-or-console-kit.conf \
scripts/plymouth-active-vt.conf \
scripts/plymouth-inactive-vt.conf \
scripts/plymouth-no-seat.conf \
diff --git a/tests/scripts/power-no-login1-or-console-kit.conf b/tests/scripts/power-no-login1-or-console-kit.conf
new file mode 100644
index 00000000..d7077a2d
--- /dev/null
+++ b/tests/scripts/power-no-login1-or-console-kit.conf
@@ -0,0 +1,65 @@
+#
+# Check can do power operations from the greeter when no login1 or ConsoleKit service (falls back to upower for some)
+#
+
+[test-runner-config]
+disable-login1=true
+disable-console-kit=true
+
+#?*START-DAEMON
+#?RUNNER DAEMON-START
+
+# X server starts
+#?XSERVER-0 START VT=7 SEAT=seat0
+
+# Daemon connects when X server is ready
+#?*XSERVER-0 INDICATE-READY
+#?XSERVER-0 INDICATE-READY
+#?XSERVER-0 ACCEPT-CONNECT
+
+# Greeter starts
+#?GREETER-X-0 START XDG_SEAT=seat0 XDG_VTNR=7 XDG_SESSION_CLASS=greeter
+#?XSERVER-0 ACCEPT-CONNECT
+#?GREETER-X-0 CONNECT-XSERVER
+#?GREETER-X-0 CONNECT-TO-DAEMON
+#?GREETER-X-0 CONNECTED-TO-DAEMON
+
+# See if can suspend
+#?*GREETER-X-0 GET-CAN-SUSPEND
+#?UPOWER SUSPEND-ALLOWED
+#?GREETER-X-0 CAN-SUSPEND ALLOWED=TRUE
+
+# Suspend
+#?*GREETER-X-0 SUSPEND
+#?UPOWER SUSPEND
+
+# See if can hibernate
+#?*GREETER-X-0 GET-CAN-HIBERNATE
+#?UPOWER HIBERNATE-ALLOWED
+#?GREETER-X-0 CAN-HIBERNATE ALLOWED=TRUE
+
+# Hibernate
+#?*GREETER-X-0 HIBERNATE
+#?UPOWER HIBERNATE
+
+# See if can restart
+#?*GREETER-X-0 GET-CAN-RESTART
+#?GREETER-X-0 CAN-RESTART ALLOWED=FALSE
+
+# Restart
+#?*GREETER-X-0 RESTART
+#?GREETER-X-0 FAIL-RESTART
+
+# See if can shutdown
+#?*GREETER-X-0 GET-CAN-SHUTDOWN
+#?GREETER-X-0 CAN-SHUTDOWN ALLOWED=FALSE
+
+# Shutdown
+#?*GREETER-X-0 SHUTDOWN
+#?GREETER-X-0 FAIL-SHUTDOWN
+
+# Cleanup
+#?*STOP-DAEMON
+#?GREETER-X-0 TERMINATE SIGNAL=15
+#?XSERVER-0 TERMINATE SIGNAL=15
+#?RUNNER DAEMON-EXIT STATUS=0
diff --git a/tests/scripts/power-no-login1.conf b/tests/scripts/power-no-login1.conf
index 79df9b4c..ed9d2e21 100644
--- a/tests/scripts/power-no-login1.conf
+++ b/tests/scripts/power-no-login1.conf
@@ -26,21 +26,21 @@ disable-login1=true
# See if can suspend
#?*GREETER-X-0 GET-CAN-SUSPEND
-#?UPOWER SUSPEND-ALLOWED
+#?CONSOLE-KIT CAN-SUSPEND
#?GREETER-X-0 CAN-SUSPEND ALLOWED=TRUE
# Suspend
#?*GREETER-X-0 SUSPEND
-#?UPOWER SUSPEND
+#?CONSOLE-KIT SUSPEND
# See if can hibernate
#?*GREETER-X-0 GET-CAN-HIBERNATE
-#?UPOWER HIBERNATE-ALLOWED
+#?CONSOLE-KIT CAN-HIBERNATE
#?GREETER-X-0 CAN-HIBERNATE ALLOWED=TRUE
# Hibernate
#?*GREETER-X-0 HIBERNATE
-#?UPOWER HIBERNATE
+#?CONSOLE-KIT HIBERNATE
# See if can restart
#?*GREETER-X-0 GET-CAN-RESTART
diff --git a/tests/src/test-runner.c b/tests/src/test-runner.c
index 1cc6962b..71e367ac 100644
--- a/tests/src/test-runner.c
+++ b/tests/src/test-runner.c
@@ -1336,6 +1336,16 @@ handle_ck_call (GDBusConnection *connection,
check_status ("CONSOLE-KIT CAN-STOP");
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
}
+ else if (strcmp (method_name, "CanSuspend") == 0)
+ {
+ check_status ("CONSOLE-KIT CAN-SUSPEND");
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
+ }
+ else if (strcmp (method_name, "CanHibernate") == 0)
+ {
+ check_status ("CONSOLE-KIT CAN-HIBERNATE");
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
+ }
else if (strcmp (method_name, "CloseSession") == 0)
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
else if (strcmp (method_name, "OpenSession") == 0)
@@ -1379,6 +1389,16 @@ handle_ck_call (GDBusConnection *connection,
check_status ("CONSOLE-KIT STOP");
g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
}
+ else if (strcmp (method_name, "Suspend") == 0)
+ {
+ check_status ("CONSOLE-KIT SUSPEND");
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
+ }
+ else if (strcmp (method_name, "Hibernate") == 0)
+ {
+ check_status ("CONSOLE-KIT HIBERNATE");
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
+ }
else
g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such method: %s", method_name);
}
@@ -1439,6 +1459,12 @@ ck_name_acquired_cb (GDBusConnection *connection,
" <method name='CanStop'>"
" <arg name='can_stop' direction='out' type='b'/>"
" </method>"
+ " <method name='CanSuspend'>"
+ " <arg name='can_suspend' direction='out' type='b'/>"
+ " </method>"
+ " <method name='CanHibernate'>"
+ " <arg name='can_hibernate' direction='out' type='b'/>"
+ " </method>"
" <method name='CloseSession'>"
" <arg name='cookie' direction='in' type='s'/>"
" <arg name='result' direction='out' type='b'/>"
@@ -1456,6 +1482,12 @@ ck_name_acquired_cb (GDBusConnection *connection,
" </method>"
" <method name='Restart'/>"
" <method name='Stop'/>"
+ " <method name='Suspend'>"
+ " <arg name='policykit_interactivity' direction='in' type='b'/>"
+ " </method>"
+ " <method name='Hibernate'>"
+ " <arg name='policykit_interactivity' direction='in' type='b'/>"
+ " </method>"
" <signal name='SeatAdded'>"
" <arg name='seat' type='o'/>"
" </signal>"
diff --git a/tests/test-power-no-login1-or-console-kit b/tests/test-power-no-login1-or-console-kit
new file mode 100755
index 00000000..e71f25cb
--- /dev/null
+++ b/tests/test-power-no-login1-or-console-kit
@@ -0,0 +1,2 @@
+#!/bin/sh
+./src/dbus-env ./src/test-runner power-no-login1-or-console-kit test-gobject-greeter