Skip to content

Commit

Permalink
dnsdist: Save history to home-dir
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterlexis committed Dec 16, 2016
1 parent 81d1f27 commit a1e6a66
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pdns/dnsdist-console.cc
Expand Up @@ -21,6 +21,7 @@
*/
#include "dnsdist.hh"
#include "sodcrypto.hh"
#include "pwd.h"

#if defined (__OpenBSD__)
#include <readline/readline.h>
Expand Down Expand Up @@ -85,14 +86,25 @@ void doClient(ComboAddress server, const std::string& command)
return;
}

string histfile;
struct passwd* pwd = getpwuid(getuid());
const char *homedir = getenv("HOME");
if (pwd)
histfile = string(pwd->pw_dir);
if (homedir) // $HOME overrides what the OS tells us
histfile = string(homedir);
if (histfile.empty()) // Fall back to CWD
histfile = "./";
histfile.append(".dnsdist_history");

set<string> dupper;
{
ifstream history(".dnsdist_history");
ifstream history(histfile);
string line;
while(getline(history, line))
add_history(line.c_str());
}
ofstream history(".dnsdist_history", std::ios_base::app);
ofstream history(histfile, std::ios_base::app);
string lastline;
for(;;) {
char* sline = readline("> ");
Expand Down

0 comments on commit a1e6a66

Please sign in to comment.