wendy

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

commit 6c09b1154ee762731099b081edbb39ae686df4a0
parent f1ecd626eacbcac98fe252a4b7b5a463acaed2d6
Author: Willy Goiffon <dev@z3bra.org>
Date:   Fri, 28 Feb 2020 20:01:17 +0100

Add flag to watch directories recursively

Diffstat:
Mwendy.c | 18++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/wendy.c b/wendy.c @@ -41,7 +41,7 @@ int verbose = 1; void usage(char *name) { - fprintf(stderr, "usage: %s [-v] [-m mask] [-f file] [cmd [args..]]\n", name); + fprintf(stderr, "usage: %s [-vr] [-m mask] [-f file]\n", name); exit(1); } @@ -102,10 +102,11 @@ wdpath(struct inotify_event *e) int main (int argc, char **argv) { - int fd; + int fd, rflag = 0; uint8_t buf[EVSZ]; uint32_t mask = IN_ALL_EVENTS; ssize_t len, off = 0; + char path[PATH_MAX]; char *argv0 = NULL; struct watcher *tmp, *w; struct inotify_event *e; @@ -116,6 +117,9 @@ main (int argc, char **argv) perror("inotify_init"); ARGBEGIN { + case 'r': + rflag = 1; + break; case 'm': mask = atoi(EARGF(usage(argv0))); break; @@ -145,6 +149,16 @@ main (int argc, char **argv) fflush(stdout); } + switch(e->mask & IN_ALL_EVENTS) { + case IN_CREATE: + /* Watch subdirectories upon creation */ + if (rflag && e->mask & IN_ISDIR) { + snprintf(path, PATH_MAX, "%s/%s", w->path, e->name); + watch(fd, path, mask); + } + break; + } + /* * IN_IGNORED is triggered when a file watched * doesn't exists anymore. In this case we first try to