X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;ds=sidebyside;f=src%2Fnet.c;h=d80a7129de593312c9912ed3e917c5e95d97dc6e;hb=refs%2Fheads%2F1.1-threads;hp=2ffe03a7b39a7985fdb01a7ab1108880a62c0184;hpb=6834b882015a9323672e9fce8811aa4283f196f0;p=tinc diff --git a/src/net.c b/src/net.c index 2ffe03a7..d80a7129 100644 --- a/src/net.c +++ b/src/net.c @@ -38,6 +38,7 @@ int contradicting_add_edge = 0; int contradicting_del_edge = 0; +bool running = true; /* Purge edges and subnets of unreachable nodes. Use carefully. */ @@ -198,7 +199,7 @@ static void timeout_handler(void *arg) { if(rand() % 3 == 0) { logger(LOG_ERR, "Shutting down, check configuration of all nodes for duplicate Names!"); - abort(); + running = false; return; } @@ -215,13 +216,12 @@ void handle_meta_connection_data(void *data) { int result; socklen_t len = sizeof result; - if(c->status.connecting) { - c->status.connecting = false; - - getsockopt(c->socket, SOL_SOCKET, SO_ERROR, &result, &len); + while(c->status.connecting) { + result = connect(c->socket, &c->address.sa, SALEN(c->address.sa)); if(!result) { mutex_lock(&mutex); + c->status.connecting = false; finish_connecting(c); mutex_unlock(&mutex); } else { @@ -229,10 +229,10 @@ void handle_meta_connection_data(void *data) { "Error while connecting to %s (%s): %s", c->name, c->hostname, sockstrerror(result)); closesocket(c->socket); + c->status.connecting = false; mutex_lock(&mutex); do_outgoing_connection(c); mutex_unlock(&mutex); - return; } } @@ -244,16 +244,6 @@ void handle_meta_connection_data(void *data) { } } -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; @@ -268,7 +258,7 @@ int reload_configuration(void) { if(!read_server_config()) { logger(LOG_ERR, "Unable to reread configuration file, exitting."); - abort(); + running = false; return EINVAL; } @@ -361,17 +351,7 @@ int main_loop(void) { 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) { + while(running) { mutex_unlock(&mutex); usleep(1000000); mutex_lock(&mutex);