Skip to content

Commit f1f331a

Browse files
fbuihuubluca
authored andcommitted
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.
1 parent 8f766af commit f1f331a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/sleep/sleep.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,18 @@ static int execute(
262262
return log_error_errno(r, "Failed to find location to hibernate to: %m");
263263
resume_set = r > 0;
264264

265+
r = write_efi_hibernate_location(hibernate_location, !resume_set);
265266
if (!resume_set) {
267+
if (r == -EOPNOTSUPP)
268+
return log_error_errno(r, "No valid 'resume=' option found, refusing to hibernate.");
269+
if (r < 0)
270+
return r;
271+
266272
r = write_kernel_hibernate_location(hibernate_location);
267273
if (r < 0)
268274
return log_error_errno(r, "Failed to prepare for hibernation: %m");
269275
}
270276

271-
r = write_efi_hibernate_location(hibernate_location, !resume_set);
272-
if (r < 0 && !resume_set)
273-
return r;
274-
275277
r = write_mode(modes);
276278
if (r < 0)
277279
return log_error_errno(r, "Failed to write mode to /sys/power/disk: %m");

0 commit comments

Comments
 (0)