[LTP] [PATCH 5/6] Add ioctl_pidfd03 test

Cyril Hrubis chrubis@suse.cz
Fri Jun 27 11:56:44 CEST 2025


Hi!
> +static void run(void)
> +{
> +	int status;
> +	int pidfd = 0;
> +	pid_t pid_child;
> +
> +	memset(args, 0, sizeof(struct tst_clone_args));
> +
> +	args->flags = CLONE_PIDFD | CLONE_NEWUSER | CLONE_NEWPID;
> +	args->pidfd = (uint64_t)&pidfd;
> +	args->exit_signal = SIGCHLD;
> +
> +	pid_child = SAFE_CLONE(args);
> +	if (!pid_child)
> +		exit(100);
> +
> +	SAFE_WAITPID(pid_child, &status, 0);
> +
> +	TST_EXP_FAIL(ioctl(pidfd, PIDFD_GET_INFO, info), ESRCH);
> +	TST_EXP_EQ_LI(info->mask & PIDFD_INFO_EXIT, 0);

If I'm reading the kernel code correctly, we should get the same result
even before the pid was waited for, so we may as well do this check
twice, once before the WAITPID() and once after the WAITPID().

> +}
> +
> +static struct tst_test test = {
> +	.test_all = run,
> +	.forks_child = 1,
> +	.min_kver = "6.15",
> +	.bufs = (struct tst_buffers []) {
> +		{&args, .size = sizeof(*args)},
> +		{&info, .size = sizeof(*info)},
> +		{}
> +	}
> +};
> 
> -- 
> 2.50.0
> 

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list