From: Otto Moerbeek Date: Mon, 14 Sep 2020 12:40:40 +0000 (+0200) Subject: Open file in rec_control X-Git-Tag: dnsdist-1.6.0-alpha2~39^2~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a8f0a123f78ad7afbd3c580aabb8aa96fc79764a;p=thirdparty%2Fpdns.git Open file in rec_control --- diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index 684eade7d5..e9fb0fc425 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -330,26 +330,19 @@ getfd(int s) return fd; } -template -static string doDumpCache(int s, T begin, T end) +static string doDumpCache(int s) { - int fd = getfd(s); - - T i=begin; - string fname; - if(i!=end) - fname=*i; - - if(fd < 0) + if(fd < 0) { return "Error opening dump file for writing: "+stringerror()+"\n"; + } uint64_t total = 0; try { total = g_recCache->doDump(fd) + dumpNegCache(fd) + broadcastAccFunction([=]{ return pleaseDump(fd); }); } catch(...){} - + close(fd); return "dumped "+std::to_string(total)+" records\n"; } @@ -1814,7 +1807,7 @@ string RecursorControlParser::getAnswer(int s, const string& question, RecursorC } if(cmd=="dump-cache") - return doDumpCache(s, begin, end); + return doDumpCache(s); if(cmd=="dump-ednsstatus" || cmd=="dump-edns") return doDumpEDNSStatus(begin, end); diff --git a/pdns/rec_control.cc b/pdns/rec_control.cc index 08b553ecf4..513a56332d 100644 --- a/pdns/rec_control.cc +++ b/pdns/rec_control.cc @@ -24,6 +24,7 @@ #endif #include "rec_channel.hh" #include +#include #include "pdnsexception.hh" #include "arguments.hh" @@ -103,10 +104,14 @@ try for(unsigned int i=0; i< commands.size(); ++i) { if(i>0) command+=" "; - if (commands[i] == "dump-cache") { - fd = STDOUT_FILENO; // XXX - } command+=commands[i]; + if (commands[i] == "dump-cache" && i+1 < commands.size()) { + fd = open(commands[++i].c_str(), O_CREAT | O_EXCL | O_WRONLY, 0660); + if (fd == -1) { + int err = errno; + throw PDNSException("Error opening dump file for writing: " + stringerror(err)); + } + } } rccS.send(command, nullptr, arg().asNum("timeout"), fd); string receive=rccS.recv(0, arg().asNum("timeout"));