diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-12-23 22:12:01 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-12-24 00:29:40 +0100 |
commit | dc3a1b76a6a6f9dfe9b451f534587251b50a0685 (patch) | |
tree | 88b9761729deb9d3c69b57cbd035b1a5d3499091 /src/login/logind-action.c | |
parent | 679b7d791241eb52e15e4914e0d5709f67ff5123 (diff) |
logind: don't allow suspending/hibernating if the kernel doesn't support it
Diffstat (limited to 'src/login/logind-action.c')
-rw-r--r-- | src/login/logind-action.c | 17 |
1 files changed, 17 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. ***/ +#include <unistd.h> + #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)) { |