`poll` and `epoll_wait` on an inotify fd time out after a file event, where Linux reports `POLLIN`
Maintainer antworten meist innerhalb von 2 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 55/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- c
- Bereich
- operating-systems
Rechercherichtung
Start with src/syscall/inotify.c to trace how kqueue events reach the inotify pipe, then inspect src/syscall/poll.c and the poll case in tests/test-inotify.c. Run the reproduction or the inotify tests and compare poll and epoll readiness with Linux. Done means both report the inotify fd readable after a file event, and the test fails if poll returns 0.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
What happens
After a watched directory gets an event, poll and epoll_wait on the inotify fd return 0 at their timeout, while a read on the same fd returns the event. On Linux both report the fd readable.
Evidence
On upstream main a20dfab, the probe below compared with elfuse-probe-diff against Linux 6.18.60:
| call | elfuse | Linux |
|---|---|---|
poll(fd, POLLIN, 1000) after open(O_CREAT) in the watched dir |
0 | 1, POLLIN |
epoll_wait(ep, 1, 1000) |
0 | 1 |
read(fd) |
> 0 | > 0 |
tests/test-inotify.c does not catch this: its poll case calls PASS() when poll returns 0 ("inotify via kqueue may not fire within this short timeout").
Cause
Checked by reading. In src/syscall/inotify.c the guest fd's host fd is the read end of the instance's self-pipe (fd_alloc(FD_INOTIFY, pipefd[0], ...) in sys_inotify_init1), and the file events arrive on a separate kqueue. Only pipe_signal writes the pipe, and its two callers, collect_events and the blocking wait, both run inside inotify_read. src/syscall/poll.c has no inotify case, so poll, ppoll, select and epoll_wait see the pipe empty until the guest reads.
Reproduce
#include <fcntl.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/epoll.h>
#include <sys/inotify.h>
#include <unistd.h>
int main(void)
{
char dir[] = "/tmp/inotify-poll-XXXXXX";
if (!mkdtemp(dir))
return 1;
int fd = inotify_init1(IN_NONBLOCK);
if (inotify_add_watch(fd, dir, IN_CREATE) < 0)
return 1;
int ep = epoll_create1(0);
struct epoll_event ev = {.events = EPOLLIN, .data.fd = fd};
epoll_ctl(ep, EPOLL_CTL_ADD, fd, &ev);
char path[64];
snprintf(path, sizeof(path), "%s/f", dir);
close(open(path, O_CREAT | O_WRONLY, 0644));
struct pollfd pfd = {.fd = fd, .events = POLLIN};
int pr = poll(&pfd, 1, 1000);
printf("poll = %d revents=%#x\n", pr, pfd.revents);
struct epoll_event out;
printf("epoll_wait = %d\n", epoll_wait(ep, &out, 1, 1000));
char buf[256];
ssize_t n = read(fd, buf, sizeof(buf));
printf("read > 0: %d\n", n > 0);
unlink(path);
rmdir(dir);
return 0;
}
Possible fix
Make the kqueue event raise the pipe byte without a guest read: for example, a watcher that waits on each instance's kq_fd and calls collect_events (which signals the pipe), or a poll/epoll hook for FD_INOTIFY that runs collect_events before it waits and adds kq_fd to the host wait set. Either way, tests/test-inotify.c should fail when poll returns 0.
Origin
Follow-up from #525. Related: #412 (a dup of an inotify fd has no state; a different cause).
- Vorherrschende Sprache
- C
- Sterne
- 287
- Forks
- 33
- Ø Merge
- 2 T. 17 Std.
- Gemergte PRs (30 T.)
- 18
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus sysprog21/elfuse
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 80/100
Maintainer antworten meist innerhalb von 2 Tagen
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
Maintainer antworten meist innerhalb von 2 Tagen
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 2 Tagen
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 2 Tagen
Alle Issues in sysprog21/elfuse
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
OpenTenBase/OpenTenBase#557 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Claude:NeedsReview GPT:ConfirmedBug GPT:NeedsReview triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
open5gs/open5gs#5141 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
CI: MSYS2 jobs fail — mingw python3 package renamed upstream to pythonEvtl. vergeben @ronaldtse hat das heute übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 95/100
-
Typos and grammar issuesOffenbug good first issue
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
TanvirHasanAkash/CSE114-Lab-Project-72_B2_G2#37 ·
Maintainer antworten meist innerhalb von 1 Tag
-
issue: bug report
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
Maintainer antworten meist innerhalb von 2 Tagen