[LTP] [PATCH v4 6/8] Add ioctl_pidfd04 test
Andrea Cervesato
andrea.cervesato@suse.de
Wed Jul 23 16:15:20 CEST 2025
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that ioctl() permits to obtain the exit code of an isolated
signaled child via PIDFD_INFO_EXIT from within a process.
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/ioctl/.gitignore | 1 +
testcases/kernel/syscalls/ioctl/ioctl_pidfd04.c | 71 +++++++++++++++++++++++++
3 files changed, 73 insertions(+)
diff --git a/runtest/syscalls b/runtest/syscalls
index 7e019675216a59919b137b84b023ebb2969efcdb..3d0789bee7d4723f6af549eace1e14e358e17220 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -616,6 +616,7 @@ ioctl_fiemap01 ioctl_fiemap01
ioctl_pidfd01 ioctl_pidfd01
ioctl_pidfd02 ioctl_pidfd02
ioctl_pidfd03 ioctl_pidfd03
+ioctl_pidfd04 ioctl_pidfd04
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 393ec47fecaed101f413284f28646aeff76cc30b..b92cb5d33fe05652874c5ba4027c8521528f8ecc 100644
--- a/testcases/kernel/syscalls/ioctl/.gitignore
+++ b/testcases/kernel/syscalls/ioctl/.gitignore
@@ -33,3 +33,4 @@
/ioctl_pidfd01
/ioctl_pidfd02
/ioctl_pidfd03
+/ioctl_pidfd04
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_pidfd04.c b/testcases/kernel/syscalls/ioctl/ioctl_pidfd04.c
new file mode 100644
index 0000000000000000000000000000000000000000..e5f582414acce8158aaf487d38b74f137f8f3088
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl_pidfd04.c
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2025 Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * Verify that ioctl() permits to obtain the exit code of an isolated signaled
+ * child via PIDFD_INFO_EXIT from within a process.
+ */
+
+#include "ioctl_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));
+ memset(info, 0, sizeof(struct pidfd_info));
+
+ info->mask = PIDFD_INFO_EXIT;
+
+ 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_WAKE_AND_WAIT(0);
+ exit(1);
+ }
+
+ TST_CHECKPOINT_WAIT(0);
+
+ SAFE_KILL(pid_child, SIGKILL);
+ SAFE_WAITPID(pid_child, &status, 0);
+
+ SAFE_IOCTL(pidfd, PIDFD_GET_INFO, info);
+ SAFE_CLOSE(pidfd);
+
+ TST_EXP_EQ_LI(info->mask & PIDFD_INFO_EXIT, PIDFD_INFO_EXIT);
+ TST_EXP_EQ_LI(WIFSIGNALED(info->exit_code), WIFSIGNALED(status));
+ TST_EXP_EQ_LI(WEXITSTATUS(info->exit_code), WEXITSTATUS(status));
+ TST_EXP_EQ_LI(WTERMSIG(info->exit_code), WTERMSIG(status));
+
+ TST_EXP_EXPR(WIFSIGNALED(info->exit_code) &&
+ WTERMSIG(info->exit_code) == SIGKILL);
+}
+
+static void setup(void)
+{
+ if (!ioctl_pidfd_info_exit_supported())
+ tst_brk(TCONF, "PIDFD_INFO_EXIT is not supported by ioctl()");
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .forks_child = 1,
+ .needs_checkpoints = 1,
+ .bufs = (struct tst_buffers []) {
+ {&args, .size = sizeof(*args)},
+ {&info, .size = sizeof(*info)},
+ {}
+ }
+};
--
2.50.1
More information about the ltp
mailing list