4 * The secure anycast tunneling protocol (satp) defines a protocol used
5 * for communication between any combination of unicast and anycast
6 * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
7 * mode and allows tunneling of every ETHER TYPE protocol (e.g.
8 * ethernet, ip, arp ...). satp directly includes cryptography and
9 * message authentication based on the methodes used by SRTP. It is
10 * intended to deliver a generic, scaleable and secure solution for
11 * tunneling and relaying of packets of any protocol.
14 * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl,
15 * Christian Pointner <satp@wirdorange.org>
17 * This file is part of Anytun.
19 * Anytun is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation, either version 3 of the License, or
24 * Anytun is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with anytun. If not, see <http://www.gnu.org/licenses/>.
35 #include <boost/bind.hpp>
37 #include "signalController.h"
39 #include "anytunError.h"
40 #include "threadUtils.hpp"
42 SignalController* SignalController::inst = NULL;
43 Mutex SignalController::instMutex;
44 SignalController& gSignalController = SignalController::instance();
46 SignalController& SignalController::instance()
49 static instanceCleaner c;
51 inst = new SignalController();
57 int SigErrorHandler(int /*sig*/, const std::string& msg)
59 AnytunError::throwErr() << msg;
64 //use system specific signal handler
66 #include "signalHandler.hpp"
69 #include "win32/signalServiceHandler.hpp"
71 #include "win32/signalHandler.hpp"
75 void SignalController::init(DaemonService& service)
77 registerSignalHandler(*this, service);
78 handler[SIGERROR] = boost::bind(SigErrorHandler, _1, _2);
81 void SignalController::inject(int sig, const std::string& msg)
84 Lock lock(sigQueueMutex);
85 sigQueue.push(SigPair(sig, msg));
90 int SignalController::run()
92 for(CallbackMap::iterator it = callbacks.begin(); it != callbacks.end(); ++it)
93 if(it->first == CALLB_RUNNING) {
102 Lock lock(sigQueueMutex);
103 sig = sigQueue.front();
107 HandlerMap::iterator it = handler.find(sig.first);
108 if(it != handler.end()) {
109 ret = it->second(sig.first, sig.second);
115 it = handler.find(SIGUNKNOWN);
116 if(it != handler.end()) {
117 it->second(sig.first, sig.second);
119 cLog.msg(Log::PRIO_NOTICE) << "SIG " << sig.first << " caught with message '" << sig.second << "' - ignoring";
124 for(CallbackMap::iterator it = callbacks.begin(); it != callbacks.end(); ++it)
125 if(it->first == CALLB_STOPPING) {