From: Franck Bui Date: Wed, 26 Jul 2023 15:04:10 +0000 (+0200) Subject: sleep: don't init /sys/power/resume if 'resume=' option is missing and EFI is disabled X-Git-Tag: v254~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f1f331a252d22c15f37d03524cce967664358c5c;p=thirdparty%2Fsystemd.git 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. --- 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");