]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hibernate-resume: always respect user-defined timeout
authorMike Yuan <me@yhndnzj.com>
Sun, 8 Dec 2024 19:39:23 +0000 (20:39 +0100)
committerMike Yuan <me@yhndnzj.com>
Mon, 9 Dec 2024 18:24:59 +0000 (19:24 +0100)
Follow-up for 6cfce71b5034eb304eea82a31c400ff511cfa69e

Let's not override resumeflags=x-systemd.device-timeout=
specified by user, especially in the case of EFI if
the user actually wants to extend the timeout.

src/hibernate-resume/hibernate-resume-generator.c

index b6495a2581905c20d0f2943dd417989478f3fa43..666cd52e477545a4a4a2f98b2f5b944364e69b5c 100644 (file)
@@ -64,20 +64,21 @@ static int process_resume(const HibernateInfo *info) {
         if (r < 0)
                 return log_error_errno(r, "Failed to generate device unit name from path '%s': %m", info->device);
 
-        /* If hibernate info is acquired from EFI variable, don't wait forever by default. Otherwise, if
-         * swap device is not present and HibernateLocation was not correctly cleared, we end up blocking
-         * the boot process infinitely. */
-        r = write_drop_in_format(arg_dest, device_unit, 40, "device-timeout",
-                                 "# Automatically generated by systemd-hibernate-resume-generator\n\n"
-                                 "[Unit]\n"
-                                 "JobTimeoutSec=%s\n",
-                                 info->cmdline ? "infinity" : "2min");
-        if (r < 0)
-                log_warning_errno(r, "Failed to write device timeout drop-in, ignoring: %m");
-
         r = generator_write_device_timeout(arg_dest, info->device, arg_resume_options ?: arg_root_options, NULL);
         if (r < 0)
                 log_warning_errno(r, "Failed to write device timeout drop-in, ignoring: %m");
+        if (r <= 0) {
+                /* No timeout explicitly defined? Wait infinitely if resume= is specified, 2min if from EFI
+                 * HibernateLocation variable. In the latter case, we avoid blocking the boot process forever
+                 * if a stale var is detected while the swap device is not present. */
+                r = write_drop_in_format(arg_dest, device_unit, 40, "device-timeout",
+                                         "# Automatically generated by systemd-hibernate-resume-generator\n\n"
+                                         "[Unit]\n"
+                                         "JobTimeoutSec=%s\n",
+                                         info->cmdline ? "infinity" : "2min");
+                if (r < 0)
+                        log_warning_errno(r, "Failed to write fallback device timeout drop-in, ignoring: %m");
+        }
 
         r = write_drop_in_format(arg_dest, SPECIAL_HIBERNATE_RESUME_SERVICE, 90, "device-dependency",
                                  "# Automatically generated by systemd-hibernate-resume-generator\n\n"