chiark / gitweb /
Merge branch 'master' of login.chiark.greenend.org.uk:public-git/innduct
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Tue, 1 Jun 2010 20:25:43 +0000 (21:25 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Tue, 1 Jun 2010 20:25:43 +0000 (21:25 +0100)
Conflicts:

filemon.c

1  2 
filemon.c

diff --combined filemon.c
index cb054c59d25e573d9dd2464d91b5049093e4103b,7ba11b5f19d62a9b945913e0b9ea6e93c3b8d5f9..df0606b7b8b70900f41df44a9f3897bfa97aaec7
+++ b/filemon.c
@@@ -48,37 -48,45 +48,46 @@@ static void filemon_method_startfile(In
    pf->ipf= ipf;
  
    pf->wd= inotify_add_watch(filemon_inotify_fd, ipf->path, IN_MODIFY);
 -  if (pf->wd < 0) sysdie("inotify_add_watch %s", ipf->path);
 +  if (pf->wd < 0) sysdie("filemon inotify: 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);
++  dbg("filemon inotify: startfile %p wd=%d pf=%p", ipf, pf->wd, pf);
  }
  
  static void filemon_method_stopfile(InputFile *ipf, Filemon_Perfile *pf) {
 -  dbg("filemon inotify stopfile %p wd=%d pf=%p", ipf, pf->wd, pf);
 +  dbg("filemon inotify: stopfile %p wd=%d pf=%p", ipf, pf->wd, pf);
    int r= inotify_rm_watch(filemon_inotify_fd, pf->wd);
 -  if (r) syscrash("inotify_rm_watch");
 +  if (r) syscrash("filemon inotify: inotify_rm_watch");
    LIST_REMOVE(filemon_inotify_watches, 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) {
        if (isewouldblock(errno)) break;
 -      syscrash("read from inotify master");
 +      syscrash("filemon inotify: read from inotify master");
      } else if (r!=sizeof(iev)) {
 -      crash("inotify read %d bytes wanted struct of %d", r, (int)sizeof(iev));
 +      crash("filemon inotify: read %d bytes when wanted struct of %d",
 +          r, (int)sizeof(iev));
      }
      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);
    }
@@@ -100,7 -108,6 +109,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);