summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-12-23 21:58:37 +0100
committerLennart Poettering <lennart@poettering.net>2012-12-24 00:29:40 +0100
commit679b7d791241eb52e15e4914e0d5709f67ff5123 (patch)
tree08b7e7b33146761127cb59de8f85accdc22b86e4 /src/shared/util.c
parent11dc5d2b649afaf9f4470ad97929ebe844604f44 (diff)
util: if /sys mounted read-only we can't suspend/hibernate
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 59d8544d05..1779625c77 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -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) {