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-2008 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 version 3 as
21 * published by the Free Software Foundation.
23 * Anytun is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with anytun. If not, see <http://www.gnu.org/licenses/>.
37 #include <boost/bind.hpp>
38 #include "threadUtils.hpp"
39 #include "signalController.h"
43 int SigIntHandler::handle()
45 cLog
.msg(Log::PRIO_NOTICE
) << "SIG-Int caught, exiting";
50 int SigQuitHandler::handle()
52 cLog
.msg(Log::PRIO_NOTICE
) << "SIG-Quit caught, exiting";
57 int SigHupHandler::handle()
59 cLog
.msg(Log::PRIO_NOTICE
) << "SIG-Hup caught";
64 int SigTermHandler::handle()
66 cLog
.msg(Log::PRIO_NOTICE
) << "SIG-Term caughtm, exiting";
71 int SigUsr1Handler::handle()
73 cLog
.msg(Log::PRIO_NOTICE
) << "SIG-Usr1 caught";
78 int SigUsr2Handler::handle()
80 cLog
.msg(Log::PRIO_NOTICE
) << "SIG-Usr2 caught";
85 SignalController::~SignalController()
87 for(HandlerMap::iterator it
= handler
.begin(); it
!= handler
.end(); ++it
)
89 if(thread
) delete thread
;
92 void SignalController::handle(void *s
)
94 SignalController
* self
= reinterpret_cast<SignalController
*>(s
);
100 sigfillset(&signal_set
);
101 sigwait(&signal_set
, &sigNum
);
103 Lock(self
->sigQueueMutex
);
104 self
->sigQueue
.push(sigNum
);
106 self
->sigQueueSem
.up();
110 void SignalController::init()
114 sigfillset(&signal_set
);
115 sigdelset(&signal_set
, SIGCHLD
);
116 sigdelset(&signal_set
, SIGSEGV
);
117 sigdelset(&signal_set
, SIGBUS
);
118 sigdelset(&signal_set
, SIGFPE
);
120 #if defined(BOOST_HAS_PTHREADS)
121 pthread_sigmask(SIG_BLOCK
, &signal_set
, NULL
);
123 #error The signalhandler works only with pthreads
126 thread
= new boost::thread(boost::bind(handle
, this));
128 handler
[SIGINT
] = new SigIntHandler
;
129 handler
[SIGQUIT
] = new SigQuitHandler
;
130 handler
[SIGHUP
] = new SigHupHandler
;
131 handler
[SIGTERM
] = new SigTermHandler
;
132 handler
[SIGUSR1
] = new SigUsr1Handler
;
133 handler
[SIGUSR2
] = new SigUsr2Handler
;
136 int SignalController::run()
143 Lock
lock(sigQueueMutex
);
144 sigNum
= sigQueue
.front();
148 HandlerMap::iterator it
= handler
.find(sigNum
);
149 if(it
!= handler
.end())
151 int ret
= it
->second
->handle();
156 cLog
.msg(Log::PRIO_NOTICE
) << "SIG " << sigNum
<< " caught - ignoring";