From: Otto Date: Mon, 15 Feb 2021 10:42:10 +0000 (+0100) Subject: AlLow - for stdout, does need a tweak in the argument parser... X-Git-Tag: dnsdist-1.6.0-alpha2~39^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e4bbf5d58e7aa2d5c1941a304b1866b1462e8e4;p=thirdparty%2Fpdns.git AlLow - for stdout, does need a tweak in the argument parser... --- diff --git a/pdns/arguments.cc b/pdns/arguments.cc index 4a8c69b03b..aa21f6ded6 100644 --- a/pdns/arguments.cc +++ b/pdns/arguments.cc @@ -347,7 +347,7 @@ void ArgvMap::parseOne(const string &arg, const string &parseOnly, bool lax) var=arg.substr(2); val=""; } - else if(arg[0]=='-') + else if(arg[0]=='-' && arg.length() > 1) { var=arg.substr(1); val=""; diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index bb6ffb307e..1b7540bcf6 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -303,6 +303,7 @@ static uint64_t* pleaseDumpFailedServers(int fd) return new uint64_t(SyncRes::doDumpFailedServers(fd)); } +// Generic dump to file command static RecursorControlChannel::Answer doDumpToFile(int s, uint64_t* (*function)(int s), const string& name) { int fd = getfd(s); @@ -323,13 +324,14 @@ static RecursorControlChannel::Answer doDumpToFile(int s, uint64_t* (*function)( catch(PDNSException& e) { close(fd); - return { 1, name + ": error dumping NS speeds: " + e.reason + "\n" }; + return { 1, name + ": error dumping data: " + e.reason + "\n" }; } close(fd); - return { 0, name+ ": dumped " + std::to_string(total)+" records\n" }; + return { 0, name + ": dumped " + std::to_string(total) + " records\n" }; } +// Does not follow the generic dump to file pattern, has a more complex lambda static RecursorControlChannel::Answer doDumpCache(int s) { int fd = getfd(s); @@ -347,6 +349,7 @@ static RecursorControlChannel::Answer doDumpCache(int s) return { 0, "dumped " + std::to_string(total) + " records\n" }; } +// Does not follow the generic dump to file pattern, has an argument template static RecursorControlChannel::Answer doDumpRPZ(int s, T begin, T end) { diff --git a/pdns/rec_control.cc b/pdns/rec_control.cc index 701e8824b6..942058abf1 100644 --- a/pdns/rec_control.cc +++ b/pdns/rec_control.cc @@ -116,21 +116,29 @@ int main(int argc, char** argv) command += " "; } command += commands[i]; - if (fileCommands.count(commands[i]) > 0 && i+1 < commands.size()) { - // dump-rpz is different, it also has a zonename as argument - if (commands[i] == "dump-rpz" && i+2 < commands.size()) { + if (fileCommands.count(commands[i]) > 0) { + if (i + 1 < commands.size()) { + // dump-rpz is different, it also has a zonename as argument + if (commands[i] == "dump-rpz") { + if (i + 2 < commands.size()) { + ++i; + command += " " + commands[i]; // add rpzname and continue with filename + } else { + throw PDNSException("Command needs a zone and file argument"); + } + } ++i; - command += " " + commands[i]; // add rpzname and continue with filename - } - ++i; - if (commands[i] == "stdout") { - fd = STDOUT_FILENO; + if (commands[i] == "-") { + fd = STDOUT_FILENO; + } else { + 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)); + } } else { - 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)); + throw PDNSException("Command needs a file argument"); } } ++i;