Index: trunk/src/samhain.c
===================================================================
--- trunk/src/samhain.c	(revision 83)
+++ trunk/src/samhain.c	(revision 84)
@@ -1314,5 +1314,5 @@
   /* close all other files
    */
-  sh_unix_closeall(3, -1); /* after processing CL options */
+  sh_unix_closeall(3, -1); /* after processing CL options; only stderr here */
 
 
@@ -1369,7 +1369,4 @@
       sh.flag.loop     = S_FALSE;
     }
-
-  if (sh.flag.isdaemon == S_TRUE)
-    sh_error_only_stderr (BAD);
 
   /* --- load database; checksum of database
Index: trunk/src/sh_database.c
===================================================================
--- trunk/src/sh_database.c	(revision 83)
+++ trunk/src/sh_database.c	(revision 84)
@@ -1525,5 +1525,5 @@
 }
 
-static int is_escaped(char * p_in) {
+static int is_escaped(const char * p_in) {
 
   int    escp = 0;
Index: trunk/src/sh_unix.c
===================================================================
--- trunk/src/sh_unix.c	(revision 83)
+++ trunk/src/sh_unix.c	(revision 84)
@@ -1198,5 +1198,5 @@
    */
   if (fdlimit < 0)
-    fdlimit = 8;  /* POSIX lower limit */
+    fdlimit = 20;  /* POSIX lower limit */
 
   if (fdlimit > 65536)
@@ -1847,14 +1847,37 @@
   sh_unix_zeroenv();
 
-
-  /* close all file descriptors, and 
-   * open first three streams to /dev/null 
-   */
   if (goDaemon == 1)
     {
+      /* close all file descriptors 
+       */ 
       sh_unix_closeall (0, -1);  /* if running as daemon */
-      aud_open(FIL__, __LINE__, SL_NOPRIV, _("/dev/null"), O_RDWR, 0);
-      retry_aud_dup(FIL__, __LINE__, 0); 
-      retry_aud_dup(FIL__, __LINE__, 0);
+
+      /* Enable full error logging
+       */
+      sh_error_only_stderr (S_FALSE);
+
+      /* open first three streams to /dev/null 
+       */
+      status = aud_open(FIL__, __LINE__, SL_NOPRIV, _("/dev/null"), O_RDWR, 0);
+      if (status < 0)
+	{
+	  status = errno;
+	  sh_error_handle((-1), FIL__, __LINE__, status, MSG_E_SUBGEN, 
+			  sh_error_message(status), _("open"));
+	  aud_exit(FIL__, __LINE__, EXIT_FAILURE);
+	}
+
+      status = retry_aud_dup(FIL__, __LINE__, 0); 
+      if (status >= 0)
+	retry_aud_dup(FIL__, __LINE__, 0);
+
+      if (status < 0)
+	{
+	  status = errno;
+	  sh_error_handle((-1), FIL__, __LINE__, status, MSG_E_SUBGEN, 
+			  sh_error_message(status), _("dup"));
+	  aud_exit(FIL__, __LINE__, EXIT_FAILURE);
+	}
+
 #if defined(HAVE_LIBPRELUDE)
       sh_prelude_reset ();
