chiark / gitweb /
shared/sleep-fix: fix check if s-then-h is possible
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 10 Apr 2018 09:39:14 +0000 (11:39 +0200)
committerSven Eden <yamakuzure@gmx.net>
Fri, 24 Aug 2018 14:47:08 +0000 (16:47 +0200)
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

index 15cd439c2a5eb205cf8b063245f1b5b5255d48bf..210e753c4f56f2a09d3f76e73960ed7279a21908 100644 (file)
@@ -368,6 +368,7 @@ int read_fiemap(int fd, struct fiemap **ret) {
 
 #if 0 /// elogind has to do, or better, *can* do it differently
 static bool can_s2h(void) {
+        const char *p;
         int r;
 
         r = access("/sys/class/rtc/rtc0/wakealarm", W_OK);
@@ -377,16 +378,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;