]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hibernate-util: make sure we use blockdev path for HibernationDevice.path
authorMike Yuan <me@yhndnzj.com>
Wed, 27 Dec 2023 14:19:07 +0000 (22:19 +0800)
committerMike Yuan <me@yhndnzj.com>
Wed, 27 Dec 2023 14:38:42 +0000 (22:38 +0800)
Before this commit, this field could spuriously contain the path of the
swapfile.

src/shared/hibernate-util.c

index 48ed4141973d841eb52d2181a2a98621298b8665..99b37483bdb8f8bec876e549609603d29653957c 100644 (file)
@@ -388,12 +388,24 @@ int find_suitable_hibernation_device_full(HibernationDevice *ret_device, uint64_
                 return log_debug_errno(SYNTHETIC_ERRNO(ENOSPC), "Cannot find swap entry corresponding to /sys/power/resume.");
         }
 
-        if (ret_device)
+        if (ret_device) {
+                char *path;
+
+                if (entry->swapfile) {
+                        r = device_path_make_canonical(S_IFBLK, entry->devno, &path);
+                        if (r < 0)
+                                return log_debug_errno(r,
+                                                       "Failed to format canonical device path for devno '" DEVNUM_FORMAT_STR "': %m",
+                                                       DEVNUM_FORMAT_VAL(entry->devno));
+                } else
+                        path = TAKE_PTR(entry->path);
+
                 *ret_device = (HibernationDevice) {
                         .devno = entry->devno,
                         .offset = entry->offset,
-                        .path = TAKE_PTR(entry->path),
+                        .path = path,
                 };
+        }
 
         if (ret_size) {
                 *ret_size = entry->size;