[Pdns-users] Automatic AXFR as slave with 2.9.10 doesn't seem to work right?

Derrik Pates dpates at dsdk12.net
Fri Aug 22 20:23:28 UTC 2003


On Fri, Aug 22, 2003 at 08:10:20PM +0200, bert hubert wrote:
> On Wed, Aug 13, 2003 at 07:57:57PM -0600, dpates at dsdk12.net wrote:
> > Looking through the list archives, I saw someone mention this, and I saw
> > evidence of this problem today, when I switched our secondary nameserver over to
> > PowerDNS 2.9.10. A remote server (running BIND 9) sent PowerDNS 4 different
> 
> Can you check with 2.9.11?

2.9.11 removes the cout statement that invokes a symptom, but the real
problem is that PowerDNS, and the recursor, close stdin, stdout and
stderr, but never reopen them, so anything that reads from stdin, or
writes to stdout or stderr, will be playing with fd's that it should
not. They should _always_ be reopened to /dev/null, because fd's 0, 1
and 2 are always treated as "magical". I'm attaching a small patch that
fixes the daemonize() call to reopen those fd's to /dev/null, as is
standard practice. It should fix the problem permanently.

-- 
Derrik Pates
dpates at dsdk12.net
dpates at voxel.net
-------------- next part --------------
--- stock/pdns-2.9.11/pdns/receiver.cc	Fri Aug 22 09:33:31 2003
+++ pdns-2.9.11/pdns/receiver.cc	Fri Aug 22 16:14:46 2003
@@ -92,15 +92,22 @@
 
 void daemonize(void)
 {
+  int fd;
   if(fork())
     exit(0); // bye bye
   
   setsid(); 
 
-  // cleanup open fds, but skip sockets 
-  close(0);
-  close(1);
-  close(2);
+  // reopen default fd's to /dev/null
+  if ((fd = open("/dev/null", O_RDONLY)) != 0) {
+    dup2(fd, 0);
+    close(fd);
+  }
+  if ((fd = open("/dev/null", O_WRONLY)) != 1) {
+    dup2(fd, 1);
+    close(fd);
+  }
+  dup2(1, 2);
 
 }
 
--- stock/pdns-2.9.11/pdns/pdns_recursor.cc	Mon Jul 28 14:53:29 2003
+++ pdns-2.9.11/pdns/pdns_recursor.cc	Fri Aug 22 16:14:46 2003
@@ -357,15 +357,22 @@
 #ifndef WIN32
 void daemonize(void)
 {
+  int fd;
   if(fork())
     exit(0); // bye bye
   
   setsid(); 
 
-  // cleanup open fds, but skip sockets 
-  close(0);
-  close(1);
-  close(2);
+  // reopen default fd's to /dev/null
+  if ((fd = open("/dev/null", O_RDONLY)) != 0) {
+    dup2(fd, 0);
+    close(fd);
+  }
+  if ((fd = open("/dev/null", O_WRONLY)) != 1) {
+    dup2(fd, 1);
+    close(fd);
+  }
+  dup2(1, 2);
 
 }
 #endif


More information about the Pdns-users mailing list