From 232efdc5bd60be72d279a18052655a38fbc7547f Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sat, 25 Nov 2023 15:07:17 +0800 Subject: [PATCH 1/3] hibernate-util: return 1 for hibernation_is_safe only when all checks pass The return value is currently not used, but let's correct this. --- src/shared/hibernate-util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/hibernate-util.c b/src/shared/hibernate-util.c index 3eb13d48f6..2ce3781cbf 100644 --- a/src/shared/hibernate-util.c +++ b/src/shared/hibernate-util.c @@ -446,7 +446,7 @@ int hibernation_is_safe(void) { "Not running on EFI and resume= is not set. Hibernation is not safe."); if (bypass_space_check) - return true; + return 0; r = get_proc_meminfo_active(&active); if (r < 0) From 1fe536aa37f7f3b2a4155f9c7d6c86abce56d130 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 4 Dec 2023 21:17:03 +0800 Subject: [PATCH 2/3] sleep: reduce the scope of hibernation_device --- src/sleep/sleep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 21af3e9e52..6ff012d447 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -218,7 +218,6 @@ static int execute( NULL }; - _cleanup_(hibernation_device_done) HibernationDevice hibernation_device = {}; _cleanup_close_ int state_fd = -EBADF; int r; @@ -238,6 +237,7 @@ static int execute( /* Configure hibernation settings if we are supposed to hibernate */ if (sleep_operation_is_hibernation(operation)) { + _cleanup_(hibernation_device_done) HibernationDevice hibernation_device = {}; bool resume_set; r = find_suitable_hibernation_device(&hibernation_device); From 24ab77c3cd72306f23edef11091feec100603cac Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 5 Dec 2023 16:37:36 +0800 Subject: [PATCH 3/3] hibernate-resume: always clear HibernateLocation if system info matches Follow-up for a628d933cc67cc8b183dc809ba1451aa5b2996e5 HibernateInfo.from_efi is not actually useful. info.efi is only set if the system identifier stored in EFI variable matches with that of the running system, and thus the variable should be cleared no matter whether resume= is set from kernel cmdline or not. --- src/hibernate-resume/hibernate-resume-config.c | 9 +++------ src/hibernate-resume/hibernate-resume-config.h | 1 - src/hibernate-resume/hibernate-resume.c | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/hibernate-resume/hibernate-resume-config.c b/src/hibernate-resume/hibernate-resume-config.c index fe4add2c19..e4be7ca245 100644 --- a/src/hibernate-resume/hibernate-resume-config.c +++ b/src/hibernate-resume/hibernate-resume-config.c @@ -204,13 +204,12 @@ void compare_hibernate_location_and_warn(const HibernateInfo *info) { int r; assert(info); - assert(info->from_efi || info->cmdline); - if (info->from_efi) - return; - if (!info->efi) + if (!info->cmdline || !info->efi) return; + assert(info->device == info->cmdline->device); + if (!path_equal(info->cmdline->device, info->efi->device)) { r = devnode_same(info->cmdline->device, info->efi->device); if (r < 0) @@ -256,11 +255,9 @@ int acquire_hibernate_info(HibernateInfo *ret) { if (i.cmdline) { i.device = i.cmdline->device; i.offset = i.cmdline->offset; - i.from_efi = false; } else if (i.efi) { i.device = i.efi->device; i.offset = i.efi->offset; - i.from_efi = true; } else return -ENODEV; diff --git a/src/hibernate-resume/hibernate-resume-config.h b/src/hibernate-resume/hibernate-resume-config.h index 364abf7912..365d9ccda5 100644 --- a/src/hibernate-resume/hibernate-resume-config.h +++ b/src/hibernate-resume/hibernate-resume-config.h @@ -27,7 +27,6 @@ typedef struct EFIHibernateLocation { typedef struct HibernateInfo { const char *device; uint64_t offset; /* in memory pages */ - bool from_efi; KernelHibernateLocation *cmdline; EFIHibernateLocation *efi; diff --git a/src/hibernate-resume/hibernate-resume.c b/src/hibernate-resume/hibernate-resume.c index 9d81332f26..175a0bda96 100644 --- a/src/hibernate-resume/hibernate-resume.c +++ b/src/hibernate-resume/hibernate-resume.c @@ -59,7 +59,7 @@ static int run(int argc, char *argv[]) { if (r <= 0) return r; - if (arg_info.from_efi) + if (arg_info.efi) clear_efi_hibernate_location(); }