[LTP] [PATCH v3] Introduce ioctl_pidfd_get_info_supported() function

Avinesh Kumar akumar@suse.de
Wed Sep 24 22:30:10 CEST 2025


Hi Cyril,

On Wednesday, September 24, 2025 10:34:43 AM CEST Cyril Hrubis wrote:
> Hi!
> > +static inline bool ioctl_pidfd_get_info_supported(void)
> > +{
> > +	pid_t pid;
> > +	int pidfd, ret;
> > +	int supported = 0;
> > +	struct pidfd_info info;
> > +
> > +	if (tst_kvercmp(6, 12, 0) >= 0)
> > +		return 1;
> > +
> > +	memset(&info, 0, sizeof(struct pidfd_info));
> > +
> > +	pid = SAFE_FORK();
> > +	if (!pid)
> > +		exit(100);
> > +
> > +	pidfd = SAFE_PIDFD_OPEN(pid, 0);
> > +	SAFE_WAITPID(pid, NULL, 0);
> 
> Again, please do not waitpid before the PIDFD_GET_INFO ioctl(). If you
> do that it has no chance of succeeding.
> 
> From fs/pidfd.c:
> 
> ...
>         task = get_pid_task(pid, PIDTYPE_PID);
>         if (!task) {
>                 /*
>                  * If the task has already been reaped, only exit
>                  * information is available
>                  */
>                 if (!(mask & PIDFD_INFO_EXIT))
>                         return -ESRCH;
> 
>                 goto copy_out;
>         }
> ...
> 
> We have to do the ioctl() first and the waitpid() second for this case.
> 
> And if we do so we don't have to check the errno at all, the call will
> just succeed in case that it's supported.
> 
Thank you for your patience explaining this one repeatedly. I read through
the iterations of these new tests in ML to get better understanding of
checking the feature detection. I have sent another revision.
I have also changed the kernel version check from 6.12 to 6.13 as that's
where I see pidfd_info() implementation.


Regards,
Avinesh





More information about the ltp mailing list