tools/testing/selftests/ptrace/peeksiginfo.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/ptrace/peeksiginfo.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/ptrace/peeksiginfo.c- Extension
.c- Size
- 4743 bytes
- Lines
- 220
- 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
stdio.hsignal.hunistd.herrno.hlinux/types.hsys/wait.hsys/syscall.hsys/user.hsys/mman.hlinux/ptrace.h
Detected Declarations
function sys_rt_sigqueueinfofunction sys_rt_tgsigqueueinfofunction sys_ptracefunction fprintffunction check_direct_pathfunction main
Annotated Snippet
if (ret == -1) {
err("ptrace() failed: %m\n");
goto out;
}
if (ret == 0)
break;
for (j = 0; j < ret; j++, i++) {
if (siginfo[j].si_code == si_code &&
siginfo[j].si_int == i)
continue;
err("%d: Wrong siginfo i=%d si_code=%d si_int=%d\n",
shared, i, siginfo[j].si_code, siginfo[j].si_int);
goto out;
}
}
if (i != SIGNR) {
err("Only %d signals were read\n", i);
goto out;
}
exit_code = 0;
out:
return exit_code;
}
int main(int argc, char *argv[])
{
siginfo_t siginfo;
int i, exit_code = 1;
sigset_t blockmask;
pid_t child;
sigemptyset(&blockmask);
sigaddset(&blockmask, SIGRTMIN);
sigprocmask(SIG_BLOCK, &blockmask, NULL);
child = fork();
if (child == -1) {
err("fork() failed: %m");
return 1;
} else if (child == 0) {
pid_t ppid = getppid();
while (1) {
if (ppid != getppid())
break;
sleep(1);
}
return 1;
}
/* Send signals in process-wide and per-thread queues */
for (i = 0; i < SIGNR; i++) {
siginfo.si_code = TEST_SICODE_SHARE;
siginfo.si_int = i;
sys_rt_sigqueueinfo(child, SIGRTMIN, &siginfo);
siginfo.si_code = TEST_SICODE_PRIV;
siginfo.si_int = i;
sys_rt_tgsigqueueinfo(child, child, SIGRTMIN, &siginfo);
}
if (sys_ptrace(PTRACE_ATTACH, child, NULL, NULL) == -1)
return 1;
waitpid(child, NULL, 0);
/* Dump signals one by one*/
if (check_direct_path(child, 0, 1))
goto out;
/* Dump all signals for one call */
if (check_direct_path(child, 0, SIGNR))
goto out;
/*
* Dump signal from the process-wide queue.
* The number of signals is not multiple to the buffer size
*/
if (check_direct_path(child, 1, 3))
goto out;
if (check_error_paths(child))
goto out;
printf("PASS\n");
exit_code = 0;
out:
Annotation
- Immediate include surface: `stdio.h`, `signal.h`, `unistd.h`, `errno.h`, `linux/types.h`, `sys/wait.h`, `sys/syscall.h`, `sys/user.h`.
- Detected declarations: `function sys_rt_sigqueueinfo`, `function sys_rt_tgsigqueueinfo`, `function sys_ptrace`, `function fprintf`, `function check_direct_path`, `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.