From: Zbigniew Jędrzejewski-Szmek Date: Tue, 10 Apr 2018 09:39:14 +0000 (+0200) Subject: shared/sleep-fix: fix check if s-then-h is possible X-Git-Tag: v239~419^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c863dc05881fd5afbc3c7ce700980354530cee8e;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index 79cd90a7442..03fd497f527 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;