summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/anytun-controld.cpp16
-rw-r--r--src/anytun.cpp11
2 files changed, 11 insertions, 16 deletions
diff --git a/src/anytun-controld.cpp b/src/anytun-controld.cpp
index 43196dc..767db53 100644
--- a/src/anytun-controld.cpp
+++ b/src/anytun-controld.cpp
@@ -77,7 +77,7 @@ void syncListener()
int main(int argc, char* argv[])
{
- DaemonService daemon;
+ DaemonService service;
try
{
try
@@ -114,15 +114,15 @@ int main(int argc, char* argv[])
exit(-1);
}
- daemon.initPrivs(gOpt.getUsername(), gOpt.getGroupname());
+ service.initPrivs(gOpt.getUsername(), gOpt.getGroupname());
if(gOpt.getDaemonize())
- daemon.daemonize();
+ service.daemonize();
if(gOpt.getChrootDir() != "")
- daemon.chroot(gOpt.getChrootDir());
- daemon.dropPrivs();
+ service.chroot(gOpt.getChrootDir());
+ service.dropPrivs();
- gSignalController.init();
+ gSignalController.init(service);
gResolver.init();
boost::thread * syncListenerThread;
@@ -134,14 +134,14 @@ int main(int argc, char* argv[])
}
catch(std::runtime_error& e)
{
- if(daemon.isDaemonized())
+ 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(daemon.isDaemonized())
+ if(service.isDaemonized())
cLog.msg(Log::PRIO_ERROR) << "uncaught exception, exiting: " << e.what();
else
std::cout << "uncaught exception, exiting: " << e.what() << std::endl;
diff --git a/src/anytun.cpp b/src/anytun.cpp
index a693e34..1ac9397 100644
--- a/src/anytun.cpp
+++ b/src/anytun.cpp
@@ -359,12 +359,10 @@ int main(int argc, char* argv[])
int real_main(int argc, char* argv[], WinService& service)
{
- bool daemonized=true;
#else
int main(int argc, char* argv[])
{
DaemonService service;
- bool daemonized=false;
#endif
try
{
@@ -389,10 +387,8 @@ int main(int argc, char* argv[])
// daemonizing has to done before any thread gets started
service.initPrivs(gOpt.getUsername(), gOpt.getGroupname());
- if(gOpt.getDaemonize()) {
+ if(gOpt.getDaemonize())
service.daemonize();
- daemonized = true;
- }
OptionNetwork net = gOpt.getIfconfigParam();
TunDevice dev(gOpt.getDevName(), gOpt.getDevType(), net.net_addr, net.prefix_length);
@@ -467,19 +463,18 @@ int main(int argc, char* argv[])
// delete src;
// if(connTo)
// delete connTo;
-
return ret;
}
catch(std::runtime_error& e)
{
cLog.msg(Log::PRIO_ERROR) << "uncaught runtime error, exiting: " << e.what();
- if(!daemonized)
+ if(!service.isDaemonized())
std::cout << "uncaught runtime error, exiting: " << e.what() << std::endl;
}
catch(std::exception& e)
{
cLog.msg(Log::PRIO_ERROR) << "uncaught exception, exiting: " << e.what();
- if(!daemonized)
+ if(!service.isDaemonized())
std::cout << "uncaught exception, exiting: " << e.what() << std::endl;
}
return -1;