]> granicus.if.org Git - pdns/commitdiff
improve pid writing logic, plus control-socket separation. Patch by Matti Hiljanen.
authorBert Hubert <bert.hubert@netherlabs.nl>
Sat, 22 Mar 2008 20:43:44 +0000 (20:43 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Sat, 22 Mar 2008 20:43:44 +0000 (20:43 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1170 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/pdns_recursor.cc
pdns/rec_channel.cc
pdns/rec_channel.hh

index 106b8a435ae0d6506faa87cc6bc59ea1693cbd24..74c5a977121d762465f44b75266492831989f5b4 100644 (file)
@@ -404,8 +404,7 @@ static void setSendBuffer(int fd, uint32_t size)
 string s_pidfname;
 static void writePid(void)
 {
-  s_pidfname=::arg()["socket-dir"]+"/"+s_programname+".pid";
-  ofstream of(s_pidfname.c_str());
+  ofstream of(s_pidfname.c_str(), ios_base::app);
   if(of)
     of<< Utility::getpid() <<endl;
   else
@@ -1050,7 +1049,6 @@ void makeUDPServerSockets()
 #ifndef WIN32
 void daemonize(void)
 {
-  s_rcc.d_dontclose=true;
   if(fork())
     exit(0); // bye bye
   
@@ -1728,6 +1726,10 @@ int serviceMain(int argc, char*argv[])
   
   makeUDPServerSockets();
   makeTCPServerSockets();
+
+  s_pidfname=::arg()["socket-dir"]+"/"+s_programname+".pid";
+  if(!s_pidfname.empty())
+    unlink(s_pidfname.c_str()); // remove possible old pid file 
   
 #ifndef WIN32
   if(::arg().mustDo("fork")) {
@@ -1737,7 +1739,6 @@ int serviceMain(int argc, char*argv[])
 #endif
   
   MT=new MTasker<PacketID,string>(::arg().asNum("stack-size"));
-  makeControlChannelSocket();        
   PacketID pident;
   primeHints();    
   L<<Logger::Warning<<"Done priming cache with root hints"<<endl;
@@ -1752,6 +1753,7 @@ int serviceMain(int argc, char*argv[])
   signal(SIGPIPE,SIG_IGN);
   writePid();
 #endif
+  makeControlChannelSocket();        
   g_fdm=getMultiplexer();
   
   for(deferredAdd_t::const_iterator i=deferredAdd.begin(); i!=deferredAdd.end(); ++i) 
index ffc85830f8ec4db9f09509d1f7a8f7672a915284..86be6bddd54dec6377ce7d4628b71891a8b2634a 100644 (file)
@@ -14,7 +14,6 @@ using namespace std;
 RecursorControlChannel::RecursorControlChannel()
 {
   d_fd=-1;
-  d_dontclose=false;
   *d_local.sun_path=0;
 }
 
@@ -22,7 +21,7 @@ RecursorControlChannel::~RecursorControlChannel()
 {
   if(d_fd > 0)
     close(d_fd);
-  if(*d_local.sun_path && !d_dontclose)
+  if(*d_local.sun_path)
     unlink(d_local.sun_path);
 }
 
index b89063b283aaaa100a65c9628301a81162a9594d..4a381a50075b8cd624eabe307233667301fbb3db 100644 (file)
@@ -32,7 +32,6 @@ public:
   std::string recv(std::string* remote=0);
 
   int d_fd;
-  bool d_dontclose;
 private:
   struct sockaddr_un d_local;
 };