]>
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> | |
20 | #include "ahuexception.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"; |
aaacf7f2 BH |
44 | arg().setCmd("help","Provide this helpful message"); |
45 | ||
46 | arg().laxParse(argc,argv); | |
85c143a2 BH |
47 | if(arg().getCommands().empty() || arg().mustDo("help")) { |
48 | cerr<<"syntax: rec_control [options] command, options as below: "<<endl<<endl; | |
aaacf7f2 BH |
49 | cerr<<arg().helpstring(arg()["help"])<<endl; |
50 | exit(99); | |
51 | } | |
aaacf7f2 BH |
52 | } |
53 | ||
f6f016d1 | 54 | int main(int argc, char** argv) |
1d5b3ce6 | 55 | try |
f6f016d1 | 56 | { |
aaacf7f2 BH |
57 | initArguments(argc, argv); |
58 | ||
1d5b3ce6 | 59 | RecursorControlChannel rccS; |
677e2a46 BH |
60 | string sockname="pdns_recursor"; |
61 | if(!arg()["process"].empty()) | |
62 | sockname+="."+arg()["process"]; | |
63 | ||
64 | sockname.append(".controlsocket"); | |
41f7a068 BH |
65 | |
66 | rccS.connect(arg()["socket-dir"], sockname); | |
1d5b3ce6 | 67 | |
aaacf7f2 | 68 | const vector<string>&commands=arg().getCommands(); |
1d5b3ce6 | 69 | string command; |
a2bfc3ff | 70 | for(unsigned int i=0; i< commands.size(); ++i) { |
aaacf7f2 | 71 | if(i>0) |
1d5b3ce6 | 72 | command+=" "; |
aaacf7f2 | 73 | command+=commands[i]; |
1d5b3ce6 | 74 | } |
1d5b3ce6 | 75 | rccS.send(command); |
61203240 | 76 | string receive=rccS.recv(0, arg().asNum("timeout")); |
1d5b3ce6 | 77 | cout<<receive; |
dd9e83ed | 78 | return 0; |
1d5b3ce6 BH |
79 | } |
80 | catch(AhuException& ae) | |
81 | { | |
82 | cerr<<"Fatal: "<<ae.reason<<"\n"; | |
dd9e83ed | 83 | return 1; |
f6f016d1 | 84 | } |