Archived
1
0
Fork 0

inotify.c: call add/rmwatch on files to (symbolic links).

This commit is contained in:
Henrik Hautakoski 2011-02-28 19:29:47 +01:00
parent 361f30c6b3
commit 2d5f94374c

View file

@ -46,7 +46,7 @@ static int inotify_watch(const char *path) {
int wd = inotify_add_watch(fd, path, WATCH_MASK); int wd = inotify_add_watch(fd, path, WATCH_MASK);
if (wd < 0) { if (wd < 0) {
if (errno != EACCES) if (errno != EACCES && errno != ENOTDIR)
logerrno(LOG_CRIT, "inotify_watch", errno); logerrno(LOG_CRIT, "inotify_watch", errno);
return -1; return -1;
} }
@ -122,13 +122,17 @@ static int rmwatch(const char *path, const char *name) {
return -1; return -1;
} }
logmsg(LOG_DEBUG, "remove watch: %i %s", wd, fpath); if (inotify_unmap_path(fpath) == 0) {
free(fpath);
if (inotify_rm_watch(fd, wd) < 0) { logmsg(LOG_DEBUG, "remove watch: %i %s", wd, fpath);
logerrno(LOG_CRIT, "intotify_rm_watch", errno); if (inotify_rm_watch(fd, wd) < 0) {
return -1; logerrno(LOG_CRIT, "intotify_rm_watch", errno);
free(fpath);
return -1;
}
} }
free(fpath);
return 0; return 0;
} }
@ -172,24 +176,14 @@ static void proc_event(inoev *iev) {
queue_enqueue(event_queue, event); queue_enqueue(event_queue, event);
switch(iev->mask) { switch(iev->mask) {
case IN_CREATE : case IN_CREATE :
if (event->dir) {
logmsg(LOG_DEBUG, "IN_CREATE on directory, adding");
addwatch(event->path, event->filename);
}
type = NOTIFY_CREATE;
break;
case IN_MOVED_TO : case IN_MOVED_TO :
if (event->dir) { addwatch(event->path, event->filename);
logmsg(LOG_DEBUG, "IN_MOVED_TO on directory, adding");
addwatch(event->path, event->filename);
}
type = NOTIFY_CREATE; type = NOTIFY_CREATE;
break; break;
case IN_MOVED_FROM :
if (event->dir)
rmwatch(event->path, event->filename);
case IN_DELETE : case IN_DELETE :
case IN_MOVED_FROM :
rmwatch(event->path, event->filename);
type = NOTIFY_DELETE; type = NOTIFY_DELETE;
break; break;
} }