tools/testing/selftests/pidfd/pidfd_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/pidfd/pidfd_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/pidfd/pidfd_test.c- Extension
.c- Size
- 15522 bytes
- Lines
- 629
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hfcntl.hlinux/types.hpthread.hsched.hsignal.hstdio.hstdbool.hstdlib.hstring.hsyscall.hsys/epoll.hsys/mman.hsys/mount.hsys/wait.htime.hunistd.hpidfd.hkselftest.h
Detected Declarations
function pidfd_clonefunction set_signal_received_on_sigusr1function send_signalfunction pidfd_send_signalfunction test_pidfd_send_signal_exited_failfunction test_pidfd_send_signal_recycled_pid_failfunction test_pidfd_send_signal_syscall_supportfunction poll_pidfdfunction child_poll_exec_testfunction test_pidfd_poll_execfunction child_poll_leader_exit_testfunction test_pidfd_poll_leader_exitfunction main
Annotated Snippet
if (errno == EPERM) {
ksft_test_result_skip("%s test: Unsharing pid namespace not permitted\n",
test_name);
return 0;
}
ksft_exit_fail_msg("%s test: Failed to unshare pid namespace\n",
test_name);
}
ret = unshare(CLONE_NEWNS);
if (ret < 0) {
if (errno == EPERM) {
ksft_test_result_skip("%s test: Unsharing mount namespace not permitted\n",
test_name);
return 0;
}
ksft_exit_fail_msg("%s test: Failed to unshare mount namespace\n",
test_name);
}
ret = mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0);
if (ret < 0)
ksft_exit_fail_msg("%s test: Failed to remount / private\n",
test_name);
/* pid 1 in new pid namespace */
pid1 = fork();
if (pid1 < 0)
ksft_exit_fail_msg("%s test: Failed to create new process\n",
test_name);
if (pid1 == 0) {
char buf[256];
pid_t pid2;
int pidfd = -1;
(void)umount2("/proc", MNT_DETACH);
ret = mount("proc", "/proc", "proc", 0, NULL);
if (ret < 0)
_exit(PIDFD_ERROR);
/* grab pid PID_RECYCLE */
for (i = 0; i <= PIDFD_MAX_DEFAULT; i++) {
pid2 = fork();
if (pid2 < 0)
_exit(PIDFD_ERROR);
if (pid2 == 0)
_exit(PIDFD_PASS);
if (pid2 == PID_RECYCLE) {
snprintf(buf, sizeof(buf), "/proc/%d", pid2);
ksft_print_msg("pid to recycle is %d\n", pid2);
pidfd = open(buf, O_DIRECTORY | O_CLOEXEC);
}
if (wait_for_pid(pid2))
_exit(PIDFD_ERROR);
if (pid2 >= PID_RECYCLE)
break;
}
/*
* We want to be as predictable as we can so if we haven't been
* able to grab pid PID_RECYCLE skip the test.
*/
if (pid2 != PID_RECYCLE) {
/* skip test */
close(pidfd);
_exit(PIDFD_SKIP);
}
if (pidfd < 0)
_exit(PIDFD_ERROR);
for (i = 0; i <= PIDFD_MAX_DEFAULT; i++) {
char c;
int pipe_fds[2];
pid_t recycled_pid;
int child_ret = PIDFD_PASS;
ret = pipe2(pipe_fds, O_CLOEXEC);
if (ret < 0)
_exit(PIDFD_ERROR);
recycled_pid = fork();
if (recycled_pid < 0)
_exit(PIDFD_ERROR);
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `linux/types.h`, `pthread.h`, `sched.h`, `signal.h`, `stdio.h`, `stdbool.h`.
- Detected declarations: `function pidfd_clone`, `function set_signal_received_on_sigusr1`, `function send_signal`, `function pidfd_send_signal`, `function test_pidfd_send_signal_exited_fail`, `function test_pidfd_send_signal_recycled_pid_fail`, `function test_pidfd_send_signal_syscall_support`, `function poll_pidfd`, `function child_poll_exec_test`, `function test_pidfd_poll_exec`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.