int contradicting_add_edge = 0;
int contradicting_del_edge = 0;
+bool running = true;
/* Purge edges and subnets of unreachable nodes. Use carefully. */
}
}
-static void sigterm_handler(int signal, short events, void *data) {
- logger(LOG_NOTICE, "Got %s signal", strsignal(signal));
- exit(0);
-}
-
-static void sighup_handler(int signal, short events, void *data) {
- logger(LOG_NOTICE, "Got %s signal", strsignal(signal));
- reload_configuration();
-}
-
int reload_configuration(void) {
connection_t *c;
splay_node_t *node, *next;
event_add(&timeout_event);
-#ifdef SIGHUP
- signal(SIGHUP, sighup_handler);
-#endif
-#ifdef SIGTERM
- signal(SIGTERM, sigterm_handler);
-#endif
-#ifdef SIGQUIT
- signal(SIGQUIT, sigterm_handler);
-#endif
while(true) {
mutex_unlock(&mutex);
#endif
extern mutex_t mutex;
+extern bool running;
#endif /* __TINC_NET_H__ */
*/
#ifndef HAVE_MINGW
+static RETSIGTYPE sigterm_handler(int a) {
+ logger(LOG_NOTICE, "Got %s signal", "TERM");
+ if(running)
+ running = false;
+ else
+ exit(1);
+}
+
static RETSIGTYPE fatal_signal_square(int a) {
logger(LOG_ERR, "Got another fatal signal %d (%s): not restarting.", a,
strsignal(a));
int signal;
void (*handler)(int);
} sighandlers[] = {
+ {SIGTERM, sigterm_handler},
+ {SIGQUIT, sigterm_handler},
+ {SIGINT, sigterm_handler},
{SIGSEGV, fatal_signal_handler},
{SIGBUS, fatal_signal_handler},
{SIGILL, fatal_signal_handler},
{SIGPIPE, ignore_signal_handler},
{SIGCHLD, ignore_signal_handler},
+ {SIGALRM, ignore_signal_handler},
{0, NULL}
};
#endif
typedef pthread_mutex_t mutex_t;
static inline bool thread_create(thread_t *tid, void (*func)(void *), void *arg) {
- return !pthread_create(tid, NULL, (void *(*)(void *))func, arg);
+ bool result;
+
+ sigset_t old, block;
+ sigfillset(&block);
+ pthread_sigmask(SIG_SETMASK, &block, &old);
+ result = pthread_create(tid, NULL, (void *(*)(void *))func, arg);
+ pthread_sigmask(SIG_SETMASK, &old, NULL);
+ return !result;
}
static inline void thread_destroy(thread_t *tid) {
pthread_cancel(*tid);