klibc-bot for Ben Hutchings
2019-Jan-20 00:24 UTC
[klibc] [klibc:master] resume: Write resume_offset attribute
Commit-ID: a2f9cd4abe2d5cb72e1e89089b132e866e3cea81 Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=a2f9cd4abe2d5cb72e1e89089b132e866e3cea81 Author: Ben Hutchings <ben at decadent.org.uk> AuthorDate: Thu, 19 Jul 2018 20:09:28 +0100 Committer: Ben Hutchings <ben at decadent.org.uk> CommitDate: Sun, 20 Jan 2019 00:22:24 +0000 [klibc] resume: Write resume_offset attribute Support for a device offset as part of the string written to /sys/power/resume never got into a mainline kernel. However, since Linux 4.17 there is a separate resume_offset attribute that we can use to set the offset before attempting to resume. Change resume() to write the resume_offset attribute instead. Signed-off-by: Ben Hutchings <ben at decadent.org.uk> --- usr/kinit/resume/resumelib.c | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/usr/kinit/resume/resumelib.c b/usr/kinit/resume/resumelib.c index e557b05..03e596a 100644 --- a/usr/kinit/resume/resumelib.c +++ b/usr/kinit/resume/resumelib.c @@ -44,8 +44,8 @@ int do_resume(int argc, char *argv[]) int resume(const char *resume_file, unsigned long long resume_offset) { dev_t resume_device; - int powerfd = -1; - char device_string[64]; + int attr_fd = -1; + char attr_value[64]; int len; resume_device = name_to_dev_t(resume_file); @@ -55,30 +55,50 @@ int resume(const char *resume_file, unsigned long long resume_offset) goto failure; } - if ((powerfd = open("/sys/power/resume", O_WRONLY)) < 0) - goto fail_r; + if ((attr_fd = open("/sys/power/resume_offset", O_WRONLY)) < 0) + goto fail_offset; - len = snprintf(device_string, sizeof device_string, - "%u:%u:%llu", - major(resume_device), minor(resume_device), + len = snprintf(attr_value, sizeof attr_value, + "%llu", resume_offset); /* This should never happen */ - if (len >= sizeof device_string) + if (len >= sizeof attr_value) + goto fail_offset; + + if (write(attr_fd, attr_value, len) != len) + goto fail_offset; + + close(attr_fd); + + if ((attr_fd = open("/sys/power/resume", O_WRONLY)) < 0) + goto fail_r; + + len = snprintf(attr_value, sizeof attr_value, + "%u:%u", + major(resume_device), minor(resume_device)); + + /* This should never happen */ + if (len >= sizeof attr_value) goto fail_r; dprintf("kinit: trying to resume from %s\n", resume_file); - if (write(powerfd, device_string, len) != len) + if (write(attr_fd, attr_value, len) != len) goto fail_r; /* Okay, what are we still doing alive... */ failure: - if (powerfd >= 0) - close(powerfd); + if (attr_fd >= 0) + close(attr_fd); dprintf("kinit: No resume image, doing normal boot...\n"); return -1; +fail_offset: + fprintf(stderr, "Cannot write /sys/power/resume_offset " + "(no software suspend kernel support, or old kernel version?)\n"); + goto failure; + fail_r: fprintf(stderr, "Cannot write /sys/power/resume " "(no software suspend kernel support?)\n");