]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/communicator.cc
add OpenSSL exception to PowerDNS, Netherlabs, van Dijk and Hubert copyrights
[thirdparty/pdns.git] / pdns / communicator.cc
CommitLineData
12c86877
BH
1/*
2 PowerDNS Versatile Database Driven Nameserver
f309dacd 3 Copyright (C) 2002-2011 PowerDNS.COM BV
12c86877
BH
4
5 This program is free software; you can redistribute it and/or modify
4cf26303
BH
6 it under the terms of the GNU General Public License version 2 as
7 published by the Free Software Foundation;
12c86877 8
f782fe38
MH
9 Additionally, the license of this program contains a special
10 exception which allows to distribute the program in binary form when
11 it is linked against OpenSSL.
12
12c86877
BH
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
06bd9ccf 20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12c86877 21*/
379ab445 22#include "packetcache.hh"
12c86877
BH
23#include "utility.hh"
24#include <errno.h>
25#include "communicator.hh"
26#include <set>
4232a932 27#include <boost/utility.hpp>
12c86877
BH
28#include "dnsbackend.hh"
29#include "ueberbackend.hh"
30#include "packethandler.hh"
31#include "resolver.hh"
32#include "logger.hh"
33#include "dns.hh"
34#include "arguments.hh"
35#include "session.hh"
13597144 36#include "packetcache.hh"
02b37061
BH
37#include <boost/lexical_cast.hpp>
38
dbcb3066 39// #include "namespaces.hh"
13597144 40
dbcb3066
BH
41void CommunicatorClass::retrievalLoopThread(void)
42{
43 for(;;) {
44 d_suck_sem.wait();
45 SuckRequest sr;
46 {
47 Lock l(&d_lock);
48 if(d_suckdomains.empty())
f2d26033 49 continue;
dbcb3066
BH
50
51 sr=d_suckdomains.front();
f4ce804f 52 d_suckdomains.pop_front();
dbcb3066 53 }
480fbb40 54 suck(sr.domain,sr.master);
dbcb3066
BH
55 }
56}
57
dbcb3066
BH
58void CommunicatorClass::go()
59{
60 pthread_t tid;
a71bee29 61 pthread_create(&tid,0,&launchhelper,this); // Starts CommunicatorClass::mainloop()
dbcb3066 62 for(int n=0; n < ::arg().asNum("retrieval-threads"); ++n)
a71bee29 63 pthread_create(&tid, 0, &retrieveLaunchhelper, this); // Starts CommunicatorClass::retrievalLoopThread()
dbcb3066 64
8db49a64 65 d_preventSelfNotification =::arg().mustDo("prevent-self-notification");
dbcb3066 66}
12c86877
BH
67
68void CommunicatorClass::mainloop(void)
69{
70 try {
12c86877 71 signal(SIGPIPE,SIG_IGN);
12c86877
BH
72 L<<Logger::Error<<"Master/slave communicator launching"<<endl;
73 PacketHandler P;
379ab445 74 d_tickinterval=::arg().asNum("slave-cycle-interval");
0c01dd7c 75 makeNotifySockets();
12c86877
BH
76
77 int rc;
7f3d870e 78 time_t next, tick;
12c86877
BH
79
80 for(;;) {
81 slaveRefresh(&P);
82 masterUpdateCheck(&P);
7f3d870e 83 tick=doNotifications(); // this processes any notification acknowledgements and actually send out our own notifications
3696224d
BH
84
85 tick = min (tick, d_tickinterval);
7f3d870e 86
12c86877
BH
87 next=time(0)+tick;
88
88c0425a 89 while(time(0) < next) {
4957a608 90 rc=d_any_sem.tryWait();
12c86877 91
4957a608
BH
92 if(rc)
93 Utility::sleep(1);
94 else {
7f3d870e 95 break; // something happened
4957a608
BH
96 }
97 // this gets executed at least once every second
98 doNotifications();
12c86877
BH
99 }
100 }
101 }
3f81d239 102 catch(PDNSException &ae) {
b88b9a11 103 L<<Logger::Error<<"Exiting because communicator thread died with error: "<<ae.reason<<endl;
ac2bb9e7 104 Utility::sleep(1);
12c86877
BH
105 exit(0);
106 }
0c70797e 107 catch(std::exception &e) {
b88b9a11 108 L<<Logger::Error<<"Exiting because communicator thread died with STL error: "<<e.what()<<endl;
12c86877
BH
109 exit(0);
110 }
111 catch( ... )
112 {
b88b9a11 113 L << Logger::Error << "Exiting because communicator caught unknown exception." << endl;
12c86877
BH
114 exit( 0 );
115 }
116}
117