wendy

inotify based node watcher
git clone git://git.2f30.org/wendy
Log | Files | Refs | README | LICENSE

commit c3e9487830fe62b4adcf4ad22053485a435a1fac
parent e98930f741f75b078057ea54e5a252f85b10dc98
Author: Willy Goiffon <dev@z3bra.org>
Date:   Fri, 28 Feb 2020 20:23:27 +0100

Add flag to only monitor directories

Use inotify mechanism IN_ONLYDIR to watch directories only. This makes
it easier to limit the number of watchers when watching directories
recursively.

Diffstat:
Mwendy.c | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/wendy.c b/wendy.c @@ -42,7 +42,7 @@ int verbose = 0; void usage(char *name) { - fprintf(stderr, "usage: %s [-vr] [-m mask] [-f file]\n", name); + fprintf(stderr, "usage: %s [-vdr] [-m mask] [-f file]\n", name); exit(1); } @@ -103,7 +103,7 @@ wdpath(struct inotify_event *e) int main (int argc, char **argv) { - int fd, rflag = 0; + int fd, dflag = 0, rflag = 0; uint8_t buf[EVSZ]; uint32_t mask = MASK; ssize_t len, off = 0; @@ -118,6 +118,9 @@ main (int argc, char **argv) perror("inotify_init"); ARGBEGIN { + case 'd': + dflag = 1; + break; case 'r': rflag = 1; break; @@ -134,6 +137,10 @@ main (int argc, char **argv) usage(argv0); } ARGEND; + /* ensure that only directories are watched for */ + if (dflag) + mask |= IN_ONLYDIR; + while (!SLIST_EMPTY(&head) && (off || (len=read(fd, buf, EVSZ))>0)) { /* cast buffer into the event structure */ @@ -153,7 +160,7 @@ main (int argc, char **argv) switch(e->mask & IN_ALL_EVENTS) { case IN_CREATE: /* Watch subdirectories upon creation */ - if (rflag && e->mask & IN_ISDIR) { + if (rflag) { snprintf(path, PATH_MAX, "%s/%s", w->path, e->name); watch(fd, path, mask); }