return fd;
}
-template<typename T>
-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<uint64_t>([=]{ return pleaseDump(fd); });
}
catch(...){}
-
+
close(fd);
return "dumped "+std::to_string(total)+" records\n";
}
}
if(cmd=="dump-cache")
- return doDumpCache(s, begin, end);
+ return doDumpCache(s);
if(cmd=="dump-ednsstatus" || cmd=="dump-edns")
return doDumpEDNSStatus(begin, end);
#endif
#include "rec_channel.hh"
#include <iostream>
+#include <fcntl.h>
#include "pdnsexception.hh"
#include "arguments.hh"
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"));