chiark / gitweb /
util: if /sys mounted read-only we can't suspend/hibernate
authorLennart Poettering <lennart@poettering.net>
Sun, 23 Dec 2012 20:58:37 +0000 (21:58 +0100)
committerLennart Poettering <lennart@poettering.net>
Sun, 23 Dec 2012 23:29:40 +0000 (00:29 +0100)
src/shared/util.c

index 59d8544d053b9eca14e917e5c51c45ad5bb76603..1779625c77916ccb10b1d8ceca99d3b40688acc9 100644 (file)
@@ -5282,9 +5282,13 @@ int can_sleep(const char *type) {
 
         assert(type);
 
+        /* If /sys is read-only we cannot sleep */
+        if (access("/sys/power/state", W_OK) < 0)
+                return false;
+
         r = read_one_line_file("/sys/power/state", &p);
         if (r < 0)
-                return r == -ENOENT ? 0 : r;
+                return false;
 
         k = strlen(type);
         FOREACH_WORD_SEPARATOR(w, l, p, WHITESPACE, state)
@@ -5302,9 +5306,14 @@ int can_sleep_disk(const char *type) {
 
         assert(type);
 
+        /* If /sys is read-only we cannot sleep */
+        if (access("/sys/power/state", W_OK) < 0 ||
+            access("/sys/power/disk", W_OK) < 0)
+                return false;
+
         r = read_one_line_file("/sys/power/disk", &p);
         if (r < 0)
-                return r == -ENOENT ? 0 : r;
+                return false;
 
         k = strlen(type);
         FOREACH_WORD_SEPARATOR(w, l, p, WHITESPACE, state) {