From dc3a1b76a6a6f9dfe9b451f534587251b50a0685 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 23 Dec 2012 22:12:01 +0100 Subject: logind: don't allow suspending/hibernating if the kernel doesn't support it --- src/login/logind-action.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/login/logind-action.c b/src/login/logind-action.c index bd5664e905..e1517d6ac2 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -19,6 +19,8 @@ along with systemd; If not, see . ***/ +#include + #include "conf-parser.h" #include "special.h" #include "dbus-common.h" @@ -54,6 +56,7 @@ int manager_handle_action( DBusError error; int r; InhibitWhat inhibit_operation; + bool supported = true; assert(m); @@ -63,6 +66,20 @@ int manager_handle_action( return 0; } + if (handle == HANDLE_SUSPEND) + supported = can_sleep("mem") > 0; + else if (handle == HANDLE_HIBERNATE) + supported = can_sleep("disk") > 0; + else if (handle == HANDLE_HYBRID_SLEEP) + supported = can_sleep("disk") > 0 && can_sleep_disk("suspend") > 0; + else if (handle == HANDLE_KEXEC) + supported = access("/sbin/kexec", X_OK) >= 0; + + if (!supported) { + log_warning("Requested operation not supported, ignoring."); + return -ENOTSUP; + } + /* If the key handling is inhibited, don't do anything */ if (inhibit_key > 0) { if (manager_is_inhibited(m, inhibit_key, INHIBIT_BLOCK, NULL, true, false, 0)) { -- cgit v1.2.3-54-g00ecf