]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sleep-config: pin swap device while operating via O_PATH
authorLennart Poettering <lennart@poettering.net>
Tue, 20 Jun 2023 10:32:21 +0000 (12:32 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 20 Jun 2023 11:14:38 +0000 (13:14 +0200)
src/shared/sleep-config.c

index 88e907422b9b737ebf892eb0f5a261b2390d3f4c..342eb283889462475b218eefc5380348b6c374d0 100644 (file)
@@ -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);
 }
 
 /*