X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fsleep%2Fsleep.c;h=f5e78c13c60a56947f92f09ed82f9b79ba9e861d;hb=2d76d14ea3682c1c144001449654eb0c6bbda08d;hp=2f312675c5df8c4b4e154b1d7a9242643826dbb6;hpb=1ca6783f5ea3755bd83e723f529c2eda512c7fed;p=elogind.git diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 2f312675c..f5e78c13c 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -27,6 +27,7 @@ #include "util.h" #include "systemd/sd-id128.h" #include "systemd/sd-messages.h" +#include "fileio.h" int main(int argc, char *argv[]) { const char *verb; @@ -46,7 +47,7 @@ int main(int argc, char *argv[]) { if (streq(argv[1], "suspend")) verb = "mem"; - else if (streq(argv[1], "hibernate")) + else if (streq(argv[1], "hibernate") || streq(argv[1], "hybrid-sleep")) verb = "disk"; else { log_error("Unknown action '%s'.", argv[1]); @@ -54,6 +55,16 @@ int main(int argc, char *argv[]) { goto finish; } + /* Configure the hibernation mode */ + if (streq(argv[1], "hibernate")) { + if (write_string_file("/sys/power/disk", "platform") < 0) + write_string_file("/sys/power/disk", "shutdown"); + } else if (streq(argv[1], "hybrid-sleep")) { + if (write_string_file("/sys/power/disk", "suspend") < 0) + if (write_string_file("/sys/power/disk", "platform") < 0) + write_string_file("/sys/power/disk", "shutdown"); + } + f = fopen("/sys/power/state", "we"); if (!f) { log_error("Failed to open /sys/power/state: %m"); @@ -73,12 +84,18 @@ int main(int argc, char *argv[]) { "MESSAGE=Suspending system...", "SLEEP=suspend", NULL); - else + else if (streq(argv[1], "hibernate")) log_struct(LOG_INFO, MESSAGE_ID(SD_MESSAGE_SLEEP_START), "MESSAGE=Hibernating system...", "SLEEP=hibernate", NULL); + else + log_struct(LOG_INFO, + MESSAGE_ID(SD_MESSAGE_SLEEP_START), + "MESSAGE=Hibernating and suspending system...", + "SLEEP=hybrid-sleep", + NULL); fputs(verb, f); fputc('\n', f);