]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hibernate-util: de-duplicate clear_efi_hibernate_location
authorMike Yuan <me@yhndnzj.com>
Sat, 9 Dec 2023 14:34:43 +0000 (22:34 +0800)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 10 Dec 2023 05:08:46 +0000 (14:08 +0900)
src/hibernate-resume/hibernate-resume-config.c
src/hibernate-resume/hibernate-resume-config.h
src/hibernate-resume/hibernate-resume.c
src/shared/hibernate-util.c
src/shared/hibernate-util.h
src/sleep/sleep.c

index e4be7ca245171ce0245c0866b40d26e34344a185..201e14bc83bbd495cf53bdc758b96e6961df1ba5 100644 (file)
@@ -225,17 +225,6 @@ void compare_hibernate_location_and_warn(const HibernateInfo *info) {
                 log_warning("resume_offset=%" PRIu64 " doesn't match with EFI HibernateLocation offset %" PRIu64 ", proceeding anyway with resume_offset=.",
                             info->cmdline->offset, info->efi->offset);
 }
-
-void clear_efi_hibernate_location(void) {
-        int r;
-
-        if (!is_efi_boot())
-                return;
-
-        r = efi_set_variable(EFI_SYSTEMD_VARIABLE(HibernateLocation), NULL, 0);
-        if (r < 0)
-                log_warning_errno(r, "Failed to clear EFI variable HibernateLocation, ignoring: %m");
-}
 #endif
 
 int acquire_hibernate_info(HibernateInfo *ret) {
index 365d9ccda5934bded24b7c040aee4d488d00aa1e..be759ec5d6bff5360df71ec958d6eccb54e583cc 100644 (file)
@@ -40,16 +40,10 @@ int acquire_hibernate_info(HibernateInfo *ret);
 
 void compare_hibernate_location_and_warn(const HibernateInfo *info);
 
-void clear_efi_hibernate_location(void);
-
 #else
 
 static inline void compare_hibernate_location_and_warn(const HibernateInfo *info) {
         return;
 }
 
-static inline void clear_efi_hibernate_location(void) {
-        return;
-}
-
 #endif
index 175a0bda960274c7c9117ec1237b7f8ce296eb02..3f45836d591b127cfc44af4249ef4c7bc191a69b 100644 (file)
@@ -60,7 +60,7 @@ static int run(int argc, char *argv[]) {
                         return r;
 
                 if (arg_info.efi)
-                        clear_efi_hibernate_location();
+                        clear_efi_hibernate_location_and_warn();
         }
 
         if (stat(arg_info.device, &st) < 0)
index 2ce3781cbf6892a76a3f44efb1bd133bf69281c3..48ed4141973d841eb52d2181a2a98621298b8665 100644 (file)
@@ -506,3 +506,14 @@ int write_resume_config(dev_t devno, uint64_t offset, const char *device) {
 
         return 0;
 }
+
+void clear_efi_hibernate_location_and_warn(void) {
+        int r;
+
+        if (!is_efi_boot())
+                return;
+
+        r = efi_set_variable(EFI_SYSTEMD_VARIABLE(HibernateLocation), NULL, 0);
+        if (r < 0)
+                log_warning_errno(r, "Failed to clear EFI variable HibernateLocation, ignoring: %m");
+}
index 2ae10fb10013223ad2d503813427e3a0a665a63f..1064d2b4dd4ac30716053a8cd7cdafbc24760b4f 100644 (file)
@@ -22,5 +22,7 @@ int hibernation_is_safe(void);
 
 int write_resume_config(dev_t devno, uint64_t offset, const char *device);
 
+void clear_efi_hibernate_location_and_warn(void);
+
 /* Only for test-fiemap */
 int read_fiemap(int fd, struct fiemap **ret);
index 6ff012d4477b250f52e1fb988529682beeff09ed..3784796487a42bb2eddf851688b7bc6ab52b674d 100644 (file)
@@ -301,8 +301,8 @@ static int execute(
                 return 0;
 
 fail:
-        if (sleep_operation_is_hibernation(operation) && is_efi_boot())
-                (void) efi_set_variable(EFI_SYSTEMD_VARIABLE(HibernateLocation), NULL, 0);
+        if (sleep_operation_is_hibernation(operation))
+                clear_efi_hibernate_location_and_warn();
 
         return r;
 }