summaryrefslogtreecommitdiff
path: root/src/login
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-10-28 00:49:04 +0200
committerLennart Poettering <lennart@poettering.net>2012-10-28 00:50:35 +0200
commit6524990fdc98370ecba5d9f73e67161e8798c010 (patch)
tree870ed57ed3c756dd34a0223692d1ec5b9e5ef44d /src/login
parent2001208c2ab631a69896d1f670c26846b70d1fb7 (diff)
logind: support for hybrid sleep (i.e. suspend+hibernate at the same time)
Diffstat (limited to 'src/login')
-rw-r--r--src/login/logind-button.c21
-rw-r--r--src/login/logind-button.h1
-rw-r--r--src/login/logind-dbus.c69
3 files changed, 74 insertions, 17 deletions
diff --git a/src/login/logind-button.c b/src/login/logind-button.c
index 8fdab789bc..753d95454c 100644
--- a/src/login/logind-button.c
+++ b/src/login/logind-button.c
@@ -163,16 +163,18 @@ static int button_handle(
[HANDLE_HALT] = "Halting...",
[HANDLE_KEXEC] = "Rebooting via kexec...",
[HANDLE_SUSPEND] = "Suspending...",
- [HANDLE_HIBERNATE] = "Hibernating..."
+ [HANDLE_HIBERNATE] = "Hibernating...",
+ [HANDLE_HYBRID_SLEEP] = "Hibernating and suspend...",
};
static const char * const target_table[_HANDLE_BUTTON_MAX] = {
- [HANDLE_POWEROFF] = "poweroff.target",
- [HANDLE_REBOOT] = "reboot.target",
- [HANDLE_HALT] = "halt.target",
- [HANDLE_KEXEC] = "kexec.target",
- [HANDLE_SUSPEND] = "suspend.target",
- [HANDLE_HIBERNATE] = "hibernate.target"
+ [HANDLE_POWEROFF] = SPECIAL_POWEROFF_TARGET,
+ [HANDLE_REBOOT] = SPECIAL_REBOOT_TARGET,
+ [HANDLE_HALT] = SPECIAL_HALT_TARGET,
+ [HANDLE_KEXEC] = SPECIAL_KEXEC_TARGET,
+ [HANDLE_SUSPEND] = SPECIAL_SUSPEND_TARGET,
+ [HANDLE_HIBERNATE] = SPECIAL_HIBERNATE_TARGET,
+ [HANDLE_HYBRID_SLEEP] = SPECIAL_HYBRID_SLEEP_TARGET
};
DBusError error;
@@ -193,7 +195,7 @@ static int button_handle(
return 0;
}
- inhibit_operation = handle == HANDLE_SUSPEND || handle == HANDLE_HIBERNATE ? INHIBIT_SLEEP : INHIBIT_SHUTDOWN;
+ inhibit_operation = handle == HANDLE_SUSPEND || handle == HANDLE_HIBERNATE || handle == HANDLE_HYBRID_SLEEP ? INHIBIT_SLEEP : INHIBIT_SHUTDOWN;
/* If the actual operation is inhibited, warn and fail */
if (!ignore_inhibited &&
@@ -305,7 +307,8 @@ static const char* const handle_button_table[_HANDLE_BUTTON_MAX] = {
[HANDLE_HALT] = "halt",
[HANDLE_KEXEC] = "kexec",
[HANDLE_SUSPEND] = "suspend",
- [HANDLE_HIBERNATE] = "hibernate"
+ [HANDLE_HIBERNATE] = "hibernate",
+ [HANDLE_HYBRID_SLEEP] = "hybrid-sleep",
};
DEFINE_STRING_TABLE_LOOKUP(handle_button, HandleButton);
DEFINE_CONFIG_PARSE_ENUM(config_parse_handle_button, handle_button, HandleButton, "Failed to parse handle button setting");
diff --git a/src/login/logind-button.h b/src/login/logind-button.h
index ca820ed7e5..827a03e460 100644
--- a/src/login/logind-button.h
+++ b/src/login/logind-button.h
@@ -32,6 +32,7 @@ typedef enum HandleButton {
HANDLE_KEXEC,
HANDLE_SUSPEND,
HANDLE_HIBERNATE,
+ HANDLE_HYBRID_SLEEP,
_HANDLE_BUTTON_MAX,
_HANDLE_BUTTON_INVALID = -1
} HandleButton;
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index a7647e3c80..3bcb91bf13 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -145,6 +145,9 @@
" <method name=\"Hibernate\">\n" \
" <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
" </method>\n" \
+ " <method name=\"HybridSleep\">\n" \
+ " <arg name=\"interactive\" type=\"b\" direction=\"in\"/>\n" \
+ " </method>\n" \
" <method name=\"CanPowerOff\">\n" \
" <arg name=\"result\" type=\"s\" direction=\"out\"/>\n" \
" </method>\n" \
@@ -157,6 +160,9 @@
" <method name=\"CanHibernate\">\n" \
" <arg name=\"result\" type=\"s\" direction=\"out\"/>\n" \
" </method>\n" \
+ " <method name=\"CanHybridSleep\">\n" \
+ " <arg name=\"result\" type=\"s\" direction=\"out\"/>\n" \
+ " </method>\n" \
" <method name=\"Inhibit\">\n" \
" <arg name=\"what\" type=\"s\" direction=\"in\"/>\n" \
" <arg name=\"who\" type=\"s\" direction=\"in\"/>\n" \
@@ -1054,6 +1060,7 @@ static int bus_manager_can_shutdown_or_sleep(
const char *action_multiple_sessions,
const char *action_ignore_inhibit,
const char *sleep_type,
+ const char *sleep_disk_type,
DBusError *error,
DBusMessage **_reply) {
@@ -1085,6 +1092,17 @@ static int bus_manager_can_shutdown_or_sleep(
}
}
+ if (sleep_disk_type) {
+ r = can_sleep_disk(sleep_disk_type);
+ if (r < 0)
+ return r;
+
+ if (r == 0) {
+ result = "na";
+ goto finish;
+ }
+ }
+
ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), error);
if (ul == (unsigned long) -1)
return -EIO;
@@ -1234,6 +1252,7 @@ static int bus_manager_do_shutdown_or_sleep(
const char *action_multiple_sessions,
const char *action_ignore_inhibit,
const char *sleep_type,
+ const char *sleep_disk_type,
DBusError *error,
DBusMessage **_reply) {
@@ -1271,6 +1290,15 @@ static int bus_manager_do_shutdown_or_sleep(
return -ENOTSUP;
}
+ if (sleep_disk_type) {
+ r = can_sleep_disk(sleep_disk_type);
+ if (r < 0)
+ return r;
+
+ if (r == 0)
+ return -ENOTSUP;
+ }
+
ul = dbus_bus_get_unix_user(connection, dbus_message_get_sender(message), error);
if (ul == (unsigned long) -1)
return -EIO;
@@ -2065,7 +2093,7 @@ static DBusHandlerResult manager_message_handler(
"org.freedesktop.login1.power-off",
"org.freedesktop.login1.power-off-multiple-sessions",
"org.freedesktop.login1.power-off-ignore-inhibit",
- NULL,
+ NULL, NULL,
&error, &reply);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
@@ -2077,7 +2105,7 @@ static DBusHandlerResult manager_message_handler(
"org.freedesktop.login1.reboot",
"org.freedesktop.login1.reboot-multiple-sessions",
"org.freedesktop.login1.reboot-ignore-inhibit",
- NULL,
+ NULL, NULL,
&error, &reply);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
@@ -2090,7 +2118,7 @@ static DBusHandlerResult manager_message_handler(
"org.freedesktop.login1.suspend",
"org.freedesktop.login1.suspend-multiple-sessions",
"org.freedesktop.login1.suspend-ignore-inhibit",
- "mem",
+ "mem", NULL,
&error, &reply);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
@@ -2102,7 +2130,20 @@ static DBusHandlerResult manager_message_handler(
"org.freedesktop.login1.hibernate",
"org.freedesktop.login1.hibernate-multiple-sessions",
"org.freedesktop.login1.hibernate-ignore-inhibit",
- "disk",
+ "disk", NULL,
+ &error, &reply);
+ if (r < 0)
+ return bus_send_error_reply(connection, message, &error, r);
+
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "HybridSleep")) {
+ r = bus_manager_do_shutdown_or_sleep(
+ m, connection, message,
+ SPECIAL_HYBRID_SLEEP_TARGET,
+ INHIBIT_SLEEP,
+ "org.freedesktop.login1.hibernate",
+ "org.freedesktop.login1.hibernate-multiple-sessions",
+ "org.freedesktop.login1.hibernate-ignore-inhibit",
+ "disk", "suspend",
&error, &reply);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
@@ -2115,7 +2156,7 @@ static DBusHandlerResult manager_message_handler(
"org.freedesktop.login1.power-off",
"org.freedesktop.login1.power-off-multiple-sessions",
"org.freedesktop.login1.power-off-ignore-inhibit",
- NULL,
+ NULL, NULL,
&error, &reply);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
@@ -2126,7 +2167,7 @@ static DBusHandlerResult manager_message_handler(
"org.freedesktop.login1.reboot",
"org.freedesktop.login1.reboot-multiple-sessions",
"org.freedesktop.login1.reboot-ignore-inhibit",
- NULL,
+ NULL, NULL,
&error, &reply);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
@@ -2138,7 +2179,7 @@ static DBusHandlerResult manager_message_handler(
"org.freedesktop.login1.suspend",
"org.freedesktop.login1.suspend-multiple-sessions",
"org.freedesktop.login1.suspend-ignore-inhibit",
- "mem",
+ "mem", NULL,
&error, &reply);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
@@ -2150,7 +2191,19 @@ static DBusHandlerResult manager_message_handler(
"org.freedesktop.login1.hibernate",
"org.freedesktop.login1.hibernate-multiple-sessions",
"org.freedesktop.login1.hibernate-ignore-inhibit",
- "disk",
+ "disk", NULL,
+ &error, &reply);
+ if (r < 0)
+ return bus_send_error_reply(connection, message, &error, r);
+
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "CanHybridSleep")) {
+ r = bus_manager_can_shutdown_or_sleep(
+ m, connection, message,
+ INHIBIT_SLEEP,
+ "org.freedesktop.login1.hibernate",
+ "org.freedesktop.login1.hibernate-multiple-sessions",
+ "org.freedesktop.login1.hibernate-ignore-inhibit",
+ "disk", "suspend",
&error, &reply);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);