From: Remi Gacogne Date: Thu, 29 Nov 2018 10:28:37 +0000 (+0100) Subject: rec: Use the timeout passed to rec_control for sending too X-Git-Tag: auth-4.2.0-alpha1~9^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F7242%2Fhead;p=thirdparty%2Fpdns.git rec: Use the timeout passed to rec_control for sending too --- diff --git a/pdns/rec_channel.cc b/pdns/rec_channel.cc index 2bbb54c1a3..cec4dff6a7 100644 --- a/pdns/rec_channel.cc +++ b/pdns/rec_channel.cc @@ -108,8 +108,16 @@ void RecursorControlChannel::connect(const string& path, const string& fname) } } -void RecursorControlChannel::send(const std::string& msg, const std::string* remote) +void RecursorControlChannel::send(const std::string& msg, const std::string* remote, unsigned int timeout) { + int ret = waitForRWData(d_fd, false, timeout, 0); + if(ret == 0) { + throw PDNSException("Timeout sending message over control channel"); + } + else if(ret < 0) { + throw PDNSException("Error sending message over control channel:" + string(strerror(errno))); + } + if(remote) { struct sockaddr_un remoteaddr; memset(&remoteaddr, 0, sizeof(remoteaddr)); diff --git a/pdns/rec_channel.hh b/pdns/rec_channel.hh index 1b8e4d8f30..0fadd41259 100644 --- a/pdns/rec_channel.hh +++ b/pdns/rec_channel.hh @@ -44,7 +44,7 @@ public: uint64_t getStat(const std::string& name); - void send(const std::string& msg, const std::string* remote=0); + void send(const std::string& msg, const std::string* remote=nullptr, unsigned int timeout=5); std::string recv(std::string* remote=0, unsigned int timeout=5); int d_fd; diff --git a/pdns/rec_control.cc b/pdns/rec_control.cc index 90f6fd1c21..56f6776c36 100644 --- a/pdns/rec_control.cc +++ b/pdns/rec_control.cc @@ -104,7 +104,7 @@ try command+=" "; command+=commands[i]; } - rccS.send(command); + rccS.send(command, nullptr, arg().asNum("timeout")); string receive=rccS.recv(0, arg().asNum("timeout")); if(receive.compare(0, 7, "Unknown") == 0) { cerr<