From: Lennart Poettering Date: Sun, 23 Dec 2012 21:12:01 +0000 (+0100) Subject: logind: don't allow suspending/hibernating if the kernel doesn't support it X-Git-Tag: v197~93 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=dc3a1b76a6a6f9dfe9b451f534587251b50a0685 logind: don't allow suspending/hibernating if the kernel doesn't support it --- diff --git a/src/login/logind-action.c b/src/login/logind-action.c index bd5664e90..e1517d6ac 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)) {