1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-06 08:26:52 +03:00

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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-04-10 11:39:14 +02:00
parent 6524f1a8eb
commit c863dc0588

View File

@ -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.");
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;
}
r = can_sleep("hibernate");
if (r < 0) {
log_debug_errno(r, "Unable to hibernate system.");
return false;
}
return true;