tools/testing/selftests/timens/vfork_exec.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/timens/vfork_exec.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/timens/vfork_exec.c- Extension
.c- Size
- 2772 bytes
- Lines
- 142
- 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.hsched.hstdio.hstdbool.hsys/stat.hsys/syscall.hsys/types.hsys/wait.htime.hunistd.hstring.hpthread.hlog.htimens.h
Detected Declarations
struct thread_argsfunction check_in_threadfunction checkfunction main
Annotated Snippet
struct thread_args {
char *tst_name;
struct timespec *now;
};
static void *tcheck(void *_args)
{
struct thread_args *args = _args;
struct timespec *now = args->now, tst;
int i;
for (i = 0; i < 2; i++) {
_gettime(CLOCK_MONOTONIC, &tst, i);
if (labs(tst.tv_sec - now->tv_sec) > 5) {
pr_fail("%s: in-thread: unexpected value: %ld (%ld)\n",
args->tst_name, tst.tv_sec, now->tv_sec);
return (void *)1UL;
}
}
return NULL;
}
static int check_in_thread(char *tst_name, struct timespec *now)
{
struct thread_args args = {
.tst_name = tst_name,
.now = now,
};
pthread_t th;
void *retval;
if (pthread_create(&th, NULL, tcheck, &args))
return pr_perror("thread");
if (pthread_join(th, &retval))
return pr_perror("pthread_join");
return !(retval == NULL);
}
static int check(char *tst_name, struct timespec *now)
{
struct timespec tst;
int i;
for (i = 0; i < 2; i++) {
_gettime(CLOCK_MONOTONIC, &tst, i);
if (labs(tst.tv_sec - now->tv_sec) > 5)
return pr_fail("%s: unexpected value: %ld (%ld)\n",
tst_name, tst.tv_sec, now->tv_sec);
}
if (check_in_thread(tst_name, now))
return 1;
ksft_test_result_pass("%s\n", tst_name);
return 0;
}
int main(int argc, char *argv[])
{
struct timespec now;
int status;
pid_t pid;
if (argc > 1) {
char *endptr;
ksft_cnt.ksft_pass = 1;
now.tv_sec = strtoul(argv[1], &endptr, 0);
if (*endptr != 0)
return pr_perror("strtoul");
return check("child after exec", &now);
}
ksft_print_header();
nscheck();
ksft_set_plan(4);
clock_gettime(CLOCK_MONOTONIC, &now);
if (unshare_timens())
return 1;
if (_settime(CLOCK_MONOTONIC, OFFSET))
return 1;
if (check("parent before vfork", &now))
return 1;
pid = vfork();
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `sched.h`, `stdio.h`, `stdbool.h`, `sys/stat.h`, `sys/syscall.h`, `sys/types.h`.
- Detected declarations: `struct thread_args`, `function check_in_thread`, `function check`, `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.