]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pidfd-util: use fd_to_handle_u64()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 3 Feb 2026 15:29:06 +0000 (00:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 3 Feb 2026 17:45:17 +0000 (02:45 +0900)
src/basic/pidfd-util.c

index 8c4c8324529d1e22f718d26ccc35fba87dbadfbb..7bfe83d319d3846bf43eec172d6312b4881bb6a7 100644 (file)
@@ -1,6 +1,5 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
-#include <linux/fs.h>
 #include <linux/magic.h>
 #include <sys/ioctl.h>
 #include <threads.h>
@@ -236,25 +235,10 @@ int pidfd_get_inode_id_impl(int fd, uint64_t *ret) {
 
         assert(fd >= 0);
 
+        /* Since kernel 6.14 (b3caba8f7a34a2bbaf45ffc6ff3a49b70afeb192), we can use name_to_handle_at(). */
         if (file_handle_supported) {
-                union {
-                        struct file_handle file_handle;
-                        uint8_t space[MAX_HANDLE_SZ];
-                } fh = {
-                        .file_handle.handle_bytes = sizeof(uint64_t),
-                        .file_handle.handle_type = FILEID_KERNFS,
-                };
-                int mnt_id;
-
-                r = RET_NERRNO(name_to_handle_at(fd, "", &fh.file_handle, &mnt_id, AT_EMPTY_PATH));
-                if (r >= 0) {
-                        if (ret)
-                                /* Note, "struct file_handle" is 32bit aligned usually, but we need to read a 64bit value from it */
-                                *ret = unaligned_read_ne64(fh.file_handle.f_handle);
-                        return 0;
-                }
-                assert(r != -EOVERFLOW);
-                if (is_name_to_handle_at_fatal_error(r))
+                r = fd_to_handle_u64(fd, ret);
+                if (r >= 0 || is_name_to_handle_at_fatal_error(r))
                         return r;
 
                 file_handle_supported = false;