diff options
author | Ben Hutchings <ben@decadent.org.uk> | 2018-07-19 20:09:28 +0100 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2019-01-20 00:22:24 +0000 |
commit | a2f9cd4abe2d5cb72e1e89089b132e866e3cea81 (patch) | |
tree | f6fb27e7c13259584e17b0016243f7e8dd3721fd | |
parent | 908fca5066fa8e8934df21cbde84b8eccab8a5c9 (diff) | |
download | klibc-a2f9cd4abe2d5cb72e1e89089b132e866e3cea81.tar.gz |
[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@decadent.org.uk>
-rw-r--r-- | usr/kinit/resume/resumelib.c | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/usr/kinit/resume/resumelib.c b/usr/kinit/resume/resumelib.c index e557b05c050b2a..03e596a47d04e6 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"); |