pike.git / lib / modules / Filesystem.pmod / Monitor.pmod / basic.pike

version» Context lines:

pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:875: Inside #if HAVE_EVENTSTREAM
   }   }      constant DefaultMonitor = EventStreamMonitor;      #elseif HAVE_INOTIFY      protected System.Inotify._Instance instance;   protected Stdio.File file;    + protected string(8bit) inotify_cookie(int wd) + { +  // NB: Prefix with a NUL to make sure not to conflict with real paths. +  return sprintf("\0%8c", wd); + } +    //! Read callback for events on the Inotify file.   protected void inotify_parse(mixed id, string data)   {    MON_WERR("inotify_parse(%O, %O)...\n", id, data);    while (sizeof(data)) {    array a;    mixed err = catch {    a = System.Inotify.parse_event(data);    };       if (err) {    // TODO: might have a partial event struct here which gets completed    // by the next call?? maybe add an internal buffer.    MON_WERR("Could not parse inotify event: %s\n", describe_error(err));    return;    }    MON_WERR("### Event: %O\n", a); -  +  string(8bit) cookie = inotify_cookie(a[0]);    string path;    path = a[3]; -  if(path && monitors[path]) { -  monitors[path]->check(0); +  Monitor m; +  if((m = monitors[cookie])) { +  if (a[1] == System.Inotify.IN_IGNORED) { +  // This Inotify watch has been removed +  // (either by us or automatically). +  MON_WERR("### Monitor watch descriptor %d is no more.\n", a[0]); +  m_delete(monitors, cookie); +  } +  mixed err = catch { +  m->check(0); +  }; +  if (err) { +  master()->handler_error(err); +  }    } else { -  +  // Unknown monitor. Perform a full scan. +  MON_WERR("### Unknown monitor! Performing full scan.\n"); +  check_all();    // No need to look at the other entries if we're going to do    // a full scan. -  check_all(); +     return;    }       data = data[a[4]..];    }   }      //! Inotify-accellerated @[Monitor].   protected class InotifyMonitor   {
pike.git/lib/modules/Filesystem.pmod/Monitor.pmod/basic.pike:983: Inside #if undefined(INHIBIT_INOTIFY_MONITOR)
   System.Inotify.IN_CREATE);       MON_WERR("Registered %O with %O ==> %d.\n", path, instance, new_wd);    if (new_wd != -1) {    // We shouldn't need to be polled.    if (!initial) {    MON_WERR("Unregistering from polling.\n");    release_monitor(this);    }    wd = new_wd; +  monitors[inotify_cookie(wd)] = this;    if (initial) {    // NB: Inotify seems to not notify on preexisting paths,    // so we need to strap it along.    check();    }    return;    }    };   #endif /* !INHIBIT_INOTIFY_MONITOR */    MON_WERR("Registering %O for polling.\n", path);