tools/gpio/gpio-watch.c
Source file repositories/reference/linux-study-clean/tools/gpio/gpio-watch.c
File Facts
- System
- Linux kernel
- Corpus path
tools/gpio/gpio-watch.c- Extension
.c- Size
- 2165 bytes
- Lines
- 101
- 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
ctype.herrno.hfcntl.hinttypes.hlinux/gpio.hpoll.hstdbool.hstdio.hstdlib.hstring.hsys/ioctl.hunistd.h
Detected Declarations
function Copyright
Annotated Snippet
if (ret) {
perror("unable to set up line watch");
return EXIT_FAILURE;
}
}
pfd.fd = fd;
pfd.events = POLLIN | POLLPRI;
for (;;) {
ret = poll(&pfd, 1, 5000);
if (ret < 0) {
perror("error polling the linechanged fd");
return EXIT_FAILURE;
} else if (ret > 0) {
memset(&chg, 0, sizeof(chg));
rd = read(pfd.fd, &chg, sizeof(chg));
if (rd < 0 || rd != sizeof(chg)) {
if (rd != sizeof(chg))
errno = EIO;
perror("error reading line change event");
return EXIT_FAILURE;
}
switch (chg.event_type) {
case GPIO_V2_LINE_CHANGED_REQUESTED:
event = "requested";
break;
case GPIO_V2_LINE_CHANGED_RELEASED:
event = "released";
break;
case GPIO_V2_LINE_CHANGED_CONFIG:
event = "config changed";
break;
default:
fprintf(stderr,
"invalid event type received from the kernel\n");
return EXIT_FAILURE;
}
printf("line %u: %s at %" PRIu64 "\n",
chg.info.offset, event, (uint64_t)chg.timestamp_ns);
}
}
return 0;
err_usage:
printf("%s: <gpiochip> <line0> <line1> ...\n", argv[0]);
return EXIT_FAILURE;
}
Annotation
- Immediate include surface: `ctype.h`, `errno.h`, `fcntl.h`, `inttypes.h`, `linux/gpio.h`, `poll.h`, `stdbool.h`, `stdio.h`.
- Detected declarations: `function Copyright`.
- 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.