root/trunk/pdns/pdns/rec_control.cc @ 1696

Revision 1696, 2.3 KB (checked in by ahu, 3 years ago)

make sure rec_control builds again

Line 
1/*
2    PowerDNS Versatile Database Driven Nameserver
3    Copyright (C) 2006 PowerDNS.COM BV
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
16    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17*/
18#include "rec_channel.hh"
19#include <iostream>
20#include "ahuexception.hh"
21#include "arguments.hh"
22#include "config.h"
23
24using namespace std;
25
26#ifndef RECURSOR
27#include "statbag.hh"
28StatBag S;
29#endif
30
31ArgvMap &arg()
32{
33  static ArgvMap arg;
34  return arg;
35}
36
37static void initArguments(int argc, char** argv)
38{
39  arg().set("config-dir","Location of configuration directory (pdns.conf)")=SYSCONFDIR;
40
41  arg().set("socket-dir","Where the controlsocket will live")=LOCALSTATEDIR;
42  arg().set("socket-pid","When controlling multiple recursors, the target pid")="";
43  arg().set("timeout", "Number of seconds to wait for the recursor to respond")="5";
44  arg().setCmd("help","Provide this helpful message");
45
46  arg().laxParse(argc,argv); 
47  if(arg().getCommands().empty() || arg().mustDo("help")) {
48    cerr<<"syntax: rec_control [options] command, options as below: "<<endl<<endl;
49    cerr<<arg().helpstring(arg()["help"])<<endl;
50    exit(99);
51  }
52
53}
54
55int main(int argc, char** argv)
56try
57{
58  initArguments(argc, argv);
59
60  RecursorControlChannel rccS;
61  string sockname="pdns_recursor.controlsocket";
62  if(!arg()["socket-pid"].empty())
63    sockname+="."+arg()["socket-pid"];
64
65  rccS.connect(arg()["socket-dir"], sockname);
66
67  const vector<string>&commands=arg().getCommands();
68  string command;
69  for(unsigned int i=0; i< commands.size(); ++i) {
70    if(i>0)
71      command+=" ";
72    command+=commands[i];
73  }
74  rccS.send(command);
75  string receive=rccS.recv(0, arg().asNum("timeout"));
76  cout<<receive;
77  return 0;
78}
79catch(AhuException& ae)
80{
81  cerr<<"Fatal: "<<ae.reason<<"\n";
82  return 1;
83}
Note: See TracBrowser for help on using the browser.