tools/testing/selftests/net/af_unix/scm_rights.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/af_unix/scm_rights.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/net/af_unix/scm_rights.c- Extension
.c- Size
- 7085 bytes
- Lines
- 382
- 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
sched.hstdio.hstring.hunistd.hsys/types.hsys/socket.hsys/un.hkselftest_harness.h
Detected Declarations
function count_socketsfunction create_listenersfunction create_socketpairsfunction __create_socketsfunction __close_socketsfunction __send_fd
Annotated Snippet
if (variant->disabled) {
ret = setsockopt(self->fd[i], SOL_SOCKET, SO_PASSRIGHTS,
&(int){0}, sizeof(int));
ASSERT_EQ(0, ret);
}
addrlen = sizeof(addr);
ret = getsockname(self->fd[i], (struct sockaddr *)&addr, &addrlen);
ASSERT_EQ(0, ret);
self->fd[i + 1] = socket(AF_UNIX, SOCK_STREAM, 0);
ASSERT_LE(0, self->fd[i + 1]);
ret = connect(self->fd[i + 1], (struct sockaddr *)&addr, addrlen);
ASSERT_EQ(0, ret);
}
}
static void create_socketpairs(struct __test_metadata *_metadata,
FIXTURE_DATA(scm_rights) *self,
const FIXTURE_VARIANT(scm_rights) *variant,
int n)
{
int i, ret;
ASSERT_GE(sizeof(self->fd) / sizeof(int), n);
for (i = 0; i < n * 2; i += 2) {
ret = socketpair(AF_UNIX, variant->type, 0, self->fd + i);
ASSERT_EQ(0, ret);
if (variant->disabled) {
ret = setsockopt(self->fd[i], SOL_SOCKET, SO_PASSRIGHTS,
&(int){0}, sizeof(int));
ASSERT_EQ(0, ret);
}
}
}
static void __create_sockets(struct __test_metadata *_metadata,
FIXTURE_DATA(scm_rights) *self,
const FIXTURE_VARIANT(scm_rights) *variant,
int n)
{
ASSERT_LE(n * 2, sizeof(self->fd) / sizeof(self->fd[0]));
if (variant->test_listener)
create_listeners(_metadata, self, variant, n);
else
create_socketpairs(_metadata, self, variant, n);
}
static void __close_sockets(struct __test_metadata *_metadata,
FIXTURE_DATA(scm_rights) *self,
int n)
{
int i, ret;
ASSERT_GE(sizeof(self->fd) / sizeof(int), n);
for (i = 0; i < n * 2; i++) {
ret = close(self->fd[i]);
ASSERT_EQ(0, ret);
}
}
void __send_fd(struct __test_metadata *_metadata,
const FIXTURE_DATA(scm_rights) *self,
const FIXTURE_VARIANT(scm_rights) *variant,
int inflight, int receiver)
{
#define MSG "x"
#define MSGLEN 1
int fds[2] = {
self->fd[inflight * 2],
self->fd[inflight * 2],
};
char cmsg_buf[CMSG_SPACE(sizeof(fds))];
struct iovec iov = {
.iov_base = MSG,
.iov_len = MSGLEN,
};
struct msghdr msg = {
.msg_name = NULL,
.msg_namelen = 0,
.msg_iov = &iov,
.msg_iovlen = 1,
.msg_control = cmsg_buf,
.msg_controllen = sizeof(cmsg_buf),
};
Annotation
- Immediate include surface: `sched.h`, `stdio.h`, `string.h`, `unistd.h`, `sys/types.h`, `sys/socket.h`, `sys/un.h`, `kselftest_harness.h`.
- Detected declarations: `function count_sockets`, `function create_listeners`, `function create_socketpairs`, `function __create_sockets`, `function __close_sockets`, `function __send_fd`.
- 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.