From f1f331a252d22c15f37d03524cce967664358c5c Mon Sep 17 00:00:00 2001 From: Franck Bui Date: Wed, 26 Jul 2023 17:04:10 +0200 Subject: [PATCH] sleep: don't init /sys/power/resume if 'resume=' option is missing and EFI is disabled Otherwise in such case a first `systemctl hibernate` would fail but would still initialize /sys/power/resume fooling a second `systemctl hibernate` into believing that 'resume=' is correctly set and can be used by the resume process to find the swap device to resume from. Follow-up for #27330. --- src/sleep/sleep.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 30e53f3a360..de1f6c7ec1f 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -262,16 +262,18 @@ static int execute( return log_error_errno(r, "Failed to find location to hibernate to: %m"); resume_set = r > 0; + r = write_efi_hibernate_location(hibernate_location, !resume_set); if (!resume_set) { + if (r == -EOPNOTSUPP) + return log_error_errno(r, "No valid 'resume=' option found, refusing to hibernate."); + if (r < 0) + return r; + r = write_kernel_hibernate_location(hibernate_location); if (r < 0) return log_error_errno(r, "Failed to prepare for hibernation: %m"); } - r = write_efi_hibernate_location(hibernate_location, !resume_set); - if (r < 0 && !resume_set) - return r; - r = write_mode(modes); if (r < 0) return log_error_errno(r, "Failed to write mode to /sys/power/disk: %m"); -- 2.47.3