title: inotify fails to react on IN_DELETE
body: <p>I have the following (crude) function, which continually watches a directory for new files and files being deleted, recording such changes. It correctly records all new files and directories, but doesn't seem to react at all to files or directories being deleted.</p>
  
  <p>It appears to be the <code>read()</code> call which doesn't return as it should when files are being deleted, though it does for files being created.</p>
  
  <p>The function is being called as one of two independent threads, though at present the other thread doesn't do anything (just an empty, infinite loop as a placeholder).</p>
  
  <pre><code>void* watchfs(void* arg) {
      int infp, watch, length, i ;
      char buffer[EVENT_BUF_LEN] ;
      struct inotify_event* event ;
  
      if ((infp = inotify_init()) &lt; 0) {
          fatal("inotify: Could not initialize") ;
      }
  
      watch = inotify_add_watch(infp, userdir, IN_CREATE | IN_DELETE) ;
  
      for (;;) {
          length = read(infp, buffer, EVENT_BUF_LEN) ;
          if (length &lt; 0) {
              fatal("inotify: Could not read events") ;
          }
  
          i = 0 ;
          while (i &lt; length) {
              event = (struct inotify_event*) &amp;buffer[i] ;
  
              if (event-&gt;len) {
                  if (event-&gt;mask &amp; IN_CREATE) {
                      if (event-&gt;mask &amp; IN_ISDIR) {
                          record(LOG_FILESYS, "New directory created") ;
                      } else {
                          record(LOG_FILESYS, "New file created") ;
                      }
                  } else if (event-&gt;mask &amp; IN_DELETE) {
                      if (event-&gt;mask &amp; IN_ISDIR) {
                          record(LOG_FILESYS, "Directory deleted") ;
                      } else {
                          record(LOG_FILESYS, "File deleted") ;
                      }
                  }
              }
  
              i += EVENT_SIZE + event-&gt;len ;
          }
      }
  
      inotify_rm_watch(infp, watch) ;
      close(infp) ;
  
      return 0 ;
  }
  </code></pre>