From 524e4f4d81f4ed9eb218715cbc8a59f0b9868234 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Tue, 3 Feb 2015 10:39:40 +0100 Subject: [PATCH] clear up local socket in rec_control in case recursor is down, close #2061 --- pdns/rec_channel.cc | 6 +++++- pdns/rec_control.cc | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pdns/rec_channel.cc b/pdns/rec_channel.cc index e08484e8a..d566c06a7 100644 --- a/pdns/rec_channel.cc +++ b/pdns/rec_channel.cc @@ -68,6 +68,7 @@ void RecursorControlChannel::connect(const string& path, const string& fname) throw PDNSException("Setsockopt failed: "+stringerror()); string localname=path+"/lsockXXXXXX"; + *d_local.sun_path=0; if (makeUNsockaddr(localname, &d_local)) throw PDNSException("Unable to bind to local temporary file, path '"+localname+"' is not a valid UNIX socket path."); @@ -88,8 +89,11 @@ void RecursorControlChannel::connect(const string& path, const string& fname) if (makeUNsockaddr(remotename, &remote)) throw PDNSException("Unable to connect to controlsocket, path '"+remotename+"' is not a valid UNIX socket path."); - if(::connect(d_fd, (sockaddr*)&remote, sizeof(remote)) < 0) + if(::connect(d_fd, (sockaddr*)&remote, sizeof(remote)) < 0) { + if(*d_local.sun_path) + unlink(d_local.sun_path); throw PDNSException("Unable to connect to remote '"+string(remote.sun_path)+"': "+stringerror()); + } } catch (...) { close(d_fd); diff --git a/pdns/rec_control.cc b/pdns/rec_control.cc index 86a8e8471..c282126bc 100644 --- a/pdns/rec_control.cc +++ b/pdns/rec_control.cc @@ -1,6 +1,6 @@ /* PowerDNS Versatile Database Driven Nameserver - Copyright (C) 2006 - 2011 PowerDNS.COM BV + Copyright (C) 2006 - 2015 PowerDNS.COM BV This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as -- 2.40.0