Index: /trunk/configure.ac
===================================================================
--- /trunk/configure.ac	(revision 173)
+++ /trunk/configure.ac	(revision 174)
@@ -13,5 +13,5 @@
 dnl start
 dnl
-AM_INIT_AUTOMAKE(samhain, 2.4.5a)
+AM_INIT_AUTOMAKE(samhain, 2.4.6)
 AC_DEFINE([SAMHAIN], 1, [Application is samhain])
 AC_CANONICAL_HOST
Index: /trunk/docs/Changelog
===================================================================
--- /trunk/docs/Changelog	(revision 173)
+++ /trunk/docs/Changelog	(revision 174)
@@ -1,3 +1,8 @@
-2.4.5a:
+2.4.6:
+	* fix potential deadlock with dnmalloc upon fork()
+	* fix non-portable use of 'hostname -f' in regression test suite
+	  (reported by Borut Podlipnik)
+
+2.4.5a (18-08-2008):
 	* fix compile problem in dnmalloc.c (remove prototypes for
 	  memset/memcpy), problem reported by Juergen Daubert
Index: /trunk/include/sh_unix.h
===================================================================
--- /trunk/include/sh_unix.h	(revision 173)
+++ /trunk/include/sh_unix.h	(revision 174)
@@ -209,5 +209,5 @@
 /* close all files >= fd, except possibly one
  */
-void sh_unix_closeall (int fd, int except);
+void sh_unix_closeall (int fd, int except, int inchild);
 
 
Index: /trunk/include/slib.h
===================================================================
--- /trunk/include/slib.h	(revision 173)
+++ /trunk/include/slib.h	(revision 174)
@@ -401,4 +401,5 @@
    */
   int sl_dropall(int fd, int except);
+  int sl_dropall_dirty(int fd, int except); /* don't deallocate */
 
   /* Check whether file is trustworthy.
Index: /trunk/src/dnmalloc.c
===================================================================
--- /trunk/src/dnmalloc.c	(revision 173)
+++ /trunk/src/dnmalloc.c	(revision 174)
@@ -1508,12 +1508,22 @@
     pthread_mutex_unlock(&mALLOC_MUTEx); 
 }
-void dnmalloc_fork_child(void) { 
+void dnmalloc_fork_child(void) {
+  int rc;
 #ifdef __GLIBC__
   if (dnmalloc_use_mutex)
-    pthread_mutex_init(&mALLOC_MUTEx, NULL); 
+    {
+      pthread_mutex_unlock (&mALLOC_MUTEx);
+      pthread_mutex_destroy(&mALLOC_MUTEx);
+      rc = pthread_mutex_init(&mALLOC_MUTEx, NULL);
+    } 
 #else
   if (dnmalloc_use_mutex)
-    pthread_mutex_unlock(&mALLOC_MUTEx); 
-#endif
+    rc = pthread_mutex_unlock(&mALLOC_MUTEx); 
+#endif
+  if (rc != 0)
+    {
+      fputs("fork_child failed", stderr);
+      _exit(EXIT_FAILURE);
+    }
 }
 static int dnmalloc_mutex_lock(pthread_mutex_t *mutex)
Index: /trunk/src/samhain.c
===================================================================
--- /trunk/src/samhain.c	(revision 173)
+++ /trunk/src/samhain.c	(revision 174)
@@ -1234,5 +1234,5 @@
   /* --- Close all but first three file descriptors. ---
    */
-  sh_unix_closeall(3, -1); /* at program start */
+  sh_unix_closeall(3, -1, SL_FALSE); /* at program start */
 
 
Index: /trunk/src/sh_entropy.c
===================================================================
--- /trunk/src/sh_entropy.c	(revision 173)
+++ /trunk/src/sh_entropy.c	(revision 174)
@@ -581,5 +581,5 @@
       /* don't leak file descriptors
        */
-      sh_unix_closeall (3, -1); /* in child process */
+      sh_unix_closeall (3, -1, SL_TRUE); /* in child process */
 
       /* zero priv info
Index: /trunk/src/sh_extern.c
===================================================================
--- /trunk/src/sh_extern.c	(revision 173)
+++ /trunk/src/sh_extern.c	(revision 174)
@@ -294,5 +294,5 @@
 	   */
 #if !defined(PDGBFILE)
-	  sh_unix_closeall (3, task->com_fd); /* in child process */
+	  sh_unix_closeall (3, task->com_fd, SL_TRUE); /* in child process */
 #endif
 
Index: /trunk/src/sh_gpg.c
===================================================================
--- /trunk/src/sh_gpg.c	(revision 173)
+++ /trunk/src/sh_gpg.c	(revision 174)
@@ -487,5 +487,5 @@
       /* don't leak file descriptors
        */
-      sh_unix_closeall (3, -1); /* in child process */
+      sh_unix_closeall (3, -1, SL_TRUE); /* in child process */
 
       if (NULL == freopen(_("/dev/null"), "r+", stderr))
Index: /trunk/src/sh_unix.c
===================================================================
--- /trunk/src/sh_unix.c	(revision 173)
+++ /trunk/src/sh_unix.c	(revision 174)
@@ -1246,5 +1246,5 @@
 #endif
 
-void sh_unix_closeall (int fd, int except)
+void sh_unix_closeall (int fd, int except, int inchild)
 {
   int fdx = fd;
@@ -1281,5 +1281,8 @@
     }
 
-  sl_dropall (fdx, except);
+  if (!inchild)
+    sl_dropall (fdx, except);
+  else
+    sl_dropall_dirty (fdx, except);
 
   SL_RET0(_("sh_unix_closeall"));
Index: /trunk/src/slib.c
===================================================================
--- /trunk/src/slib.c	(revision 173)
+++ /trunk/src/slib.c	(revision 174)
@@ -2093,4 +2093,17 @@
 	    (void) free(ofiles[fd]->path);
 	  (void) free(ofiles[fd]);
+	  ofiles[fd] = NULL;
+	}
+      ++fd;
+    }
+  return 0;
+}
+
+int sl_dropall_dirty(int fd, int except)
+{
+  while (fd < MAXFD)
+    {
+      if (ofiles[fd] != NULL && fd != except)
+	{
 	  ofiles[fd] = NULL;
 	}
Index: /trunk/test/test.sh
===================================================================
--- /trunk/test/test.sh	(revision 173)
+++ /trunk/test/test.sh	(revision 174)
@@ -482,6 +482,12 @@
 
 find_hostname () {
-    tmp=`hostname -f 2>/dev/null`
-    if [ $? -ne 0 ]; then
+
+    uname -a | grep Linux >/dev/null
+    if [ $? -eq 0 ]; then
+	tmp=`hostname -f 2>/dev/null`
+	if [ $? -ne 0 ]; then
+	    tmp=`hostname 2>/dev/null`
+	fi
+    else
 	tmp=`hostname 2>/dev/null`
     fi
