tools/testing/selftests/cgroup/test_core.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/cgroup/test_core.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/cgroup/test_core.c- Extension
.c- Size
- 19964 bytes
- Lines
- 960
- 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
linux/limits.hlinux/sched.hsys/types.hsys/mman.hsys/mount.hsys/stat.hsys/wait.hunistd.hfcntl.hsched.hstdio.herrno.hsignal.hstring.hpthread.hkselftest.hcgroup_util.h
Detected Declarations
struct lesser_ns_open_thread_argstruct corecg_testfunction touch_anonfunction alloc_and_touch_anon_noexitfunction test_cgcore_destroyfunction Afunction Afunction test_cgcore_parent_becomes_threadedfunction test_cgcore_no_internal_process_constraint_on_threadsfunction test_cgcore_top_down_constraint_enablefunction test_cgcore_top_down_constraint_disablefunction test_cgcore_internal_process_constraintfunction test_cgcore_proc_migrationfunction test_cgcore_thread_migrationfunction test_cgcore_lesser_euid_openfunction lesser_ns_open_thread_fnfunction test_cgcore_lesser_ns_openfunction setup_named_v1_rootfunction cleanup_named_v1_rootfunction main
Annotated Snippet
struct lesser_ns_open_thread_arg {
const char *path;
int fd;
int err;
};
static int lesser_ns_open_thread_fn(void *arg)
{
struct lesser_ns_open_thread_arg *targ = arg;
targ->fd = open(targ->path, O_RDWR);
targ->err = errno;
return 0;
}
/*
* cgroup migration permission check should be performed based on the cgroup
* namespace at the time of open instead of write.
*/
static int test_cgcore_lesser_ns_open(const char *root)
{
static char stack[65536];
const uid_t test_euid = 65534; /* usually nobody, any !root is fine */
int ret = KSFT_FAIL;
char *cg_test_a = NULL, *cg_test_b = NULL;
char *cg_test_a_procs = NULL, *cg_test_b_procs = NULL;
int cg_test_b_procs_fd = -1;
struct lesser_ns_open_thread_arg targ = { .fd = -1 };
pid_t pid;
int status;
if (!nsdelegate)
return KSFT_SKIP;
cg_test_a = cg_name(root, "cg_test_a");
cg_test_b = cg_name(root, "cg_test_b");
if (!cg_test_a || !cg_test_b)
goto cleanup;
cg_test_a_procs = cg_name(cg_test_a, "cgroup.procs");
cg_test_b_procs = cg_name(cg_test_b, "cgroup.procs");
if (!cg_test_a_procs || !cg_test_b_procs)
goto cleanup;
if (cg_create(cg_test_a) || cg_create(cg_test_b))
goto cleanup;
if (cg_enter_current(cg_test_b))
goto cleanup;
if (chown(cg_test_a_procs, test_euid, -1) ||
chown(cg_test_b_procs, test_euid, -1))
goto cleanup;
targ.path = cg_test_b_procs;
pid = clone(lesser_ns_open_thread_fn, stack + sizeof(stack),
CLONE_NEWCGROUP | CLONE_FILES | CLONE_VM | SIGCHLD,
&targ);
if (pid < 0)
goto cleanup;
if (waitpid(pid, &status, 0) < 0)
goto cleanup;
if (!WIFEXITED(status))
goto cleanup;
cg_test_b_procs_fd = targ.fd;
if (cg_test_b_procs_fd < 0)
goto cleanup;
if (cg_enter_current(cg_test_a))
goto cleanup;
if ((status = write(cg_test_b_procs_fd, "0", 1)) >= 0 || errno != ENOENT)
goto cleanup;
ret = KSFT_PASS;
cleanup:
cg_enter_current(root);
if (cg_test_b_procs_fd >= 0)
close(cg_test_b_procs_fd);
if (cg_test_b)
cg_destroy(cg_test_b);
if (cg_test_a)
cg_destroy(cg_test_a);
free(cg_test_b_procs);
Annotation
- Immediate include surface: `linux/limits.h`, `linux/sched.h`, `sys/types.h`, `sys/mman.h`, `sys/mount.h`, `sys/stat.h`, `sys/wait.h`, `unistd.h`.
- Detected declarations: `struct lesser_ns_open_thread_arg`, `struct corecg_test`, `function touch_anon`, `function alloc_and_touch_anon_noexit`, `function test_cgcore_destroy`, `function A`, `function A`, `function test_cgcore_parent_becomes_threaded`, `function test_cgcore_no_internal_process_constraint_on_threads`, `function test_cgcore_top_down_constraint_enable`.
- 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.