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 anytun.org <satp@wirdorange.org>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2
18 * as published by the Free Software Foundation.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program (see the file COPYING included with this
27 * distribution); if not, write to the Free Software Foundation, Inc.,
28 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #include "threadUtils.hpp"
37 #include "signalController.h"
41 int SigIntHandler::handle()
43 cLog
.msg(Log::PRIO_NOTICE
) << "SIG-Int caught, exiting";
48 int SigQuitHandler::handle()
50 cLog
.msg(Log::PRIO_NOTICE
) << "SIG-Quit caught, exiting";
55 int SigHupHandler::handle()
57 cLog
.msg(Log::PRIO_NOTICE
) << "SIG-Hup caught";
62 int SigTermHandler::handle()
64 cLog
.msg(Log::PRIO_NOTICE
) << "SIG-Term caughtm, exiting";
69 int SigUsr1Handler::handle()
71 cLog
.msg(Log::PRIO_NOTICE
) << "SIG-Usr1 caught";
76 int SigUsr2Handler::handle()
78 cLog
.msg(Log::PRIO_NOTICE
) << "SIG-Usr2 caught";
83 SignalController::~SignalController()
85 for(HandlerMap::iterator it
= handler
.begin(); it
!= handler
.end(); ++it
)
89 void* SignalController::handle(void *s
)
91 SignalController
* self
= reinterpret_cast<SignalController
*>(s
);
97 sigfillset(&signal_set
);
98 sigwait(&signal_set
, &sigNum
);
100 Lock(self
->sigQueueMutex
);
101 self
->sigQueue
.push(sigNum
);
103 self
->sigQueueSem
.up();
108 void SignalController::init()
112 sigfillset(&signal_set
);
113 sigdelset(&signal_set
, SIGCHLD
);
114 sigdelset(&signal_set
, SIGSEGV
);
115 sigdelset(&signal_set
, SIGBUS
);
116 sigdelset(&signal_set
, SIGFPE
);
117 pthread_sigmask(SIG_BLOCK
, &signal_set
, NULL
);
119 pthread_create(&thread
, NULL
, handle
, this);
120 pthread_detach(thread
);
122 handler
[SIGINT
] = new SigIntHandler
;
123 handler
[SIGQUIT
] = new SigQuitHandler
;
124 handler
[SIGHUP
] = new SigHupHandler
;
125 handler
[SIGTERM
] = new SigTermHandler
;
126 handler
[SIGUSR1
] = new SigUsr1Handler
;
127 handler
[SIGUSR2
] = new SigUsr2Handler
;
130 int SignalController::run()
137 Lock
lock(sigQueueMutex
);
138 sigNum
= sigQueue
.front();
142 HandlerMap::iterator it
= handler
.find(sigNum
);
143 if(it
!= handler
.end())
145 int ret
= it
->second
->handle();
150 cLog
.msg(Log::PRIO_NOTICE
) << "SIG " << sigNum
<< " caught - ignoring";