From 966cc2f90841aa0d44eac8322a9f953b5cda84a9 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 1 Jun 2010 20:14:32 +0100 Subject: [PATCH] make new filemon work --- filemon.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/filemon.c b/filemon.c index fe7a638..7ba11b5 100644 --- a/filemon.c +++ b/filemon.c @@ -51,7 +51,7 @@ static void filemon_method_startfile(InputFile *ipf, Filemon_Perfile *pf) { if (pf->wd < 0) sysdie("inotify_add_watch %s", ipf->path); LIST_ADDHEAD(filemon_inotify_watches, pf); - dbg("filemon inotify startfile %p wd=%d pf=%p", ipf, wd, pf); + dbg("filemon inotify startfile %p wd=%d pf=%p", ipf, pf->wd, pf); } static void filemon_method_stopfile(InputFile *ipf, Filemon_Perfile *pf) { @@ -64,6 +64,7 @@ static void filemon_method_stopfile(InputFile *ipf, Filemon_Perfile *pf) { static void *filemon_inotify_readable(oop_source *lp, int fd, oop_event e, void *u) { struct inotify_event iev; + InputFile *ipf; for (;;) { int r= read(filemon_inotify_fd, &iev, sizeof(iev)); if (r==-1) { @@ -75,9 +76,17 @@ static void *filemon_inotify_readable(oop_source *lp, int fd, Filemon_Perfile *pf; FOR_LIST_NODE(pf, filemon_inotify_watches) if (pf->wd == iev.wd) goto found; - crash("inotify read event on unknown wd=%p", iev.wd); + /* Linux seems to remember events and can produce them even after + * you've removed the watch. This means that we can't spot bugs + * where we lose track of our watches and have to just regard + * unexpected random watch events as normal. It's not a + * correctness problem as the watch is just a prod to read a file, + * which is harmless if it does not need to be read. */ + dbg("inotify read event on unknown wd=%d", iev.wd); + continue; + found: - InputFile *ipf= pf->ipf; + ipf= pf->ipf; /*dbg("filemon inotify readable read %p wd=%d", ipf, iev.wd);*/ tailing_make_readable(ipf); } @@ -99,7 +108,6 @@ int filemon_method_init(void) { } void filemon_method_dump_info(FILE *f) { - int i; fprintf(f,"inotify"); DUMPV("%d",,filemon_inotify_fd); DUMPV("%d",filemon_inotify_watches.,count); -- 2.30.2