tools/iio/iio_event_monitor.c
Source file repositories/reference/linux-study-clean/tools/iio/iio_event_monitor.c
File Facts
- System
- Linux kernel
- Corpus path
tools/iio/iio_event_monitor.c- Extension
.c- Size
- 11745 bytes
- Lines
- 472
- 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
unistd.hstdlib.hdirent.hstdbool.hstdio.herrno.hstring.hpoll.hfcntl.hsys/ioctl.hiio_utils.hlinux/iio/events.hlinux/iio/types.h
Detected Declarations
function event_is_knownfunction print_eventfunction enable_eventsfunction main
Annotated Snippet
if (iioutils_check_suffix(ent->d_name, "_en")) {
printf("%sabling: %s\n",
enable ? "En" : "Dis",
ent->d_name);
ret = write_sysfs_int(ent->d_name, evdir,
enable);
if (ret < 0)
fprintf(stderr, "Failed to enable/disable %s\n",
ent->d_name);
}
}
if (closedir(dp) == -1) {
perror("Enabling/disabling channels: "
"Failed to close directory");
return;
}
}
int main(int argc, char **argv)
{
struct iio_event_data event;
const char *device_name;
char *dev_dir_name = NULL;
char *chrdev_name;
int ret;
int dev_num;
int fd, event_fd;
bool all_events = false;
if (argc == 2) {
device_name = argv[1];
} else if (argc == 3) {
device_name = argv[2];
if (!strcmp(argv[1], "-a"))
all_events = true;
} else {
fprintf(stderr,
"Usage: iio_event_monitor [options] <device_name>\n"
"Listen and display events from IIO devices\n"
" -a Auto-activate all available events\n");
return -1;
}
dev_num = find_type_by_name(device_name, "iio:device");
if (dev_num >= 0) {
printf("Found IIO device with name %s with device number %d\n",
device_name, dev_num);
ret = asprintf(&chrdev_name, "/dev/iio:device%d", dev_num);
if (ret < 0)
return -ENOMEM;
/* Look up sysfs dir as well if we can */
ret = asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num);
if (ret < 0)
return -ENOMEM;
} else {
/*
* If we can't find an IIO device by name assume device_name is
* an IIO chrdev
*/
chrdev_name = strdup(device_name);
if (!chrdev_name)
return -ENOMEM;
}
if (all_events && dev_dir_name)
enable_events(dev_dir_name, 1);
fd = open(chrdev_name, 0);
if (fd == -1) {
ret = -errno;
fprintf(stderr, "Failed to open %s\n", chrdev_name);
goto error_free_chrdev_name;
}
ret = ioctl(fd, IIO_GET_EVENT_FD_IOCTL, &event_fd);
if (ret == -1 || event_fd == -1) {
ret = -errno;
if (ret == -ENODEV)
fprintf(stderr,
"This device does not support events\n");
else
fprintf(stderr, "Failed to retrieve event fd\n");
if (close(fd) == -1)
perror("Failed to close character device file");
goto error_free_chrdev_name;
}
if (close(fd) == -1) {
Annotation
- Immediate include surface: `unistd.h`, `stdlib.h`, `dirent.h`, `stdbool.h`, `stdio.h`, `errno.h`, `string.h`, `poll.h`.
- Detected declarations: `function event_is_known`, `function print_event`, `function enable_events`, `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.