From: bert hubert Date: Mon, 10 Jun 2013 14:11:20 +0000 (+0200) Subject: CHANGES BEHAVIOUR: before we launch, check if we can connect to the controlsocket... X-Git-Tag: auth-3.3-rc2~49^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d72166cb414932ea6ee7659bca99952ab975a53c;p=pdns CHANGES BEHAVIOUR: before we launch, check if we can connect to the controlsocket we are about to obliterate. If it works, abort. Fixes #841 and changes standing behaviour. There might be circumstances where PowerDNS now refuses to start, where it previously would. However, starting and making our previous instance mute wasn't good. --- diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index 044b38f7b..cf627e87c 100644 --- a/pdns/common_startup.cc +++ b/pdns/common_startup.cc @@ -31,8 +31,6 @@ UDPNameserver *N; int avg_latency; TCPNameserver *TN; - - ArgvMap &arg() { return theArg; diff --git a/pdns/dynlistener.cc b/pdns/dynlistener.cc index b46dcec7c..a8cb793d4 100644 --- a/pdns/dynlistener.cc +++ b/pdns/dynlistener.cc @@ -83,8 +83,33 @@ void DynListener::createSocketAndBind(int family, struct sockaddr*local, size_t } } +/* this does a simplistic check, if we can connect, we consider it live. If we can't connect because + of access denied, we must consider it dead, nothing we can do about it. +*/ +bool DynListener::testLive(const string& fname) +{ + struct sockaddr_un addr; + int fd = socket(AF_UNIX, SOCK_STREAM, 0); + if(fd < 0) { // we'll have bigger issues down the road + return false; + } + + memset(&addr, 0, sizeof(addr)); + addr.sun_family = AF_UNIX; + strncpy(addr.sun_path, fname.c_str(), fname.length()); + + int status = connect(fd, (struct sockaddr*)&addr, sizeof(addr)); + int err=errno; + close(fd); + return status==0; +} + void DynListener::listenOnUnixDomain(const string& fname) { + if(testLive(fname)) { + L<