hibernate-util: make sure we use blockdev path for HibernationDevice.path

Before this commit, this field could spuriously contain the path of the
swapfile.
This commit is contained in:
Mike Yuan 2023-12-27 22:19:07 +08:00
parent 51dfa75c6e
commit 66b9956082
No known key found for this signature in database
GPG key ID: 417471C0A40F58B3

View 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;