Index: trunk/src/sh_fInotify.c
===================================================================
--- trunk/src/sh_fInotify.c	(revision 368)
+++ trunk/src/sh_fInotify.c	(revision 371)
@@ -143,4 +143,10 @@
 	}
     }
+  else if (arg != NULL && arg->initval < 0 &&
+      (sh.flag.isdaemon != S_TRUE && sh.flag.loop != S_TRUE))
+    {
+      sh.flag.inotify = 0;
+      return SH_MOD_FAILED;
+    }
   else if (arg != NULL && arg->initval == SH_MOD_THREAD &&
 	   (sh.flag.isdaemon == S_TRUE || sh.flag.loop == S_TRUE))
@@ -162,4 +168,5 @@
   ssize_t len = -1;
   char *  buffer = SH_ALLOC(16384);
+  static int count = 0;
 
   if (ShfInotifyActive == S_FALSE)
@@ -175,5 +182,5 @@
   /* Blocking read from inotify file descriptor.
    */
-  len = sh_inotify_read(buffer, 16384);
+  len = sh_inotify_read_timeout(buffer, 16384, 1);
   
   if (len > 0)
@@ -203,4 +210,12 @@
    */ 
   sh_inotify_recheck_watches (&sh_file_watches, &sh_file_missing);
+
+  ++count;
+
+  if (count >= 10)
+    {
+      count = 0; /* Re-expand glob patterns to discover added files */
+      sh_files_check_globFilePatterns();
+    }
 
   return 0;
@@ -274,5 +289,6 @@
   SH_MUTEX_LOCK(mutex_thread_nolog);
   sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_SUBGEN, 
-		  _("Cannot set max_user_watches"), _("sh_fInotify_set_nwatches"));
+		  _("Cannot set max_user_watches"), 
+		  _("sh_fInotify_set_nwatches"));
   SH_MUTEX_UNLOCK(mutex_thread_nolog);
   return;
@@ -353,4 +369,32 @@
   unsigned long check_mask;
   char * filename;
+  extern int flag_err_debug;
+
+  if (flag_err_debug == SL_TRUE)
+    {
+      char dbgbuf[256];
+      sl_strlcpy (dbgbuf, "inotify mask: ", sizeof(dbgbuf));
+      if (event->mask & IN_ACCESS) sl_strlcat(dbgbuf, "IN_ACCESS ", sizeof(dbgbuf));
+      if (event->mask & IN_ATTRIB) sl_strlcat(dbgbuf, "IN_ATTRIB ", sizeof(dbgbuf));
+      if (event->mask & IN_CLOSE_WRITE) sl_strlcat(dbgbuf, "IN_CLOSE_WRITE ", sizeof(dbgbuf));
+      if (event->mask & IN_CLOSE_NOWRITE) sl_strlcat(dbgbuf, "IN_CLOSE_NOWRITE ", sizeof(dbgbuf));
+      if (event->mask & IN_CREATE) sl_strlcat(dbgbuf, "IN_CREATE ", sizeof(dbgbuf));
+      if (event->mask & IN_DELETE) sl_strlcat(dbgbuf, "IN_DELETE ", sizeof(dbgbuf));
+      if (event->mask & IN_DELETE_SELF) sl_strlcat(dbgbuf, "IN_DELETE_SELF ", sizeof(dbgbuf));
+      if (event->mask & IN_MODIFY) sl_strlcat(dbgbuf, "IN_MODIFY ", sizeof(dbgbuf));
+      if (event->mask & IN_MOVE_SELF) sl_strlcat(dbgbuf, "IN_MOVE_SELF ", sizeof(dbgbuf));
+      if (event->mask & IN_MOVED_FROM) sl_strlcat(dbgbuf, "IN_MOVED_FROM ", sizeof(dbgbuf));
+      if (event->mask & IN_MOVED_TO) sl_strlcat(dbgbuf, "IN_MOVED_TO ", sizeof(dbgbuf));
+      if (event->mask & IN_OPEN) sl_strlcat(dbgbuf, "IN_OPEN ", sizeof(dbgbuf));
+      if (event->mask & IN_IGNORED) sl_strlcat(dbgbuf, "IN_IGNORED ", sizeof(dbgbuf));
+      if (event->mask & IN_ISDIR) sl_strlcat(dbgbuf, "IN_ISDIR ", sizeof(dbgbuf));
+      if (event->mask & IN_Q_OVERFLOW) sl_strlcat(dbgbuf, "IN_Q_OVERFLOW ", sizeof(dbgbuf));
+      if (event->mask & IN_UNMOUNT) sl_strlcat(dbgbuf, "IN_UNMOUNT ", sizeof(dbgbuf));
+      SH_MUTEX_LOCK(mutex_thread_nolog);
+      sh_error_handle(SH_ERR_ALL, FIL__, __LINE__, 0, MSG_E_SUBGEN, 
+		      dbgbuf, _("sh_fInotify_process"));
+      SH_MUTEX_UNLOCK(mutex_thread_nolog);
+    }
+
 
   if (event->wd >= 0)
@@ -438,5 +482,5 @@
     }
 
-  if ( (event->mask & (IN_ACCESS|IN_MODIFY)) != 0)
+  if ( (event->mask & (IN_ATTRIB|IN_MODIFY)) != 0)
     {
       sh_files_search_file(path, &class, &check_mask, &reported);
@@ -477,7 +521,9 @@
       if (S_FALSE == sh_ignore_chk_new(path))
 	{
+	  int ret;
+
 	  sh_files_clear_file_reported(path);
 	  
-	  sh_files_search_file(path, &class, &check_mask, &reported);
+	  ret = sh_files_search_file(path, &class, &check_mask, &reported);
 	  
 	  sh_files_filecheck (class, check_mask, filename,
@@ -486,4 +532,10 @@
 	  if (SH_FFLAG_REPORTED_SET(reported))
 	    sh_files_set_file_reported(path);
+
+	  if (ret != 0)
+	    {
+	      sh_inotify_add_watch(path, &sh_file_watches, &ret,
+				   class, check_mask);
+	    }
 	}
     }
