tools/testing/selftests/pid_namespace/pid_max.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/pid_namespace/pid_max.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/pid_namespace/pid_max.c- Extension
.c- Size
- 9152 bytes
- Lines
- 452
- 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.
Dependency Surface
assert.herrno.hfcntl.hlinux/types.hsched.hsignal.hstdio.hstdlib.hstring.hsyscall.hsys/mount.hsys/wait.hunistd.hkselftest_harness.h../pidfd/pidfd.h
Detected Declarations
function maxfunction pid_minfunction write_int_to_fdfunction do_clonefunction pid_max_cbfunction pid_max_nested_innerfunction pid_max_nested_outerfunction pid_max_nested_limit_innerfunction pid_max_nested_limit_outer
Annotated Snippet
if (pid > inner_limit) {
fprintf(stderr, "Managed to create pid number beyond limit\n");
return -1;
}
}
return 0;
}
static int pid_max_nested_inner(void *data)
{
int fret = -1;
pid_t pids[2];
int fd, i, ret;
ret = mount("", "/", NULL, MS_PRIVATE | MS_REC, 0);
if (ret) {
fprintf(stderr, "%m - Failed to make rootfs private mount\n");
return fret;
}
umount2("/proc", MNT_DETACH);
ret = mount("proc", "/proc", "proc", 0, NULL);
if (ret) {
fprintf(stderr, "%m - Failed to mount proc\n");
return fret;
}
fd = open("/proc/sys/kernel/pid_max", O_RDWR | O_CLOEXEC | O_NOCTTY);
if (fd < 0) {
fprintf(stderr, "%m - Failed to open pid_max\n");
return fret;
}
ret = write_int_to_fd(fd, inner_limit);
close(fd);
if (ret < 0) {
fprintf(stderr, "%m - Failed to write pid_max\n");
return fret;
}
pids[0] = fork();
if (pids[0] < 0) {
fprintf(stderr, "Failed to create first new process\n");
return fret;
}
if (pids[0] == 0)
exit(EXIT_SUCCESS);
pids[1] = fork();
wait_for_pid(pids[0]);
if (pids[1] >= 0) {
if (pids[1] == 0)
exit(EXIT_SUCCESS);
wait_for_pid(pids[1]);
fprintf(stderr, "Managed to create process even though ancestor pid namespace had a limit\n");
return fret;
}
/* Now make sure that we wrap pids at outer_limit. */
for (i = 0; i < inner_limit + 10; i++) {
pid_t pid;
pid = fork();
if (pid < 0)
return fret;
if (pid == 0)
exit(EXIT_SUCCESS);
wait_for_pid(pid);
if (pid >= inner_limit) {
fprintf(stderr, "Managed to create process with pid %d beyond configured limit\n", pid);
return fret;
}
}
return 0;
}
static int pid_max_nested_outer(void *data)
{
int fret = -1, nr_procs = 0;
pid_t *pids;
int fd, ret;
pid_t pid;
Annotation
- Immediate include surface: `assert.h`, `errno.h`, `fcntl.h`, `linux/types.h`, `sched.h`, `signal.h`, `stdio.h`, `stdlib.h`.
- Detected declarations: `function max`, `function pid_min`, `function write_int_to_fd`, `function do_clone`, `function pid_max_cb`, `function pid_max_nested_inner`, `function pid_max_nested_outer`, `function pid_max_nested_limit_inner`, `function pid_max_nested_limit_outer`.
- 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.