X-Git-Url: https://git.syn-net.org/debian/?p=anytun.git;a=blobdiff_plain;f=src%2Fanytun-controld.cpp;h=767db53fa64ec19c6ad3f31fa2215a5566b2cc36;hp=1dbc6f89be6aa5a8ae4ea64d5eadbe049f62de41;hb=ece844834d2cecc028ce81ca283f5d441088580e;hpb=bb834fe0ed7a38b724f49b944adb801634eb6194 diff --git a/src/anytun-controld.cpp b/src/anytun-controld.cpp index 1dbc6f8..767db53 100644 --- a/src/anytun-controld.cpp +++ b/src/anytun-controld.cpp @@ -46,18 +46,16 @@ #include "resolver.h" #include "syncServer.h" -#include "daemon.hpp" +#include "daemonService.h" +#include + +std::list config_; void syncOnConnect(SyncTcpConnection * connptr) { - std::ifstream file(gOpt.getFileName().c_str()); - if(file.is_open()) { - std::string line; - while (!file.eof()) { - getline (file,line); - connptr->Send(line); - } - file.close(); + for(std::list::const_iterator it=config_.begin(); it!=config_.end();++it) + { + connptr->Send(*it); } } @@ -79,25 +77,17 @@ void syncListener() int main(int argc, char* argv[]) { - bool daemonized=false; + DaemonService service; try { try { - bool result = gOpt.parse(argc, argv); - if(!result) { - gOpt.printUsage(); + if(!gOpt.parse(argc, argv)) exit(0); - } + StringList targets = gOpt.getLogTargets(); - if(targets.empty()) { - cLog.addTarget("syslog:3,anytun-controld,daemon"); - } - else { - StringList::const_iterator it; - for(it = targets.begin();it != targets.end(); ++it) - cLog.addTarget(*it); - } + for(StringList::const_iterator it = targets.begin();it != targets.end(); ++it) + cLog.addTarget(*it); } catch(syntax_error& e) { @@ -112,25 +102,28 @@ int main(int argc, char* argv[]) std::ifstream file( gOpt.getFileName().c_str() ); if( file.is_open() ) + { + std::string line; + while (!file.eof()) { + getline (file,line); + config_.push_back(line); + } file.close(); - else { + } else { std::cout << "ERROR: unable to open file!" << std::endl; exit(-1); } - PrivInfo privs(gOpt.getUsername(), gOpt.getGroupname()); - if(gOpt.getDaemonize()) { - daemonize(); - daemonized = true; - } + service.initPrivs(gOpt.getUsername(), gOpt.getGroupname()); + if(gOpt.getDaemonize()) + service.daemonize(); - gSignalController.init(); - gResolver.init(); - if(gOpt.getChrootDir() != "") - do_chroot(gOpt.getChrootDir()); - - privs.drop(); + service.chroot(gOpt.getChrootDir()); + service.dropPrivs(); + + gSignalController.init(service); + gResolver.init(); boost::thread * syncListenerThread; syncListenerThread = new boost::thread(boost::bind(syncListener)); @@ -141,14 +134,14 @@ int main(int argc, char* argv[]) } catch(std::runtime_error& e) { - if(daemonized) + if(service.isDaemonized()) cLog.msg(Log::PRIO_ERROR) << "uncaught runtime error, exiting: " << e.what(); else std::cout << "uncaught runtime error, exiting: " << e.what() << std::endl; } catch(std::exception& e) { - if(daemonized) + if(service.isDaemonized()) cLog.msg(Log::PRIO_ERROR) << "uncaught exception, exiting: " << e.what(); else std::cout << "uncaught exception, exiting: " << e.what() << std::endl;