diff options
author | Zach Smith <z@zxmth.us> | 2019-12-06 16:37:22 -0800 |
---|---|---|
committer | Zach Smith <z@zxmth.us> | 2020-01-05 20:15:38 -0800 |
commit | 52133271a7b3d76bed6d957f75371030193f5282 (patch) | |
tree | db9af7ffac021282156166fbd8f7f457e03c05fe /src/sleep | |
parent | 65ca546f0697f7a17bd435abd0d77bec26dbf28e (diff) | |
download | systemd-52133271a7b3d76bed6d957f75371030193f5282.tar.gz |
systemd-sleep: always attempt hibernation if configured
When calculation of swap file offset is unsupported, rely on the
/sys/power/resume & /sys/power/resume_offset values if configured
rather than requiring a matching swap entry to be identified.
Refactor to use dev_t for comparison of resume= device instead of string.
Diffstat (limited to 'src/sleep')
-rw-r--r-- | src/sleep/sleep.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 89b80367f8..cfd254ad55 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -39,18 +39,19 @@ STATIC_DESTRUCTOR_REGISTER(arg_verb, freep); static int write_hibernate_location_info(const HibernateLocation *hibernate_location) { char offset_str[DECIMAL_STR_MAX(uint64_t)]; + char resume_str[DECIMAL_STR_MAX(unsigned) * 2 + STRLEN(":")]; int r; assert(hibernate_location); assert(hibernate_location->swap); - assert(hibernate_location->resume); - r = write_string_file("/sys/power/resume", hibernate_location->resume, WRITE_STRING_FILE_DISABLE_BUFFER); + xsprintf(resume_str, "%u:%u", major(hibernate_location->devno), minor(hibernate_location->devno)); + r = write_string_file("/sys/power/resume", resume_str, WRITE_STRING_FILE_DISABLE_BUFFER); if (r < 0) return log_debug_errno(r, "Failed to write partition device to /sys/power/resume for '%s': '%s': %m", - hibernate_location->swap->device, hibernate_location->resume); + hibernate_location->swap->device, resume_str); - log_debug("Wrote resume= value for %s to /sys/power/resume: %s", hibernate_location->swap->device, hibernate_location->resume); + log_debug("Wrote resume= value for %s to /sys/power/resume: %s", hibernate_location->swap->device, resume_str); /* if it's a swap partition, we're done */ if (streq(hibernate_location->swap->type, "partition")) @@ -61,17 +62,17 @@ static int write_hibernate_location_info(const HibernateLocation *hibernate_loca "Invalid hibernate type: %s", hibernate_location->swap->type); /* Only available in 4.17+ */ - if (hibernate_location->resume_offset > 0 && access("/sys/power/resume_offset", W_OK) < 0) { + if (hibernate_location->offset > 0 && access("/sys/power/resume_offset", W_OK) < 0) { if (errno == ENOENT) { log_debug("Kernel too old, can't configure resume_offset for %s, ignoring: %" PRIu64, - hibernate_location->swap->device, hibernate_location->resume_offset); + hibernate_location->swap->device, hibernate_location->offset); return 0; } return log_debug_errno(errno, "/sys/power/resume_offset not writeable: %m"); } - xsprintf(offset_str, "%" PRIu64, hibernate_location->resume_offset); + xsprintf(offset_str, "%" PRIu64, hibernate_location->offset); r = write_string_file("/sys/power/resume_offset", offset_str, WRITE_STRING_FILE_DISABLE_BUFFER); if (r < 0) return log_debug_errno(r, "Failed to write swap file offset to /sys/power/resume_offset for '%s': '%s': %m", |