From: Peter van Dijk Date: Mon, 21 Jan 2013 06:42:50 +0000 (+0000) Subject: only setCloseOnExec on valid sockets X-Git-Tag: rec-3.5-rc1~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fb31631870b0330a5228f975ebb5145589486d86;p=pdns only setCloseOnExec on valid sockets git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@3067 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/nameserver.cc b/pdns/nameserver.cc index 1b92fe28d..4bc3492c1 100644 --- a/pdns/nameserver.cc +++ b/pdns/nameserver.cc @@ -165,10 +165,11 @@ void UDPNameserver::bindIPv6() string localname(*i); s=socket(AF_INET6,SOCK_DGRAM,0); - Utility::setCloseOnExec(s); if(s<0) throw AhuException("Unable to acquire a UDPv6 socket: "+string(strerror(errno))); + Utility::setCloseOnExec(s); + ComboAddress locala(localname, ::arg().asNum("local-port")); if(IsAnyAddress(locala)) { diff --git a/pdns/tcpreceiver.cc b/pdns/tcpreceiver.cc index 9e4a207b4..3e0506c9d 100644 --- a/pdns/tcpreceiver.cc +++ b/pdns/tcpreceiver.cc @@ -834,11 +834,12 @@ TCPNameserver::TCPNameserver() for(vector::const_iterator laddr=locals.begin();laddr!=locals.end();++laddr) { int s=socket(AF_INET,SOCK_STREAM,0); - Utility::setCloseOnExec(s); if(s<0) throw AhuException("Unable to acquire TCP socket: "+stringerror()); + Utility::setCloseOnExec(s); + ComboAddress local(*laddr, ::arg().asNum("local-port")); int tmp=1; @@ -866,11 +867,12 @@ TCPNameserver::TCPNameserver() #if !WIN32 && HAVE_IPV6 for(vector::const_iterator laddr=locals6.begin();laddr!=locals6.end();++laddr) { int s=socket(AF_INET6,SOCK_STREAM,0); - Utility::setCloseOnExec(s); if(s<0) throw AhuException("Unable to acquire TCPv6 socket: "+stringerror()); + Utility::setCloseOnExec(s); + ComboAddress local(*laddr, ::arg().asNum("local-port")); int tmp=1;