URI: 
       tNow recreate the file watch when getting IN_IGNORED event - wendy - watch files/directories and run commands on any event
  HTML git clone git://z3bra.org/wendy
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit e5ce4d46a667ade7fc70dbf71579f7c4029943c7
   DIR parent 6a8cc070dbd404d740009f71bec92c8c3593cf2b
  HTML Author: z3bra <willy@mailoo.org>
       Date:   Sun, 16 Feb 2014 18:17:49 +0100
       
       Now recreate the file watch when getting IN_IGNORED event
       
       Diffstat:
         M wendy.c                             |      19 ++++++++++++++-----
       
       1 file changed, 14 insertions(+), 5 deletions(-)
       ---
   DIR diff --git a/wendy.c b/wendy.c
       t@@ -128,11 +128,14 @@ main (int argc, char **argv)
            if (fd < 0)
                perror("inotify_init");
        
       +add_watch:
            /* add a watcher on the file */
            wd  = inotify_add_watch(fd, file, mask);
        
       -    if (wd < 0)
       +    if (wd < 0) {
                perror("inotify_add_watch");
       +        exit(1);
       +    }
        
            if (!quiet) {
                printf( "watching file %s with event mask %u\n", file, mask);
       t@@ -140,6 +143,7 @@ main (int argc, char **argv)
        
            /* start looping */
            for (;;) {
       +
                /* get every event raised, and queue them */
                len = read(fd, buf, BUF_LEN);
        
       t@@ -149,15 +153,20 @@ main (int argc, char **argv)
        
                i = 0;
        
       -
                /* treat all events queued */
                while (i < len) {
        
                    /* get events one by one */
       -            ev = (struct inotify_event *) &buf[i]; 
       +            ev = (struct inotify_event *) &buf[i];
       +
       +            if (ev->mask & IN_IGNORED) {
       +                printf("File watch removed. Recreating inotify watch\n");
       +                goto add_watch;
       +            }
        
       -            if (!quiet && ev->len > 0) {
       -                printf("event on file %s: %u\n", ev->name, ev->mask);
       +            if (!quiet) {
       +                printf("event on file %s: %u\n",
       +                        ev->len ? ev->name : file, ev->mask);
                    }
        
                    /*