From 98034eb0ea2f38ee6688273f5f1e33a31a3b514b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 20 Jun 2023 12:32:21 +0200 Subject: [PATCH] sleep-config: pin swap device while operating via O_PATH --- src/shared/sleep-config.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index 88e907422b..342eb28388 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -611,15 +611,18 @@ HibernateLocation* hibernate_location_free(HibernateLocation *hl) { } static int swap_device_to_device_id(const SwapEntry *swap, dev_t *ret_dev) { + _cleanup_close_ int fd = -EBADF; struct stat sb; int r; assert(swap); assert(swap->device); - assert(swap->type); - r = stat(swap->device, &sb); - if (r < 0) + fd = open(swap->device, O_CLOEXEC|O_PATH); + if (fd < 0) + return -errno; + + if (fstat(fd, &sb) < 0) return -errno; if (swap->type == SWAP_BLOCK) { @@ -634,7 +637,7 @@ static int swap_device_to_device_id(const SwapEntry *swap, dev_t *ret_dev) { if (r < 0) return r; - return get_block_device(swap->device, ret_dev); + return get_block_device_fd(fd, ret_dev); } /* -- 2.25.1