From: Mike Yuan Date: Sun, 1 Jun 2025 06:55:50 +0000 (+0200) Subject: pidfd-util: open an internal pidfd if none is passed in pidfd_check_pidfs() X-Git-Tag: v258-rc1~390^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e09b7ced6557135becc8f5fb6dc23db753772124;p=thirdparty%2Fsystemd.git pidfd-util: open an internal pidfd if none is passed in pidfd_check_pidfs() I'd like to introduce a libsystemd helper for acquiring pidfd inode id, which however means the fd passed to pidfd_check_pidfs() can no longer be trusted. Let's add back the logic of allocating a genuine pidfd allocated internally, which was remove in 5dc9d5b4eacbe32f58ad6ca18d70931ab89ea409. --- diff --git a/src/basic/pidfd-util.c b/src/basic/pidfd-util.c index f53a94f2d3e..629ffe95961 100644 --- a/src/basic/pidfd-util.c +++ b/src/basic/pidfd-util.c @@ -26,6 +26,15 @@ static int pidfd_check_pidfs(int pid_fd) { if (have_pidfs >= 0) return have_pidfs; + _cleanup_close_ int our_fd = -EBADF; + if (pid_fd < 0) { + our_fd = pidfd_open(getpid_cached(), /* flags = */ 0); + if (our_fd < 0) + return -errno; + + pid_fd = our_fd; + } + return (have_pidfs = fd_is_fs_type(pid_fd, PID_FS_MAGIC)); }