tools/testing/selftests/proc/proc-subset-pid.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/proc/proc-subset-pid.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/proc/proc-subset-pid.c- Extension
.c- Size
- 2844 bytes
- Lines
- 122
- 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
assert.herrno.hsched.hstdbool.hstdlib.hstring.hsys/mount.hsys/types.hsys/stat.hfcntl.hdirent.hunistd.hstdio.h
Detected Declarations
function Copyrightfunction make_private_procfunction string_is_pidfunction main
Annotated Snippet
if (errno == ENOSYS || errno == EPERM) {
exit(4);
}
exit(1);
}
if (mount(NULL, "/", NULL, MS_PRIVATE|MS_REC, NULL) == -1) {
exit(1);
}
if (mount(NULL, "/proc", "proc", 0, "subset=pid") == -1) {
exit(1);
}
}
static bool string_is_pid(const char *s)
{
while (1) {
switch (*s++) {
case '0':case '1':case '2':case '3':case '4':
case '5':case '6':case '7':case '8':case '9':
continue;
case '\0':
return true;
default:
return false;
}
}
}
int main(void)
{
make_private_proc();
DIR *d = opendir("/proc");
assert(d);
struct dirent *de;
bool dot = false;
bool dot_dot = false;
bool self = false;
bool thread_self = false;
while ((de = readdir(d))) {
if (streq(de->d_name, ".")) {
assert(!dot);
dot = true;
assert(de->d_type == DT_DIR);
} else if (streq(de->d_name, "..")) {
assert(!dot_dot);
dot_dot = true;
assert(de->d_type == DT_DIR);
} else if (streq(de->d_name, "self")) {
assert(!self);
self = true;
assert(de->d_type == DT_LNK);
} else if (streq(de->d_name, "thread-self")) {
assert(!thread_self);
thread_self = true;
assert(de->d_type == DT_LNK);
} else {
if (!string_is_pid(de->d_name)) {
fprintf(stderr, "d_name '%s'\n", de->d_name);
assert(0);
}
assert(de->d_type == DT_DIR);
}
}
char c;
int rv = readlink("/proc/cpuinfo", &c, 1);
assert(rv == -1 && errno == ENOENT);
int fd = open("/proc/cpuinfo", O_RDONLY);
assert(fd == -1 && errno == ENOENT);
return 0;
}
Annotation
- Immediate include surface: `assert.h`, `errno.h`, `sched.h`, `stdbool.h`, `stdlib.h`, `string.h`, `sys/mount.h`, `sys/types.h`.
- Detected declarations: `function Copyright`, `function make_private_proc`, `function string_is_pid`, `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.