Changeset 988

Show
Ignore:
Timestamp:
03/25/07 13:33:06 (2 years ago)
Author:
ahu
Message:

close ticket 120 - pdns-recursor leaves behind pidfile & controlsocket on controlled exit

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pdns/pdns/pdns_recursor.cc

    r972 r988  
    396396} 
    397397 
    398  
     398string s_pidfname; 
    399399static void writePid(void) 
    400400{ 
    401   string fname=::arg()["socket-dir"]+"/"+s_programname+".pid"; 
    402   ofstream of(fname.c_str()); 
     401  s_pidfname=::arg()["socket-dir"]+"/"+s_programname+".pid"; 
     402  ofstream of(s_pidfname.c_str()); 
    403403  if(of) 
    404404    of<< Utility::getpid() <<endl; 
    405405  else 
    406     L<<Logger::Error<<"Requested to write pid for "<<Utility::getpid()<<" to "<<fname<<" failed: "<<strerror(errno)<<endl; 
     406    L<<Logger::Error<<"Requested to write pid for "<<Utility::getpid()<<" to "<<s_pidfname<<" failed: "<<strerror(errno)<<endl; 
    407407} 
    408408 
  • trunk/pdns/pdns/rec_channel.cc

    r945 r988  
    2727int RecursorControlChannel::listen(const string& fname) 
    2828{ 
    29   struct sockaddr_un local; 
    3029  d_fd=socket(AF_UNIX,SOCK_DGRAM,0); 
    3130     
     
    4140    throw AhuException("Can't remove (previous) controlsocket '"+fname+"': "+string(strerror(errno)) + " (try --socket-dir)"); 
    4241 
    43   memset(&local,0,sizeof(local)); 
    44   local.sun_family=AF_UNIX; 
    45   strcpy(local.sun_path, fname.c_str()); 
     42  memset(&d_local,0,sizeof(d_local)); 
     43  d_local.sun_family=AF_UNIX; 
     44  strcpy(d_local.sun_path, fname.c_str()); 
    4645     
    47   if(bind(d_fd, (sockaddr*)&local,sizeof(local))<0)  
     46  if(bind(d_fd, (sockaddr*)&d_local,sizeof(d_local))<0)  
    4847    throw AhuException("Unable to bind to controlsocket '"+fname+"': "+string(strerror(errno))); 
    4948 
  • trunk/pdns/pdns/rec_channel_rec.cc

    r935 r988  
    231231{ 
    232232  L<<Logger::Error<<"Exiting on user request"<<endl; 
     233  extern RecursorControlChannel s_rcc; 
     234  s_rcc.~RecursorControlChannel();  
     235 
     236  extern string s_pidfname; 
     237  if(!s_pidfname.empty())  
     238    unlink(s_pidfname.c_str()); // we can at least try.. 
    233239  _exit(1); 
    234240}