summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2009-03-10 14:38:34 +0000
committerChristian Pointner <equinox@anytun.org>2009-03-10 14:38:34 +0000
commit591078f9c90100b1f6926bdac55877aa864f2238 (patch)
tree1f75aa9a53896e938a9c0ca8fe1021ab04e19625 /src
parentchanged packetSource to use gResolver (diff)
added SIGERROR to signal Controller
Diffstat (limited to 'src')
-rw-r--r--src/Makefile3
-rw-r--r--src/resolver.cpp9
-rw-r--r--src/signalController.cpp28
-rw-r--r--src/signalController.h15
4 files changed, 43 insertions, 12 deletions
diff --git a/src/Makefile b/src/Makefile
index 4f75c70..78806ee 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -97,8 +97,7 @@ ANYCONFOBJS := log.o \
syncServer.o \
syncTcpConnection.o \
syncRouteCommand.o \
- syncConnectionCommand.o \
- resolver.o
+ syncConnectionCommand.o
EXECUTABLE := anytun anytun-config anytun-controld anytun-showtables anytun-nosync
EXEOBJS := anytun.o anytun-config.o anytun-controld.o anytun-showtables.o
diff --git a/src/resolver.cpp b/src/resolver.cpp
index 6d5c777..5e2d862 100644
--- a/src/resolver.cpp
+++ b/src/resolver.cpp
@@ -34,6 +34,7 @@
#include "resolver.h"
#include "log.h"
+#include "signalController.h"
using ::boost::asio::ip::udp;
using ::boost::asio::ip::tcp;
@@ -68,7 +69,13 @@ template<class Proto>
void ResolveHandler<Proto>::operator()(const boost::system::error_code& e, const boost::asio::ip::basic_resolver_iterator<Proto> endpointIt)
{
if(boost::system::posix_error::success == e) {
- callback_(*endpointIt);
+ try {
+ callback_(*endpointIt);
+ }
+ catch(const std::runtime_error& e)
+ {
+ gSignalController.inject(SIGERROR, e.what());
+ }
} else {
cLog.msg(Log::PRIO_ERROR) << "Error while resolving '" << addr_ << "' '" << port_ << "', retrying in 10 sec.";
boost::thread(boost::bind(waitAndEnqueue<Proto>, 10, addr_, port_, callback_, resolv_addr_type_));
diff --git a/src/signalController.cpp b/src/signalController.cpp
index e8d231e..b2017fd 100644
--- a/src/signalController.cpp
+++ b/src/signalController.cpp
@@ -58,6 +58,13 @@ SignalController& SignalController::instance()
return *inst;
}
+int SigErrorHandler::handle(const std::string& msg)
+{
+ AnytunError::throwErr() << msg;
+
+ return 0;
+}
+
#ifndef _MSC_VER
int SigIntHandler::handle()
@@ -204,13 +211,15 @@ void SignalController::init()
handler[CTRL_LOGOFF_EVENT] = new CtrlLogoffHandler;
handler[CTRL_SHUTDOWN_EVENT] = new CtrlShutdownHandler;
#endif
+
+ handler[SIGERROR] = new SigErrorHandler;
}
-void SignalController::inject(int sig)
+void SignalController::inject(int sig, const std::string& msg)
{
{
Lock lock(sigQueueMutex);
- sigQueue.push(sig);
+ sigQueue.push(SigPair(sig, msg));
}
sigQueueSem.up();
}
@@ -219,22 +228,27 @@ int SignalController::run()
{
while(1) {
sigQueueSem.down();
- int sigNum;
+ SigPair sig;
{
Lock lock(sigQueueMutex);
- sigNum = sigQueue.front();
+ sig = sigQueue.front();
sigQueue.pop();
}
- HandlerMap::iterator it = handler.find(sigNum);
+ HandlerMap::iterator it = handler.find(sig.first);
if(it != handler.end())
{
- int ret = it->second->handle();
+ int ret;
+ if(sig.second == "")
+ ret = it->second->handle();
+ else
+ ret = it->second->handle(sig.second);
+
if(ret)
return ret;
}
else
- cLog.msg(Log::PRIO_NOTICE) << "SIG " << sigNum << " caught - ignoring";
+ cLog.msg(Log::PRIO_NOTICE) << "SIG " << sig.first << " caught with message '" << sig.second << "'- ignoring";
}
return 0;
}
diff --git a/src/signalController.h b/src/signalController.h
index ba46de0..575b50b 100644
--- a/src/signalController.h
+++ b/src/signalController.h
@@ -41,12 +41,15 @@
#include <csignal>
#endif
+#define SIGERROR -1
+
class SignalHandler
{
public:
virtual ~SignalHandler() {}
virtual int handle() { return 0; }
+ virtual int handle(const std::string& msg) { return 0; }
protected:
SignalHandler(int s) : sigNum(s) {}
@@ -56,6 +59,13 @@ private:
friend class SignalController;
};
+class SigErrorHandler : public SignalHandler
+{
+public:
+ SigErrorHandler() : SignalHandler(SIGERROR) {}
+ int handle(const std::string& msg);
+};
+
#ifndef _MSC_VER
class SigIntHandler : public SignalHandler
{
@@ -149,7 +159,7 @@ public:
void init();
int run();
- void inject(int sig);
+ void inject(int sig, const std::string& msg = "");
private:
typedef std::map<int, SignalHandler*> HandlerMap;
@@ -173,7 +183,8 @@ private:
};
friend class instanceCleaner;
- std::queue<int> sigQueue;
+ typedef std::pair<int, std::string> SigPair;
+ std::queue<SigPair> sigQueue;
Mutex sigQueueMutex;
Semaphore sigQueueSem;