tools/testing/selftests/clone3/clone3_set_tid.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/clone3/clone3_set_tid.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/clone3/clone3_set_tid.c- Extension
.c- Size
- 10735 bytes
- Lines
- 419
- 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.hlinux/types.hlinux/sched.hstdio.hstdlib.hstdbool.hsys/syscall.hsys/types.hsys/un.hsys/wait.hunistd.hsched.hkselftest.hclone3_selftests.h
Detected Declarations
function child_exitfunction call_clone3_set_tidfunction test_clone3_set_tidfunction main
Annotated Snippet
if (wait_for_it) {
ksft_print_msg("[%d] Child is ready and waiting\n",
getpid());
/* Signal the parent that the child is ready */
close(pipe_1[0]);
ret = write(pipe_1[1], &tmp, 1);
if (ret != 1) {
ksft_print_msg(
"Writing to pipe returned %d", ret);
exit_code = EXIT_FAILURE;
}
close(pipe_1[1]);
close(pipe_2[1]);
ret = read(pipe_2[0], &tmp, 1);
if (ret != 1) {
ksft_print_msg(
"Reading from pipe returned %d", ret);
exit_code = EXIT_FAILURE;
}
close(pipe_2[0]);
}
if (set_tid[0] != getpid())
child_exit(EXIT_FAILURE);
child_exit(exit_code);
}
if (expected_pid == 0 || expected_pid == pid) {
ksft_print_msg("I am the parent (%d). My child's pid is %d\n",
getpid(), pid);
} else {
ksft_print_msg(
"Expected child pid %d does not match actual pid %d\n",
expected_pid, pid);
return -1;
}
if (waitpid(pid, &status, 0) < 0) {
ksft_print_msg("Child returned %s\n", strerror(errno));
return -errno;
}
if (!WIFEXITED(status))
return -1;
return WEXITSTATUS(status);
}
static void test_clone3_set_tid(const char *desc,
pid_t *set_tid,
size_t set_tid_size,
int flags,
int expected,
int expected_pid,
bool wait_for_it)
{
int ret;
ksft_print_msg(
"[%d] Trying clone3() with CLONE_SET_TID to %d and 0x%x\n",
getpid(), set_tid[0], flags);
ret = call_clone3_set_tid(set_tid, set_tid_size, flags, expected_pid,
wait_for_it);
ksft_print_msg(
"[%d] clone3() with CLONE_SET_TID %d says: %d - expected %d\n",
getpid(), set_tid[0], ret, expected);
ksft_test_result(ret == expected, "%s with %zu TIDs and flags 0x%x\n",
desc, set_tid_size, flags);
}
int main(int argc, char *argv[])
{
FILE *f;
char buf;
char *line;
int status;
int ret = -1;
size_t len = 0;
int pid_max = 0;
uid_t uid = getuid();
char proc_path[100] = {0};
pid_t pid, ns1, ns2, ns3, ns_pid;
pid_t set_tid[MAX_PID_NS_LEVEL * 2];
ksft_print_header();
ksft_set_plan(29);
test_clone3_supported();
Annotation
- Immediate include surface: `errno.h`, `linux/types.h`, `linux/sched.h`, `stdio.h`, `stdlib.h`, `stdbool.h`, `sys/syscall.h`, `sys/types.h`.
- Detected declarations: `function child_exit`, `function call_clone3_set_tid`, `function test_clone3_set_tid`, `function main`.
- 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.