]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sleep-config: replace useless fstat() by useful fd_verify_regular()
authorLennart Poettering <lennart@poettering.net>
Tue, 20 Jun 2023 10:23:58 +0000 (12:23 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 20 Jun 2023 11:11:53 +0000 (13:11 +0200)
For some reason there was an fstat() call here whose results was
entirely ignored. Let's remove it. Let's add a call to
fd_verify_regular() instead, because this is a code path for swap files,
hence let's make sure we actually operate on a file, and nothing else.

src/shared/sleep-config.c

index cba5993afe8a98096be9734afb69b625dad161cd..cee0a69cb01205449710120f6859a002bf964324 100644 (file)
@@ -641,7 +641,6 @@ static int swap_device_to_device_id(const SwapEntry *swap, dev_t *ret_dev) {
 static int calculate_swap_file_offset(const SwapEntry *swap, uint64_t *ret_offset) {
         _cleanup_close_ int fd = -EBADF;
         _cleanup_free_ struct fiemap *fiemap = NULL;
-        struct stat sb;
         int r;
 
         assert(swap);
@@ -652,8 +651,9 @@ static int calculate_swap_file_offset(const SwapEntry *swap, uint64_t *ret_offse
         if (fd < 0)
                 return log_debug_errno(errno, "Failed to open swap file %s to determine on-disk offset: %m", swap->device);
 
-        if (fstat(fd, &sb) < 0)
-                return log_debug_errno(errno, "Failed to stat %s: %m", swap->device);
+        r = fd_verify_regular(fd);
+        if (r < 0)
+                return log_debug_errno(r, "Selected swap file is not a regular file.");
 
         r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
         if (r < 0)