diff --git a/src/iwatch.c b/src/iwatch.c index 48bedea1..ee241a66 100644 --- a/src/iwatch.c +++ b/src/iwatch.c @@ -48,7 +48,7 @@ int iwatch_init(struct iwatch *iw) iw->fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); if (iw->fd < 0) { - _pe("inotify_init()"); + _pe("Failed creating inotify descriptor"); return -1; } initialized = 1; @@ -90,7 +90,7 @@ int iwatch_add(struct iwatch *iw, char *file, uint32_t mask) wd = inotify_add_watch(iw->fd, path, IWATCH_MASK | mask); if (wd < 0) { - _pe("inotify_add_watch(%s)", path); + _pe("Failed adding watcher for %s", path); free(path); return -1; } diff --git a/src/iwatch.h b/src/iwatch.h index b59c3fb9..adff92a3 100644 --- a/src/iwatch.h +++ b/src/iwatch.h @@ -29,9 +29,16 @@ #include #include +#ifndef IN_MASK_CREATE +#define IN_MASK_CREATE 0x10000000 /* since Linux 4.18 */ +#endif -/* Monitors changes to both directories and files by default */ -#define IWATCH_MASK (IN_CREATE | IN_DELETE | IN_MODIFY | IN_ATTRIB | IN_MOVE) +/* + * Monitors changes to both directories and files by default, but only + * add watcher once (IN_MASK_CREATE) to avoid clobbering any already + * monitored paths. + */ +#define IWATCH_MASK (IN_CREATE | IN_DELETE | IN_MODIFY | IN_ATTRIB | IN_MOVE | IN_MASK_CREATE) struct iwatch_path { TAILQ_ENTRY(iwatch_path) link;