]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Open file in rec_control
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 14 Sep 2020 12:40:40 +0000 (14:40 +0200)
committerOtto <otto.moerbeek@open-xchange.com>
Mon, 15 Feb 2021 08:09:11 +0000 (09:09 +0100)
pdns/rec_channel_rec.cc
pdns/rec_control.cc

index 684eade7d5d171fc8674a7110f1ebc47a21c37e0..e9fb0fc425930651b41945384cfac85c85c556c7 100644 (file)
@@ -330,26 +330,19 @@ getfd(int s)
   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";
 }
@@ -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);
index 08b553ecf4b556685d66a869d4ac96652f3f989e..513a56332d92a81f58943900164fa26b1bdd24e5 100644 (file)
@@ -24,6 +24,7 @@
 #endif
 #include "rec_channel.hh"
 #include <iostream>
+#include <fcntl.h>
 #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"));