tools/testing/selftests/coredump/coredump_socket_protocol_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/coredump/coredump_socket_protocol_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/coredump/coredump_socket_protocol_test.c- Extension
.c- Size
- 45825 bytes
- Lines
- 1595
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sys/stat.hsys/epoll.hsys/socket.hsys/un.hcoredump_test.h
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
Annotated Snippet
if (ret < 0) {
reason = "Unable to close detached tmpfs";
goto fail;
}
self->fd_tmpfs_detached = -1;
}
return;
fail:
/* This should never happen */
fprintf(stderr, "Failed to cleanup coredump test: %s\n", reason);
}
TEST_F(coredump, socket_request_kernel)
{
int pidfd, ret, status;
pid_t pid, pid_coredump_server;
struct stat st;
struct pidfd_info info = {};
int ipc_sockets[2];
char c;
ASSERT_TRUE(set_core_pattern("@@/tmp/coredump.socket"));
ret = socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, ipc_sockets);
ASSERT_EQ(ret, 0);
pid_coredump_server = fork();
ASSERT_GE(pid_coredump_server, 0);
if (pid_coredump_server == 0) {
struct coredump_req req = {};
int fd_server = -1, fd_coredump = -1, fd_core_file = -1, fd_peer_pidfd = -1;
int exit_code = EXIT_FAILURE;
close(ipc_sockets[0]);
fd_server = create_and_listen_unix_socket("/tmp/coredump.socket");
if (fd_server < 0) {
fprintf(stderr, "socket_request_kernel: create_and_listen_unix_socket failed: %m\n");
goto out;
}
if (write_nointr(ipc_sockets[1], "1", 1) < 0) {
fprintf(stderr, "socket_request_kernel: write_nointr to ipc socket failed: %m\n");
goto out;
}
close(ipc_sockets[1]);
fd_coredump = accept4(fd_server, NULL, NULL, SOCK_CLOEXEC);
if (fd_coredump < 0) {
fprintf(stderr, "socket_request_kernel: accept4 failed: %m\n");
goto out;
}
fd_peer_pidfd = get_peer_pidfd(fd_coredump);
if (fd_peer_pidfd < 0) {
fprintf(stderr, "socket_request_kernel: get_peer_pidfd failed\n");
goto out;
}
if (!get_pidfd_info(fd_peer_pidfd, &info)) {
fprintf(stderr, "socket_request_kernel: get_pidfd_info failed\n");
goto out;
}
if (!(info.mask & PIDFD_INFO_COREDUMP)) {
fprintf(stderr, "socket_request_kernel: PIDFD_INFO_COREDUMP not set in mask\n");
goto out;
}
if (!(info.coredump_mask & PIDFD_COREDUMPED)) {
fprintf(stderr, "socket_request_kernel: PIDFD_COREDUMPED not set in coredump_mask\n");
goto out;
}
fd_core_file = creat("/tmp/coredump.file", 0644);
if (fd_core_file < 0) {
fprintf(stderr, "socket_request_kernel: creat coredump file failed: %m\n");
goto out;
}
if (!read_coredump_req(fd_coredump, &req)) {
fprintf(stderr, "socket_request_kernel: read_coredump_req failed\n");
goto out;
}
if (!check_coredump_req(&req, COREDUMP_ACK_SIZE_VER0,
COREDUMP_KERNEL | COREDUMP_USERSPACE |
COREDUMP_REJECT | COREDUMP_WAIT)) {
Annotation
- Immediate include surface: `sys/stat.h`, `sys/epoll.h`, `sys/socket.h`, `sys/un.h`, `coredump_test.h`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.