From c863dc05881fd5afbc3c7ce700980354530cee8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 10 Apr 2018 11:39:14 +0200 Subject: [PATCH] shared/sleep-fix: fix check if s-then-h is possible can_sleep() returns 0 if the operation is impossible, but the code assumed that negative is returned in that case, in effect reporting s2h was possible even if hibernation or suspend were not possible. --- src/shared/sleep-config.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index 79cd90a744..03fd497f52 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -357,6 +357,7 @@ int read_fiemap(int fd, struct fiemap **ret) { } static bool can_s2h(void) { + const char *p; int r; r = access("/sys/class/rtc/rtc0/wakealarm", W_OK); @@ -366,16 +367,14 @@ static bool can_s2h(void) { return false; } - r = can_sleep("suspend"); - if (r < 0) { - log_debug_errno(r, "Unable to suspend system."); - return false; - } - - r = can_sleep("hibernate"); - if (r < 0) { - log_debug_errno(r, "Unable to hibernate system."); - return false; + FOREACH_STRING(p, "suspend", "hibernate") { + r = can_sleep(p); + if (r < 0) + return log_debug_errno(r, "Failed to check if %s is possible: %m", p); + if (r == 0) { + log_debug("Unable to %s system.", p); + return false; + } } return true;