Index: trunk/src/samhain.c
===================================================================
--- trunk/src/samhain.c	(revision 141)
+++ trunk/src/samhain.c	(revision 142)
@@ -704,7 +704,10 @@
   for (modnum = 0; modList[modnum].name != NULL; ++modnum) 
     {
-      if (modList[modnum].initval == GOOD)
+      if (modList[modnum].initval == SH_MOD_ACTIVE)
 	(void) modList[modnum].mod_cleanup();
     }
+#ifdef HAVE_PTHREAD
+  sh_pthread_cancel_all();
+#endif
 #endif
 
@@ -1637,5 +1640,6 @@
   for (modnum = 0; modList[modnum].name != NULL; ++modnum) 
     {
-      if ( 0 != (status = modList[modnum].mod_init(&(modList[modnum]))) )
+      status = modList[modnum].mod_init(&(modList[modnum]));
+      if ( status < 0 )
 	{
 	  if (status == (-1)) {
@@ -1649,5 +1653,5 @@
 			     status);
 	  }
-	  modList[modnum].initval = S_FALSE;
+	  modList[modnum].initval = SH_MOD_FAILED;
 	}
       else
@@ -1655,5 +1659,5 @@
 	  sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_MOD_OK,
 			   _(modList[modnum].name));
-	  modList[modnum].initval = S_TRUE;
+	  modList[modnum].initval = status;
 	}
     }
@@ -1744,5 +1748,5 @@
 	      for (modnum = 0; modList[modnum].name != NULL; ++modnum) 
 		{
-		  if (modList[modnum].initval == GOOD)
+		  if (modList[modnum].initval >= SH_MOD_ACTIVE)
 		    (void) modList[modnum].mod_reconf();
 		}
@@ -1795,5 +1799,7 @@
 	      for (modnum = 0; modList[modnum].name != NULL; ++modnum) 
 		{
-		  if (0 != (status = modList[modnum].mod_init(&(modList[modnum]))))
+		  status = modList[modnum].mod_init(&(modList[modnum]));
+
+		  if (status < 0)
 		    {
 		      if (status == (-1)) {
@@ -1808,5 +1814,5 @@
 					 status);
 		      }
-		      modList[modnum].initval = S_FALSE;
+		      modList[modnum].initval = SH_MOD_FAILED;
 		    }
 		  else
@@ -1814,5 +1820,5 @@
 		      sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_MOD_OK,
 				       _(modList[modnum].name));
-		      modList[modnum].initval = S_TRUE;
+		      modList[modnum].initval = status;
 		    }
 		}
@@ -2025,5 +2031,5 @@
       for (modnum = 0; modList[modnum].name != NULL; ++modnum) 
 	{
-	  if (modList[modnum].initval == GOOD &&
+	  if (modList[modnum].initval == SH_MOD_ACTIVE &&
 	      0 != modList[modnum].mod_timer(tcurrent))
 	    if (0 != (status = modList[modnum].mod_check()))
Index: trunk/src/sh_error.c
===================================================================
--- trunk/src/sh_error.c	(revision 141)
+++ trunk/src/sh_error.c	(revision 142)
@@ -20,5 +20,6 @@
 #include "config_xor.h"
 
-/* required on linux to get the correct strerror_r function
+/* Required on linux to get the correct strerror_r function. Also
+ * for recursive mutexes (_XOPEN_SOURCE >= 500).
  */
 #define _XOPEN_SOURCE 600
Index: trunk/src/sh_modules.c
===================================================================
--- trunk/src/sh_modules.c	(revision 141)
+++ trunk/src/sh_modules.c	(revision 142)
@@ -21,5 +21,5 @@
   {
     N_("UTMP"),
-    0,
+    -1,
     sh_utmp_init,
     sh_utmp_timer,
@@ -37,5 +37,5 @@
   {
     N_("MOUNTS"),
-    0,
+    -1,
     sh_mounts_init,
     sh_mounts_timer,
@@ -53,5 +53,5 @@
   {
     N_("USERFILES"),
-    0,
+    -1,
     sh_userfiles_init,
     sh_userfiles_timer,
@@ -69,5 +69,5 @@
   {
     N_("KERNEL"),
-    0,
+    -1,
     sh_kern_init,
     sh_kern_timer,
@@ -85,5 +85,5 @@
   {
     N_("SUIDCHECK"),
-    0,
+    -1,
     sh_suidchk_init,
     sh_suidchk_timer,
@@ -101,5 +101,5 @@
   {
     N_("PROCESSCHECK"),
-    0,
+    -1,
     sh_prochk_init,
     sh_prochk_timer,
@@ -117,5 +117,5 @@
   {
     N_("PORTCHECK"),
-    0,
+    -1,
     sh_portchk_init,
     sh_portchk_timer,
@@ -132,5 +132,5 @@
   {
     NULL,
-    0,
+    -1,
 
     NULL,
Index: trunk/src/sh_pthread.c
===================================================================
--- trunk/src/sh_pthread.c	(revision 141)
+++ trunk/src/sh_pthread.c	(revision 142)
@@ -40,14 +40,19 @@
 
 /* MODULES: init()
- *             -- starts thread_run() function if threaded
- *             -- fallback on internal_init if threading fails
- *             -- and returns MODULE_INACTIVE/MODULE_ACTIVE/MODULE_THREADED
- *
- *                int retval = MODULE_INACTIVE;
- *                if (0 != sh_pthread_create(thread_run, NULL))
- *                   return internal_init();
- *                return MODULE_THREADED;
- *
- *          thread_run() 
+ *
+ * #ifdef HAVE_PTHREAD
+ *  if (arg != NULL)
+ *    {
+ *      if (0 == sh_pthread_create(sh_threaded_module_run, (void *)arg))
+ *	  return SH_MOD_THREAD;
+ *      else
+ *	  return SH_MOD_FAILED;
+ *    }
+ * #else
+ *  return sh_utmp_init_internal();
+ * #endif
+ *
+ *
+ *          sh_threaded_module_run(module_struct) 
  *             -- calls internal init, 
  *             -- polls timer, 
@@ -131,12 +136,12 @@
 /* ---- Utility functions for modules ----
  */
-void sh_threaded_module_reconf(void *arg)
+void sh_threaded_module_cleanup(void *arg)
 {
   sh_mtype * this_module = (sh_mtype *) arg;
-  this_module->mod_reconf();
+  this_module->mod_cleanup();
   return;
 }
 
-void sh_threaded_module_run(void *arg)
+void * sh_threaded_module_run(void *arg)
 {
   sh_mtype * this_module = (sh_mtype *) arg;
@@ -153,5 +158,5 @@
       if (0 == this_module->mod_init(NULL))
 	{
-	  pthread_cleanup_push(sh_threaded_module_reconf, arg);
+	  pthread_cleanup_push(sh_threaded_module_cleanup, arg);
 
 	  while (1)
@@ -159,5 +164,11 @@
 	      if (0 != this_module->mod_timer(time(NULL)))
 		{
-		  this_module->mod_check();
+		  /* 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();
 		  retry_msleep(1,0);
@@ -171,5 +182,5 @@
   pthread_cleanup_pop(1);
 
-  return;
+  return NULL;
 }
 
Index: trunk/src/sh_utmp.c
===================================================================
--- trunk/src/sh_utmp.c	(revision 141)
+++ trunk/src/sh_utmp.c	(revision 142)
@@ -455,4 +455,5 @@
 static struct log_user   * userlist   = NULL;
 static time_t  lastcheck;
+static int     init_done = 0;
 
 /*************
@@ -461,8 +462,7 @@
  *
  *************/
-int sh_utmp_init (struct mod_type * arg)
-{
-  static int done = 0;
-  (void) arg;
+
+static int sh_utmp_init_internal ()
+{
 
   SL_ENTER(_("sh_utmp_init"));
@@ -472,5 +472,5 @@
   /* do not re-initialize after a re-configuration
    */
-  if (done == 1) {
+  if (init_done == 1) {
     SL_RETURN( (0), _("sh_utmp_init"));
   }
@@ -480,6 +480,22 @@
   sh_utmp_check_internal (2); /* current logins */
   sh_utmp_check_internal (0);
-  done = 1;
+  init_done = 1;
   SL_RETURN( (0), _("sh_utmp_init"));
+}
+
+int sh_utmp_init (struct mod_type * arg)
+{
+  if (ShUtmpActive == BAD)
+    return SH_MOD_FAILED;
+#ifdef HAVE_PTHREAD
+  if (arg != NULL && arg->initval < 0)
+    {
+      if (0 == sh_pthread_create(sh_threaded_module_run, (void *)arg))
+	return SH_MOD_THREAD;
+      else
+	return SH_MOD_FAILED;
+    }
+#endif
+  return sh_utmp_init_internal();
 }
 
@@ -509,4 +525,9 @@
   (void) sh_utmp_login_clean();
 #endif
+  /* Reset the flag, such that the module
+   * can be re-enabled.
+   */
+  ShUtmpActive       = S_TRUE;
+  init_done          = 0;
   SL_RETURN( (0), _("sh_utmp_end"));
 }
@@ -536,4 +557,6 @@
 {
   SL_ENTER(_("sh_utmp_check"));
+  if (ShUtmpActive == BAD)
+    SL_RETURN( (-1), _("sh_utmp_check"));
   sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_UT_CHECK);
   sh_utmp_check_internal (1);
