commit 5639f2e5d6987e49d6d30b5d880c883fd2a87ee5 Author: George Kadianakis desnacked@gmail.com Date: Sat Jul 9 00:21:50 2011 +0200
We now close all listeners on SIGINT, instead of simply disabling them. --- src/main.c | 42 +++++++++++++++++------------------------- src/network.c | 11 ----------- src/network.h | 1 - 3 files changed, 17 insertions(+), 37 deletions(-)
diff --git a/src/main.c b/src/main.c index 56ea9c9..621a3c9 100644 --- a/src/main.c +++ b/src/main.c @@ -61,21 +61,29 @@ usage(void) }
/** - Disables all active listeners. + Frees all active listeners. */ static void -disable_all_listeners(void) +free_all_listeners(void) { + static int called_already=0; + + if (called_already) + return; if (!ll) return; - log_info("Disabling all listeners.");
- /* Iterate listener doubly linked list and disable them all. */ + log_info("Closing all listeners."); + + /* Iterate listener doubly linked list and free them all. */ dll_node_t *ll_node = ll->head; while (ll_node) { - listener_disable(ll_node->data); - ll_node = ll_node->next; + listener_free(ll_node->data); + dll_remove(ll, ll_node); + ll_node = ll->head; } + + called_already++; }
/** @@ -94,14 +102,10 @@ handle_signal_cb(evutil_socket_t fd, short what, void *arg) { int signum = (int) fd; static int got_sigint=0; - static int disabled_listeners=0;
switch (signum) { case SIGINT: - if (!disabled_listeners) { - disable_all_listeners(); - disabled_listeners++; - } + free_all_listeners(); if (!got_sigint) { log_info("Got SIGINT. Preparing shutdown."); start_shutdown(0); @@ -112,10 +116,6 @@ handle_signal_cb(evutil_socket_t fd, short what, void *arg) } break; case SIGTERM: - if (!disabled_listeners) { - disable_all_listeners(); - disabled_listeners++; - } log_info("Got SIGTERM. Terminating."); start_shutdown(1); break; @@ -431,17 +431,9 @@ main(int argc, const char **argv) if (close_obfsproxy_logfile() < 0) printf("Failed closing logfile!\n");
- /* Free all listeners in our listener dll. */ - if (ll) { - dll_node_t *ll_node = ll->head; - while (ll_node) { - listener_free(ll_node->data); - dll_remove(ll, ll_node); - ll_node = ll->head; - } - /* free dll memory */ + free_all_listeners(); /* free all listeners in our listener dll */ + if (ll) /* free listener dll */ free(ll); - }
free(protocol_options); free(n_options_array); diff --git a/src/network.c b/src/network.c index 1103eeb..b29e9dd 100644 --- a/src/network.c +++ b/src/network.c @@ -144,17 +144,6 @@ listener_new(struct event_base *base, return lsn; }
-/** - Disable listener 'lsn'. -*/ -void -listener_disable(listener_t *lsn) -{ - assert(lsn); - - evconnlistener_disable(lsn->listener); -} - void listener_free(listener_t *lsn) { diff --git a/src/network.h b/src/network.h index a8c02ac..28a0d7d 100644 --- a/src/network.h +++ b/src/network.h @@ -46,7 +46,6 @@ struct addrinfo; listener_t *listener_new(struct event_base *base, struct protocol_params_t *params); void listener_free(listener_t *listener); -void listener_disable(listener_t *lsn);
void start_shutdown(int barbaric);