tools/testing/selftests/filesystems/devpts_pts.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/devpts_pts.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/filesystems/devpts_pts.c- Extension
.c- Size
- 6054 bytes
- Lines
- 315
- 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
errno.hfcntl.hsched.hstdbool.hstdio.hstdlib.hstring.hunistd.hasm/ioctls.hsys/mount.hsys/wait.hkselftest.h
Detected Declarations
function terminal_dup2function terminal_set_stdfdsfunction login_ptyfunction wait_for_pidfunction resolve_procfd_symlinkfunction do_tiocgptpeerfunction verify_non_standard_devpts_mountfunction verify_ptmx_bind_mountfunction verify_invalid_ptmx_bind_mountfunction main
Annotated Snippet
if (!terminal_dup2(fd, (int[]){STDIN_FILENO, STDOUT_FILENO,
STDERR_FILENO}[i]))
return -1;
return 0;
}
static int login_pty(int fd)
{
int ret;
setsid();
ret = ioctl(fd, TIOCSCTTY, NULL);
if (ret < 0)
return -1;
ret = terminal_set_stdfds(fd);
if (ret < 0)
return -1;
if (fd > STDERR_FILENO)
close(fd);
return 0;
}
static int wait_for_pid(pid_t pid)
{
int status, ret;
again:
ret = waitpid(pid, &status, 0);
if (ret == -1) {
if (errno == EINTR)
goto again;
return -1;
}
if (ret != pid)
goto again;
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
return -1;
return 0;
}
static int resolve_procfd_symlink(int fd, char *buf, size_t buflen)
{
int ret;
char procfd[4096];
ret = snprintf(procfd, 4096, "/proc/self/fd/%d", fd);
if (ret < 0 || ret >= 4096)
return -1;
ret = readlink(procfd, buf, buflen);
if (ret < 0 || (size_t)ret >= buflen)
return -1;
buf[ret] = '\0';
return 0;
}
static int do_tiocgptpeer(char *ptmx, char *expected_procfd_contents)
{
int ret;
int master = -1, slave = -1, fret = -1;
master = open(ptmx, O_RDWR | O_NOCTTY | O_CLOEXEC);
if (master < 0) {
fprintf(stderr, "Failed to open \"%s\": %s\n", ptmx,
strerror(errno));
return -1;
}
/*
* grantpt() makes assumptions about /dev/pts/ so ignore it. It's also
* not really needed.
*/
ret = unlockpt(master);
if (ret < 0) {
fprintf(stderr, "Failed to unlock terminal\n");
goto do_cleanup;
}
slave = ioctl(master, TIOCGPTPEER, O_RDWR | O_NOCTTY | O_CLOEXEC);
if (slave < 0) {
if (errno == EINVAL) {
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `sched.h`, `stdbool.h`, `stdio.h`, `stdlib.h`, `string.h`, `unistd.h`.
- Detected declarations: `function terminal_dup2`, `function terminal_set_stdfds`, `function login_pty`, `function wait_for_pid`, `function resolve_procfd_symlink`, `function do_tiocgptpeer`, `function verify_non_standard_devpts_mount`, `function verify_ptmx_bind_mount`, `function verify_invalid_ptmx_bind_mount`, `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.