struct stat sb;
int r, fd, presel;
enum action sel = SEL_RUNARG + 1;
+ bool dir_changed = FALSE;
xstrlcpy(path, ipath, PATH_MAX);
xstrlcpy(fltr, ifilter, LINE_MAX);
begin:
#ifdef LINUX_INOTIFY
- if (inotify_wd >= 0)
+ if (dir_changed && inotify_wd >= 0) {
inotify_rm_watch(inotify_fd, inotify_wd);
+ inotify_wd = -1;
+ dir_changed = FALSE;
+ }
#elif defined(BSD_KQUEUE)
- if (event_fd >= 0)
+ if (dir_changed && event_fd >= 0) {
close(event_fd);
+ event_fd = -1;
+ dir_changed = FALSE;
+ }
#endif
if (populate(path, oldpath, fltr) == -1) {
}
#ifdef LINUX_INOTIFY
- inotify_wd = inotify_add_watch(inotify_fd, path, INOTIFY_MASK);
+ if (inotify_wd == -1)
+ inotify_wd = inotify_add_watch(inotify_fd, path, INOTIFY_MASK);
#elif defined(BSD_KQUEUE)
- event_fd = open(path, O_EVTONLY);
- if (event_fd >= 0)
- EV_SET(&events_to_monitor[0], event_fd, EVFILT_VNODE, EV_ADD | EV_CLEAR, KQUEUE_FFLAGS, 0, path);
+ if (event_fd == -1) {
+ event_fd = open(path, O_EVTONLY);
+ if (event_fd >= 0)
+ EV_SET(&events_to_monitor[0], event_fd, EVFILT_VNODE, EV_ADD | EV_CLEAR, KQUEUE_FFLAGS, 0, path);
+ }
#endif
for (;;) {
/* Save last working directory */
xstrlcpy(lastdir, path, PATH_MAX);
+ dir_changed = TRUE;
+
xstrlcpy(path, dir, PATH_MAX);
/* Reset filter */
xstrlcpy(fltr, ifilter, LINE_MAX);
/* Save last working directory */
xstrlcpy(lastdir, path, PATH_MAX);
+ dir_changed = TRUE;
xstrlcpy(path, newpath, PATH_MAX);
oldpath[0] = '\0';
/* Save last working directory */
xstrlcpy(lastdir, path, PATH_MAX);
+ dir_changed = TRUE;
/* Save the newly opted dir in path */
xstrlcpy(path, newpath, PATH_MAX);
/* Save last working directory */
xstrlcpy(lastdir, path, PATH_MAX);
+ dir_changed = TRUE;
xstrlcpy(path, dstdir, PATH_MAX);
oldpath[0] = '\0';
xstrlcpy(newpath, tmp, PATH_MAX);
xstrlcpy(lastdir, path, PATH_MAX);
+ dir_changed = TRUE;
xstrlcpy(path, newpath, PATH_MAX);
oldpath[0] = '\0';
/* Reset filter */
/* Save last working directory */
xstrlcpy(lastdir, path, PATH_MAX);
+ dir_changed = TRUE;
/* Save the newly opted dir in path */
xstrlcpy(path, newpath, PATH_MAX);