tools/testing/selftests/uevent/uevent_filtering.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/uevent/uevent_filtering.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/uevent/uevent_filtering.c- Extension
.c- Size
- 10522 bytes
- Lines
- 488
- 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
errno.hfcntl.hlinux/netlink.hsignal.hstdbool.hstdio.hstdlib.hstring.hsys/prctl.hsys/socket.hsched.hsys/eventfd.hsys/stat.hsys/syscall.hsys/types.hsys/wait.hunistd.hkselftest_harness.h
Detected Declarations
function read_nointrfunction write_nointrfunction wait_for_pidfunction uevent_listenerfunction trigger_ueventfunction set_death_signalfunction do_testfunction signal_handler
Annotated Snippet
if (ret < 0) {
fprintf(stderr,
"%s - Failed to unshare user namespace\n",
strerror(errno));
goto on_error;
}
}
if (post_flags & CLONE_NEWNET) {
ret = unshare(CLONE_NEWNET);
if (ret < 0) {
fprintf(stderr,
"%s - Failed to unshare network namespace\n",
strerror(errno));
goto on_error;
}
}
ret = write_nointr(sync_fd, &sync_add, sizeof(sync_add));
close(sync_fd);
if (ret != sizeof(sync_add)) {
ret = -1;
fprintf(stderr, "Failed to synchronize with parent process\n");
goto on_error;
}
ret = 0;
for (;;) {
ssize_t r;
r = recvmsg(sk_fd, &hdr, 0);
if (r <= 0) {
fprintf(stderr, "%s - Failed to receive uevent\n", strerror(errno));
ret = -1;
break;
}
/* ignore libudev messages */
if (memcmp(buf, "libudev", 8) == 0)
continue;
/* ignore uevents we didn't trigger */
if (memcmp(buf, __UEVENT_HEADER, __UEVENT_HEADER_LEN) != 0)
continue;
if (!expect_uevent) {
fprintf(stderr, "Received unexpected uevent:\n");
ret = -1;
}
if (TH_LOG_ENABLED) {
/* If logging is enabled dump the received uevent. */
(void)write_nointr(STDERR_FILENO, buf, r);
(void)write_nointr(STDERR_FILENO, "\n", 1);
}
break;
}
on_error:
close(sk_fd);
return ret;
}
int trigger_uevent(unsigned int times)
{
int fd, ret;
unsigned int i;
fd = open(__DEV_FULL, O_RDWR | O_CLOEXEC);
if (fd < 0) {
if (errno != ENOENT)
return -EINVAL;
return -1;
}
for (i = 0; i < times; i++) {
ret = write_nointr(fd, "add\n", sizeof("add\n") - 1);
if (ret < 0) {
fprintf(stderr, "Failed to trigger uevent\n");
break;
}
}
close(fd);
return ret;
}
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `linux/netlink.h`, `signal.h`, `stdbool.h`, `stdio.h`, `stdlib.h`, `string.h`.
- Detected declarations: `function read_nointr`, `function write_nointr`, `function wait_for_pid`, `function uevent_listener`, `function trigger_uevent`, `function set_death_signal`, `function do_test`, `function signal_handler`.
- 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.