From: Guus Sliepen Date: Thu, 17 May 2007 23:04:02 +0000 (+0000) Subject: Redo SIGALRM handling. X-Git-Tag: release-1.1pre1~182 X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=aaf1851315023c2f960c58a0d977085a485298e7;p=tinc Redo SIGALRM handling. --- diff --git a/src/net.c b/src/net.c index 7513e3e5..b1b7a2f9 100644 --- a/src/net.c +++ b/src/net.c @@ -267,7 +267,6 @@ void handle_meta_connection_data(int fd, short events, void *data) return; if(c->status.connecting) { - c->status.connecting = false; getsockopt(c->socket, SOL_SOCKET, SO_ERROR, &result, &len); if(!result) @@ -276,6 +275,7 @@ void handle_meta_connection_data(int fd, short events, void *data) ifdebug(CONNECTIONS) logger(LOG_DEBUG, _("Error while connecting to %s (%s): %s"), c->name, c->hostname, strerror(result)); + c->status.connecting = false; closesocket(c->socket); do_outgoing_connection(c); return; @@ -381,6 +381,26 @@ static void sighup_handler(int signal, short events, void *data) { try_outgoing_connections(); } +static void sigalrm_handler(int signal, short events, void *data) { + logger(LOG_NOTICE, _("Got %s signal"), strsignal(signal)); + + connection_t *c; + avl_node_t *node; + + for(node = connection_tree->head; node; node = node->next) { + c = node->data; + + if(c->outgoing && !c->node) { + if(timeout_initialized(&c->outgoing->ev)) + event_del(&c->outgoing->ev); + if(c->status.connecting) + close(c->socket); + c->outgoing->timeout = 0; + do_outgoing_connection(c); + } + } +} + /* this is where it all happens... */ @@ -397,6 +417,7 @@ int main_loop(void) struct event sigusr1_event; struct event sigusr2_event; struct event sigwinch_event; + struct event sigalrm_event; cp(); @@ -414,6 +435,8 @@ int main_loop(void) signal_add(&sigusr2_event, NULL); signal_set(&sigwinch_event, SIGWINCH, sigwinch_handler, NULL); signal_add(&sigwinch_event, NULL); + signal_set(&sigalrm_event, SIGALRM, sigalrm_handler, NULL); + signal_add(&sigalrm_event, NULL); last_ping_check = now; @@ -476,12 +499,6 @@ int main_loop(void) keyexpires = now + keylifetime; } } - - if(sigalrm) { - logger(LOG_INFO, _("Flushing event queue")); - // TODO: do this another way - sigalrm = false; - } } signal_del(&sighup_event); @@ -491,6 +508,7 @@ int main_loop(void) signal_del(&sigusr1_event); signal_del(&sigusr2_event); signal_del(&sigwinch_event); + signal_del(&sigalrm_event); return 0; } diff --git a/src/net_socket.c b/src/net_socket.c index 5394d364..bba0d97d 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -234,7 +234,7 @@ int setup_vpn_in_socket(const sockaddr_t *sa) } static void retry_outgoing_handler(int fd, short events, void *data) { - retry_outgoing(data); + do_outgoing_connection(data); } void retry_outgoing(outgoing_t *outgoing) { @@ -262,6 +262,7 @@ void finish_connecting(connection_t *c) configure_tcp(c); c->last_ping_time = now; + c->status.connecting = false; send_id(c); }