]>
Commit | Line | Data |
---|---|---|
aaacf7f2 BH |
1 | /* |
2 | PowerDNS Versatile Database Driven Nameserver | |
677e2a46 | 3 | Copyright (C) 2006 - 2011 PowerDNS.COM BV |
aaacf7f2 BH |
4 | |
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License version 2 as | |
7 | published by the Free Software Foundation | |
8 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along with this program; if not, write to the Free Software | |
06bd9ccf | 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
aaacf7f2 | 17 | */ |
1d5b3ce6 BH |
18 | #include "rec_channel.hh" |
19 | #include <iostream> | |
5c409fa2 | 20 | #include "pdnsexception.hh" |
aaacf7f2 | 21 | #include "arguments.hh" |
e2928fdb | 22 | #include "config.h" |
1d5b3ce6 | 23 | |
10f4eea8 | 24 | #include "namespaces.hh" |
1d5b3ce6 | 25 | |
b0f7d001 BH |
26 | #ifndef RECURSOR |
27 | #include "statbag.hh" | |
28 | StatBag S; | |
29 | #endif | |
30 | ||
aaacf7f2 BH |
31 | ArgvMap &arg() |
32 | { | |
33 | static ArgvMap arg; | |
34 | return arg; | |
35 | } | |
36 | ||
37 | static void initArguments(int argc, char** argv) | |
38 | { | |
08b7c2e2 | 39 | arg().set("config-dir","Location of configuration directory (recursor.conf)")=SYSCONFDIR; |
41f7a068 | 40 | |
aaacf7f2 | 41 | arg().set("socket-dir","Where the controlsocket will live")=LOCALSTATEDIR; |
677e2a46 | 42 | arg().set("process","When controlling multiple recursors, the target process number")=""; |
61203240 | 43 | arg().set("timeout", "Number of seconds to wait for the recursor to respond")="5"; |
5124de27 | 44 | arg().set("config-name","Name of this virtual configuration - will rename the binary image")=""; |
aaacf7f2 BH |
45 | arg().setCmd("help","Provide this helpful message"); |
46 | ||
47 | arg().laxParse(argc,argv); | |
85c143a2 BH |
48 | if(arg().getCommands().empty() || arg().mustDo("help")) { |
49 | cerr<<"syntax: rec_control [options] command, options as below: "<<endl<<endl; | |
aaacf7f2 BH |
50 | cerr<<arg().helpstring(arg()["help"])<<endl; |
51 | exit(99); | |
52 | } | |
5124de27 | 53 | |
832ad64e | 54 | string configname=::arg()["config-dir"]+"/recursor.conf"; |
5124de27 RA |
55 | if (::arg()["config-name"] != "") |
56 | configname=::arg()["config-dir"]+"/recursor-"+::arg()["config-name"]+".conf"; | |
57 | ||
832ad64e PD |
58 | cleanSlashes(configname); |
59 | ||
60 | if(!::arg().preParseFile(configname.c_str(), "socket-dir", LOCALSTATEDIR)) | |
61 | cerr<<"Warning: unable to parse configuration file '"<<configname<<"'"<<endl; | |
effe43d0 | 62 | arg().laxParse(argc,argv); // make sure the commandline wins |
aaacf7f2 BH |
63 | } |
64 | ||
f6f016d1 | 65 | int main(int argc, char** argv) |
1d5b3ce6 | 66 | try |
f6f016d1 | 67 | { |
aaacf7f2 | 68 | initArguments(argc, argv); |
1d5b3ce6 | 69 | RecursorControlChannel rccS; |
5124de27 RA |
70 | string sockname="recursor"; |
71 | ||
72 | if (arg()["config-name"] != "") | |
73 | sockname+="-"+arg()["config-name"]; | |
74 | ||
677e2a46 BH |
75 | if(!arg()["process"].empty()) |
76 | sockname+="."+arg()["process"]; | |
77 | ||
78 | sockname.append(".controlsocket"); | |
41f7a068 BH |
79 | |
80 | rccS.connect(arg()["socket-dir"], sockname); | |
1d5b3ce6 | 81 | |
aaacf7f2 | 82 | const vector<string>&commands=arg().getCommands(); |
1d5b3ce6 | 83 | string command; |
a2bfc3ff | 84 | for(unsigned int i=0; i< commands.size(); ++i) { |
aaacf7f2 | 85 | if(i>0) |
1d5b3ce6 | 86 | command+=" "; |
aaacf7f2 | 87 | command+=commands[i]; |
1d5b3ce6 | 88 | } |
1d5b3ce6 | 89 | rccS.send(command); |
61203240 | 90 | string receive=rccS.recv(0, arg().asNum("timeout")); |
1d5b3ce6 | 91 | cout<<receive; |
dd9e83ed | 92 | return 0; |
1d5b3ce6 | 93 | } |
3f81d239 | 94 | catch(PDNSException& ae) |
1d5b3ce6 BH |
95 | { |
96 | cerr<<"Fatal: "<<ae.reason<<"\n"; | |
dd9e83ed | 97 | return 1; |
f6f016d1 | 98 | } |