Index: /trunk/include/sh_inotify.h
===================================================================
--- /trunk/include/sh_inotify.h	(revision 495)
+++ /trunk/include/sh_inotify.h	(revision 496)
@@ -45,4 +45,5 @@
 void sh_inotify_remove(sh_watches * watches);
 void sh_inotify_init(sh_watches * watches);
+void sh_inotify_close();
 
 char * sh_inotify_search_item(sh_watches * watches, int watch, 
Index: /trunk/include/sh_modules.h
===================================================================
--- /trunk/include/sh_modules.h	(revision 495)
+++ /trunk/include/sh_modules.h	(revision 496)
@@ -7,5 +7,7 @@
 enum
   {
-    SH_MODFL_NOTIMER = (1 << 0)
+    SH_MODFL_NOTIMER    = (1 << 0),
+    SH_MODFL_NEEDPAUSED = (1 << 1),
+    SH_MODFL_ISPAUSED   = (1 << 2)
   };
 
Index: /trunk/src/samhain.c
===================================================================
--- /trunk/src/samhain.c	(revision 495)
+++ /trunk/src/samhain.c	(revision 496)
@@ -1250,4 +1250,15 @@
   
   sh_thread_pause_flag = S_TRUE;
+
+  for (modnum = 0; modList[modnum].name != NULL; ++modnum) 
+    {
+      if (0 != (SH_MODFL_NEEDPAUSED & modList[modnum].flags) &&
+	  modList[modnum].initval == SH_MOD_THREAD)
+	{
+	  int count = 50;
+	  while (count && 0 == (SH_MODFL_ISPAUSED & modList[modnum].flags))
+	    retry_msleep(0, 100), --count;
+	}
+    }
   
 #if defined(WITH_EXTERNAL)
Index: /trunk/src/sh_fInotify.c
===================================================================
--- /trunk/src/sh_fInotify.c	(revision 495)
+++ /trunk/src/sh_fInotify.c	(revision 496)
@@ -52,4 +52,5 @@
 
 static int ShfInotifyActive = S_FALSE;
+static int ShfInotifyClose  = S_FALSE; /* for reconf, mark instance for closing */
 
 static unsigned long ShfInotifyWatches = 0;
@@ -154,5 +155,5 @@
     {
       /* Reconfigure from main thread */
-      /* sh_fInotify_init_internal(); */
+
       SH_INOTIFY_IFUSED( sh.flag.inotify |= SH_INOTIFY_DOSCAN;   );
       SH_INOTIFY_IFUSED( sh.flag.inotify |= SH_INOTIFY_NEEDINIT; );
@@ -175,4 +176,10 @@
     {
       return SH_MOD_FAILED;
+    }
+
+  if (ShfInotifyClose == S_TRUE)
+    {
+      ShfInotifyClose = S_FALSE;
+      sh_inotify_close();
     }
 
@@ -261,4 +268,7 @@
 }
 
+/* This runs in the main thread, so it won't close
+ * the (threadspecific) inotify instance.
+ */
 int sh_fInotify_reconf()
 {
@@ -267,4 +277,6 @@
   ShfInotifyWatches = 0;
   ShfInotifyActive  = 0;
+
+  ShfInotifyClose   = S_TRUE;
 
   return sh_fInotify_cleanup();
Index: /trunk/src/sh_inotify.c
===================================================================
--- /trunk/src/sh_inotify.c	(revision 495)
+++ /trunk/src/sh_inotify.c	(revision 496)
@@ -427,5 +427,16 @@
 }
 
-
+void sh_inotify_close()
+{
+  int     ifd = sh_inotify_getfd();
+
+  if (ifd >= 0)
+    close(ifd);
+  sh_set_inotify_fd(-1);
+
+  return;
+}
+
+  
 /* This function removes all watches from the list,
  * and closes the inode file descriptor in this thread.
@@ -433,5 +444,4 @@
 void sh_inotify_remove(sh_watches * watches)
 {
-  int     ifd = sh_inotify_getfd();
   zAVLTree   * all_watches;
 
@@ -446,8 +456,5 @@
   SH_MUTEX_UNLOCK(mutex_watches);
 
-  if (ifd >= 0)
-    close(ifd);
-  sh_set_inotify_fd(-1);
-
+  sh_inotify_close();
   return;
 }
Index: /trunk/src/sh_modules.c
===================================================================
--- /trunk/src/sh_modules.c	(revision 495)
+++ /trunk/src/sh_modules.c	(revision 496)
@@ -160,5 +160,5 @@
     N_("INOTIFY"),
     -1,
-    0,
+    SH_MODFL_NEEDPAUSED,
     sh_fInotify_init,
     sh_fInotify_timer,
Index: /trunk/src/sh_pthread.c
===================================================================
--- /trunk/src/sh_pthread.c	(revision 495)
+++ /trunk/src/sh_pthread.c	(revision 496)
@@ -184,17 +184,26 @@
 	  while (1)
 	    {
-	      if (sh_thread_pause_flag != S_TRUE && 
-		  0 != this_module->mod_timer(time(NULL)))
+	      if (sh_thread_pause_flag != S_TRUE)
 		{
-		  /* If module has been de-activated on reconfigure,
-		   * mod_check() must return non-zero.
-		   * The mod_cleanup() routine must then enable the 
-		   * module to be re-activated eventually.
-		   */
-		  if (0 != this_module->mod_check())
-		    break;
-		  pthread_testcancel();
+		  this_module->flags &= ~SH_MODFL_ISPAUSED;
+		  
+		  if (0 != this_module->mod_timer(time(NULL)))
+		    {
+		      /* If module has been de-activated on reconfigure,
+		       * mod_check() must return non-zero.
+		       * The mod_cleanup() routine must then enable the 
+		       * module to be re-activated eventually.
+		       */
+		      if (0 != this_module->mod_check())
+			break;
+		      pthread_testcancel();
+		    }
 		}
-	      if (0 == (SH_MODFL_NOTIMER & this_module->flags))
+	      else
+		{
+		  this_module->flags |= SH_MODFL_ISPAUSED;
+		}
+	      if (0 == (SH_MODFL_NOTIMER & this_module->flags) ||
+		  sh_thread_pause_flag == S_TRUE)
 		retry_msleep(1,0);
 	    }
