From: Lennart Poettering Date: Tue, 20 Jun 2023 10:23:58 +0000 (+0200) Subject: sleep-config: replace useless fstat() by useful fd_verify_regular() X-Git-Tag: v254-rc1~164^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1cf78c8f785a492e592479fae2824fe99ece9b40;p=thirdparty%2Fsystemd.git sleep-config: replace useless fstat() by useful fd_verify_regular() 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. --- diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index cba5993afe8..cee0a69cb01 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -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)