]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add the 'clearConsoleHistory' command
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 10 Aug 2020 16:16:17 +0000 (18:16 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 10 Aug 2020 16:16:17 +0000 (18:16 +0200)
It removes the history items and delta() data from memory.

pdns/dnsdist-console.cc
pdns/dnsdist-console.hh
pdns/dnsdist-lua.cc

index d68eb6b58ffd81d901151c76c99d6fd6a7ae8f10..7384cd115c6912501865f8a9a1614607979ad603 100644 (file)
@@ -187,7 +187,6 @@ void doClient(ComboAddress server, const std::string& command)
   }
 
   string histfile = historyFile();
-  set<string> dupper;
   {
     ifstream history(histfile);
     string line;
@@ -230,7 +229,6 @@ void doClient(ComboAddress server, const std::string& command)
 void doConsole()
 {
   string histfile = historyFile(true);
-  set<string> dupper;
   {
     ifstream history(histfile);
     string line;
@@ -362,10 +360,11 @@ const std::vector<ConsoleKeyword> g_consoleKeywords{
   { "AndRule", true, "list of DNS rules", "matches if all sub-rules matches" },
   { "benchRule", true, "DNS Rule [, iterations [, suffix]]", "bench the specified DNS rule" },
   { "carbonServer", true, "serverIP, [ourname], [interval]", "report statistics to serverIP using our hostname, or 'ourname' if provided, every 'interval' seconds" },
-  { "controlSocket", true, "addr", "open a control socket on this address / connect to this address in client mode" },
+  { "clearConsoleHistory", true, "", "clear the internal (in-memory) history of console commands" },
   { "clearDynBlocks", true, "", "clear all dynamic blocks" },
   { "clearQueryCounters", true, "", "clears the query counter buffer" },
   { "clearRules", true, "", "remove all current rules" },
+  { "controlSocket", true, "addr", "open a control socket on this address / connect to this address in client mode" },
   { "ContinueAction", true, "action", "execute the specified action and continue the processing of the remaining rules, regardless of the return of the action" },
   { "DelayAction", true, "milliseconds", "delay the response by the specified amount of milliseconds (UDP-only)" },
   { "DelayResponseAction", true, "milliseconds", "delay the response by the specified amount of milliseconds (UDP-only)" },
@@ -822,3 +821,9 @@ catch(const std::exception& e)
   close(fd);
   errlog("Control connection died: %s", e.what());
 }
+
+void clearConsoleHistory()
+{
+  clear_history();
+  g_confDelta.clear();
+}
index 1c3bb6e2f878118b56e884a243dfbee55e966be3..70800644a56098de7508b55d321809c6b91ea41c 100644 (file)
@@ -51,3 +51,4 @@ extern "C" {
 char** my_completion( const char * text , int start,  int end);
 }
 void controlThread(int fd, ComboAddress local);
+void clearConsoleHistory();
index c6477f17f86d40a8cd32e2250fb96f4bb6e6fdeb..f753ba20b6f03030b768213aecf3db6520861b04 100644 (file)
@@ -1008,6 +1008,10 @@ static void setupLuaConfig(bool client, bool configCheck)
        g_consoleKey=newkey;
     });
 
+  g_lua.writeFunction("clearConsoleHistory", []() {
+      clearConsoleHistory();
+    });
+
   g_lua.writeFunction("testCrypto", [](boost::optional<string> optTestMsg)
    {
      setLuaNoSideEffect();