--- duende.c	Mon Jan 27 06:15:13 2003
+++ ../../maradns-1.1.14/tools/duende.c	Mon Jan 27 22:09:24 2003
@@ -111,15 +111,30 @@
     int out_offset = 0;
     int err_offset = 0;
     int time_to_die = 0;
-    /* Select() stuff so the reads *never* block */
-    fd_set rx;
-    int sout;
-    int max;
-    struct timeval timeout;
 
     /* Open up the sys log */
     openlog("maradns",0,LOG_DAEMON);
 
+    /* This works, yipee! */
+    /*dup2(stdout_fd,0);
+    for(;;) {
+        fgets(out_buf,1020,stdin);
+	syslog(LOG_INFO,"%s",out_buf);
+        if(got_hup_signal == 1 || got_term_signal == 1) {
+	    time_to_die++; 
+	    if(time_to_die == 3) {
+	        syslog(LOG_INFO,"%s","Logging helper got signal, exiting");
+	        exit(8);
+	        }
+            }
+        }
+     exit(0); *//* end (this works but doesn't catch STDERR) */
+
+    /* DEBUG */
+    syslog(LOG_INFO,"Stdout FD is %d\n",stdout_fd);
+    syslog(LOG_INFO,"Stderr FD is %d\n",stderr_fd);
+    /* END DEBUG */
+
     /* Drop all privledges */
     if(chdir(CHROOT_DIR) != 0) {
         syslog(LOG_ALERT,"Can not enter chroot directory %s",CHROOT_DIR);
@@ -142,34 +157,17 @@
         out_buf[counter] = 0;
 	err_buf[counter] = 0;
 	}
-  
-    /* Prepare select */
-    FD_ZERO(&rx);
-    FD_SET(stdout_fd,&rx);
-    FD_SET(stderr_fd,&rx);
-    if(stderr_fd > stdout_fd) {
-    	max = stderr_fd + 1;
-        }
-    else {
-        max = stdout_fd + 1;
-	}
-    timeout.tv_sec = 1;
-    timeout.tv_usec = 0;
+   
     for(;;) {
-        select(max,&rx,NULL,NULL,&timeout);
-	if(FD_ISSET(stdout_fd,&rx)) {
-	    out_read = read(stdout_fd,out_buf + out_offset,1020 - out_offset);
-	    if(out_read > 0) {
-	        out_offset = log_lines_in_buffer(LOG_INFO,out_buf,1020);
-	        }
-            }
-        if(FD_ISSET(stderr_fd,&rx)) {
-            err_read = read(stderr_fd,err_buf + err_offset,1020 - err_offset);
-	    if(err_read > 0) {
-	        err_offset = log_lines_in_buffer(LOG_ERR,err_buf,1020);
-	        }
-            }
-        /*syslog(LOG_INFO,"read %d err %d",out_read,err_read);*/
+        sleep(1); /* So we don't hoze things */
+	out_read = read(stdout_fd,out_buf + out_offset,1020 - out_offset);
+	if(out_read > 0) {
+	    out_offset = log_lines_in_buffer(LOG_INFO,out_buf,1020);
+	    }
+        err_read = read(stderr_fd,err_buf + err_offset,1020 - err_offset);
+	if(err_read > 0) {
+	    err_offset = log_lines_in_buffer(LOG_ERR,err_buf,1020);
+	    }
         if(got_hup_signal == 1 || got_term_signal == 1) {
 	    /* We give the helper a couple of seconds to pick up all
 	       of the last messages from the maradns process */
@@ -257,7 +255,7 @@
 		exit(0);
 		}
 	    sleep(1);
-	    if(waitpid(pid,&exit_status,WNOHANG) != 0) { /* If child exited */
+	    if(waitpid(pid,&exit_status,WNOHANG) == pid) { /* If child exited */
 	        if(WIFEXITED(exit_status)) { /* Exit with exit code */
 		    if(WEXITSTATUS(exit_status) != 8) { /* Anything but HUP */
 		        kill(log_pid,SIGTERM);
