1: 
   2: 
   3: /**********************
   4: *                     *
   5: *  COMPILER INCLUDES  *
   6: *                     *
   7: **********************/
   8: 
   9: 
  10: #include <iostream> 
  11: #include <signal.h> 
  12: #include <unistd.h> 
  13: 
  14: 
  15: /*********************
  16: *                    *
  17: *  PROJECT INCLUDES  *
  18: *                    *
  19: *********************/
  20:  
  21: 
  22: #include "mind.h" 
  23: #include "am.h" 
  24: #include "dnsconfig.h" 
  25: #include "ex.h" 
  26: #include "loghandle.h" 
  27: #include "mindlog.h" 
  28: #include "dnssocket.h" 
  29: #include "dthreadpool.h" 
  30: #include "requestworker.h" 
  31: #include "rrcache.h" 
  32: #include "wwwi/daemon.h" 
  33: #include "wwwi/exception.h" 
  34: 
  35: 
  36: using std::cerr;
  37: using WWWI::BecomeDaemon;
  38: using WWWI::Exception;
  39: 
  40: 
  41: /************************
  42: *                       *
  43: *  FUNCTION PROTOTYPES  *
  44: *                       *
  45: ************************/
  46: 
  47: 
  48: void sigint_handler(int);
  49: void InitializeRootServers(void);
  50: 
  51: 
  52: /*********************
  53: *                    *
  54: *  GLOBAL VARIABLES  *
  55: *                    *
  56: *********************/
  57: 
  58: 
  59: bool g_bDone = false;
  60: 
  61: 
  62: /******************
  63: *                 *
  64: *  FUNCTION MAIN  *
  65: *                 *
  66: ******************/
  67: 
  68: 
  69: int main(int argc, char **argv) {
  70:   try {
  71: 
  72: #ifdef USE_DEBUG_POINTERS 
  73:     GetSingleton<RefMgr<LabelList> >();
  74:     GetSingleton<RefMgr<RData> >();
  75:     GetSingleton<RefMgr<RR> >();
  76:     GetSingleton<RefMgr<CacheRR> >();
  77:     GetSingleton<RefMgr<RRList> >();
  78:     GetSingleton<RefMgr<CacheRRList> >();
  79:     GetSingleton<RefMgr<Question> >();
  80:     GetSingleton<RefMgr<Request> >();
  81:     GetSingleton<RefMgr<Response> >();
  82:     GetSingleton<RefMgr<DNSPacket> >();
  83: #endif 
  84: 
  85: #ifndef NDEBUG 
  86:     GetSingleton<AM<Label> >();
  87:     GetSingleton<AM<LabelList> >();
  88:     GetSingleton<AM<RR> >();
  89:     GetSingleton<AM<CacheRR> >();
  90: #endif 
  91: 
  92:     DNSConfigPtr dcp = GetSingleton<DNSConfig>();
  93:     dcp->Configure(argc,argv);
  94: 
  95:     if (dcp->GetDaemon()==true) BecomeDaemon();
  96: 
  97:     DNSSocketPtr dsp = new DNSSocket(dcp->GetUDPClientInterface(),dcp->GetUDPClientPort());
  98: 
  99:     {
 100:       DynamicThreadPool<RequestWorker,DNSSocketPtr> dl(2,5,dsp);
 101:       while (1) sleep(60);
 102:     }
 103:     dsp->Close();
 104: 
 105:     delete dsp;
 106: 
 107:   } catch (MindEx &exr) {
 108:     LogHandle lh(LF_MISC,LY_FAILURE);
 109:     lh << (const char*)argv[0] << ": fatal " << exr.name() << ": " 
 110:        << exr.what() << endl;
 111:   } catch (exception &exr) {
 112:     LogHandle lh(LF_MISC,LY_FAILURE);
 113:     lh << (const char*)argv[0] << ": fatal exception: " << exr.what() << endl;
 114:   } catch (WWWI::Exception &exr) {
 115:     LogHandle lh(LF_MISC,LY_FAILURE);
 116:     lh << (const char*)argv[0] << ": library exception: " << exr.m_strMessage << endl;
 117:   }
 118:   return 0;
 119: }
 120: 
 121: 
 122: /****************************
 123: *                           *
 124: *  FUNCTION SIGINT_HANDLER  *
 125: *                           *
 126: ****************************/
 127: 
 128: 
 129: void sigint_handler(int) {
 130:   g_bDone = true;
 131: }
 132: 
 133:  
 134: