2 PowerDNS Versatile Database Driven Nameserver
3 Copyright (C) 2006 - 2011 PowerDNS.COM BV
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
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.
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
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "rec_channel.hh"
20 #include "pdnsexception.hh"
21 #include "arguments.hh"
24 #include "namespaces.hh"
37 static void initArguments(int argc
, char** argv
)
39 arg().set("config-dir","Location of configuration directory (recursor.conf)")=SYSCONFDIR
;
41 arg().set("socket-dir","Where the controlsocket will live")=LOCALSTATEDIR
;
42 arg().set("process","When controlling multiple recursors, the target process number")="";
43 arg().set("timeout", "Number of seconds to wait for the recursor to respond")="5";
44 arg().set("config-name","Name of this virtual configuration - will rename the binary image")="";
45 arg().setCmd("help","Provide this helpful message");
47 arg().laxParse(argc
,argv
);
48 if(arg().getCommands().empty() || arg().mustDo("help")) {
49 cerr
<<"syntax: rec_control [options] command, options as below: "<<endl
<<endl
;
50 cerr
<<arg().helpstring(arg()["help"])<<endl
;
54 string configname
=::arg()["config-dir"]+"/recursor.conf";
55 if (::arg()["config-name"] != "")
56 configname
=::arg()["config-dir"]+"/recursor-"+::arg()["config-name"]+".conf";
58 cleanSlashes(configname
);
60 if(!::arg().preParseFile(configname
.c_str(), "socket-dir", LOCALSTATEDIR
))
61 cerr
<<"Warning: unable to parse configuration file '"<<configname
<<"'"<<endl
;
62 arg().laxParse(argc
,argv
); // make sure the commandline wins
65 int main(int argc
, char** argv
)
68 initArguments(argc
, argv
);
69 RecursorControlChannel rccS
;
70 string sockname
="pdns_recursor";
72 if (arg()["config-name"] != "")
73 sockname
+="-"+arg()["config-name"];
75 if(!arg()["process"].empty())
76 sockname
+="."+arg()["process"];
78 sockname
.append(".controlsocket");
80 rccS
.connect(arg()["socket-dir"], sockname
);
82 const vector
<string
>&commands
=arg().getCommands();
84 for(unsigned int i
=0; i
< commands
.size(); ++i
) {
90 string receive
=rccS
.recv(0, arg().asNum("timeout"));
94 catch(PDNSException
& ae
)
96 cerr
<<"Fatal: "<<ae
.reason
<<"\n";