tAdd flag to only monitor directories - wendy - watch files/directories and run commands on any event
 (HTM) git clone git://z3bra.org/wendy
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit c3e9487830fe62b4adcf4ad22053485a435a1fac
 (DIR) parent e98930f741f75b078057ea54e5a252f85b10dc98
 (HTM) 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:
         M wendy.c                             |      13 ++++++++++---
       
       1 file changed, 10 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/wendy.c b/wendy.c
       t@@ -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);
        }
        
       t@@ -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;
       t@@ -118,6 +118,9 @@ main (int argc, char **argv)
                        perror("inotify_init");
        
                ARGBEGIN {
       +        case 'd':
       +                dflag = 1;
       +                break;
                case 'r':
                        rflag = 1;
                        break;
       t@@ -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 */
       t@@ -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);
                                }