From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 4/6] Add ioctl_pidfd02 test
Date: Fri, 27 Jun 2025 11:11:58 +0200 [thread overview]
Message-ID: <aF5gXnHipDoPXla6@yuki.lan> (raw)
In-Reply-To: <20250626-ioctl_pidfd_suite-v1-4-165b9abf0296@suse.com>
Hi!
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 7f6312ce5fa241a778d8dda7f8ee9edd0a8800e6..23f335846663d62a39e6de3a8f6948c1b0acf8a5 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -613,6 +613,7 @@ ioctl_ficlonerange02 ioctl_ficlonerange02
> ioctl_fiemap01 ioctl_fiemap01
>
> ioctl_pidfd01 ioctl_pidfd01
> +ioctl_pidfd02 ioctl_pidfd02
>
> inotify_init1_01 inotify_init1_01
> inotify_init1_02 inotify_init1_02
> diff --git a/testcases/kernel/syscalls/ioctl/.gitignore b/testcases/kernel/syscalls/ioctl/.gitignore
> index aa952c1a7bae0ae2dbb04de0595f10d508b6759a..1c81c2bed8db952af0c93fb1ce5bfbad82794b60 100644
> --- a/testcases/kernel/syscalls/ioctl/.gitignore
> +++ b/testcases/kernel/syscalls/ioctl/.gitignore
> @@ -30,3 +30,4 @@
> /ioctl_ficlonerange02
> /ioctl_fiemap01
> /ioctl_pidfd01
> +/ioctl_pidfd02
> diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd02.c b/testcases/kernel/syscalls/ioctl/ioctl_pidfd02.c
> new file mode 100644
> index 0000000000000000000000000000000000000000..82dd8c359938cdc7bf69cc2fd6afc90ce2a95290
> --- /dev/null
> +++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd02.c
> @@ -0,0 +1,62 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2025 Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +/*\
> + * Check if the ioctl() function allows retrieval of a child's exit code
> + * using PIDFD_INFO_EXIT from a process that is isolated from the child.
> + */
> +
> +#include "tst_test.h"
> +#include "lapi/pidfd.h"
> +#include "lapi/sched.h"
> +
> +static struct tst_clone_args *args;
> +static struct pidfd_info *info;
> +
> +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) {
> + TST_CHECKPOINT_WAIT(0);
> + exit(100);
> + }
> +
> + /* child is not reaped, so ioctl() will pass */
> + info->mask = 0;
> + SAFE_IOCTL(pidfd, PIDFD_GET_INFO, info);
It will pass and:
- fill in some fields unconditionally
- if PIDFD_INFO_CREDS is set the info.*{uid,gid} should be checked
- if PIDFD_INFO_PID is set the info.*pid should be checked
- if PIDFD_INFO_CGROUPID is set the info.cgroupid will be also set
- the PIDFD_INFO_EXIT flag will not be set before the process did exit
> + TST_CHECKPOINT_WAKE(0);
> + SAFE_WAITPID(pid_child, &status, 0);
> +
> + /* child is now reaped, so we can ask for the exit status */
> + info->mask = PIDFD_INFO_EXIT;
> + SAFE_IOCTL(pidfd, PIDFD_GET_INFO, info);
> +
> + TST_EXP_EQ_LI(info->mask & PIDFD_INFO_EXIT, PIDFD_INFO_EXIT);
> + TST_EXP_EQ_LI(WIFEXITED(info->exit_code), WIFEXITED(status));
> + TST_EXP_EQ_LI(WEXITSTATUS(info->exit_code), WEXITSTATUS(status));
And here we should check that we got the same fields set as in the
previous case when the process was still running plus the exit_code.
I suppose that we will need two info structures so that we can do the
comparsion. Also it wouldn't harm to clear the structures with memset
before use.
> +}
> +
> +static struct tst_test test = {
> + .test_all = run,
> + .forks_child = 1,
> + .needs_checkpoints = 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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2025-06-27 9:11 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-26 12:34 [LTP] [PATCH 0/6] ioctl_pidfd testing suite Andrea Cervesato
2025-06-26 12:34 ` [LTP] [PATCH 1/6] Provide pidfd parameter in tst_clone_args Andrea Cervesato
2025-06-26 12:34 ` [LTP] [PATCH 2/6] Fallback PIDFD_GET_INFO related definitions Andrea Cervesato
2025-06-26 12:34 ` [LTP] [PATCH 3/6] Add ioctl_pidfd01 test Andrea Cervesato
2025-06-26 12:34 ` [LTP] [PATCH 4/6] Add ioctl_pidfd02 test Andrea Cervesato
2025-06-27 9:11 ` Cyril Hrubis [this message]
2025-06-27 9:47 ` Cyril Hrubis
2025-06-27 9:53 ` Cyril Hrubis
2025-06-26 12:34 ` [LTP] [PATCH 5/6] Add ioctl_pidfd03 test Andrea Cervesato
2025-06-27 9:56 ` Cyril Hrubis
2025-06-30 12:50 ` Andrea Cervesato via ltp
2025-06-30 14:30 ` Cyril Hrubis
2025-06-26 12:34 ` [LTP] [PATCH 6/6] Add ioctl_pidfd04 test Andrea Cervesato
2025-06-27 10:14 ` [LTP] [PATCH 0/6] ioctl_pidfd testing suite Cyril Hrubis
2025-07-01 11:15 ` Andrea Cervesato via ltp
2025-07-01 11:40 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aF5gXnHipDoPXla6@yuki.lan \
--to=chrubis@suse.cz \
--cc=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.