X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fsleep%2Fsleep.c;h=218de3a5675711ab32b1d38e9930ed6d9e60cf32;hp=c86f69c4aa379761923f45959466f0681afcbe00;hb=6524990fdc98370ecba5d9f73e67161e8798c010;hpb=ddcbc8737873ca1904562d7d3ca3de9946e2f889 diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index c86f69c4a..218de3a56 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -25,6 +25,8 @@ #include "log.h" #include "util.h" +#include "systemd/sd-id128.h" +#include "systemd/sd-messages.h" int main(int argc, char *argv[]) { const char *verb; @@ -44,7 +46,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]); @@ -52,6 +54,16 @@ int main(int argc, char *argv[]) { goto finish; } + /* Configure the hibernation mode */ + if (streq(argv[1], "hibernate")) { + if (write_one_line_file("/sys/power/disk", "platform") < 0) + write_one_line_file("/sys/power/disk", "shutdown"); + } else if (streq(argv[1], "hybrid-sleep")) { + if (write_one_line_file("/sys/power/disk", "suspend") < 0) + if (write_one_line_file("/sys/power/disk", "platform") < 0) + write_one_line_file("/sys/power/disk", "shutdown"); + } + f = fopen("/sys/power/state", "we"); if (!f) { log_error("Failed to open /sys/power/state: %m"); @@ -66,9 +78,23 @@ int main(int argc, char *argv[]) { execute_directory(SYSTEM_SLEEP_PATH, NULL, arguments); if (streq(argv[1], "suspend")) - log_info("Suspending system..."); + log_struct(LOG_INFO, + MESSAGE_ID(SD_MESSAGE_SLEEP_START), + "MESSAGE=Suspending system...", + "SLEEP=suspend", + NULL); + else if (streq(argv[1], "hibernate")) + log_struct(LOG_INFO, + MESSAGE_ID(SD_MESSAGE_SLEEP_START), + "MESSAGE=Hibernating system...", + "SLEEP=hibernate", + NULL); else - log_info("Hibernating system..."); + 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); @@ -77,9 +103,17 @@ int main(int argc, char *argv[]) { r = ferror(f) ? -errno : 0; if (streq(argv[1], "suspend")) - log_info("System resumed."); + log_struct(LOG_INFO, + MESSAGE_ID(SD_MESSAGE_SLEEP_STOP), + "MESSAGE=System resumed.", + "SLEEP=suspend", + NULL); else - log_info("System thawed."); + log_struct(LOG_INFO, + MESSAGE_ID(SD_MESSAGE_SLEEP_STOP), + "MESSAGE=System thawed.", + "SLEEP=hibernate", + NULL); arguments[1] = (char*) "post"; execute_directory(SYSTEM_SLEEP_PATH, NULL, arguments);