]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sleep: refuse hibernation if there's no possible way to resume
authorMike Yuan <me@yhndnzj.com>
Fri, 23 Jun 2023 21:49:21 +0000 (05:49 +0800)
committerLennart Poettering <lennart@poettering.net>
Mon, 26 Jun 2023 15:23:36 +0000 (17:23 +0200)
Follow-up for 90efe8a6d4c0035c6a01d42805be87d99fb12f9a
Closes #19819

src/sleep/sleep.c

index 7fe99a37a44f1d6075b4c6c6661b0aaf10e71b82..dd860d28584f70d0ddaa333c1502a0f2baa399a7 100644 (file)
@@ -53,7 +53,8 @@
 static SleepOperation arg_operation = _SLEEP_OPERATION_INVALID;
 
 static int write_efi_hibernate_location(const HibernateLocation *hibernate_location, bool required) {
-        int r = 0;
+        int log_level = required ? LOG_ERR : LOG_DEBUG,
+            log_level_ignore = required ? LOG_WARNING : LOG_DEBUG;
 
 #if ENABLE_EFI
         _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
@@ -63,16 +64,14 @@ static int write_efi_hibernate_location(const HibernateLocation *hibernate_locat
         const char *uuid_str;
         sd_id128_t uuid;
         struct utsname uts = {};
-        int log_level, log_level_ignore;
+        int r;
 
         assert(hibernate_location);
         assert(hibernate_location->swap);
 
         if (!is_efi_boot())
-                return 0;
-
-        log_level = required ? LOG_ERR : LOG_DEBUG;
-        log_level_ignore = required ? LOG_WARNING : LOG_DEBUG;
+                return log_full_errno(log_level, SYNTHETIC_ERRNO(EOPNOTSUPP),
+                                      "Not an EFI boot, passing HibernateLocation via EFI variable is not possible.");
 
         r = sd_device_new_from_devnum(&device, 'b', hibernate_location->devno);
         if (r < 0)
@@ -120,9 +119,11 @@ static int write_efi_hibernate_location(const HibernateLocation *hibernate_locat
                 return log_full_errno(log_level, r, "Failed to set EFI variable HibernateLocation: %m");
 
         log_debug("Set EFI variable HibernateLocation to '%s'.", formatted);
+        return 0;
+#else
+        return log_full_errno(log_level, SYNTHETIC_ERRNO(EOPNOTSUPP),
+                              "EFI support not enabled, passing HibernateLocation via EFI variable is not possible.");
 #endif
-
-        return r;
 }
 
 static int write_kernel_hibernate_location(const HibernateLocation *hibernate_location) {