]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sleep: don't init /sys/power/resume if 'resume=' option is missing and EFI is disabled
authorFranck Bui <fbui@suse.com>
Wed, 26 Jul 2023 15:04:10 +0000 (17:04 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 27 Jul 2023 11:30:40 +0000 (12:30 +0100)
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

index 30e53f3a360490466e3f89f817a6a06fa99f2dec..de1f6c7ec1f7893084655f4bd858649e06eb47b3 100644 (file)
@@ -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");