diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-01-14 10:03:03 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-01-14 10:03:03 +0100 |
commit | 133cee578e04e561bb17e37393bbf7e427522560 (patch) | |
tree | 4f08d1f1405e997e1d40674c1e78d4c9403f7457 | |
parent | 51a1da3272c58e631fc5cecb181327bcceb5f311 (diff) | |
download | fastd-133cee578e04e561bb17e37393bbf7e427522560.tar fastd-133cee578e04e561bb17e37393bbf7e427522560.zip |
Reset all connections on SIGUSR2
-rw-r--r-- | src/fastd.c | 39 | ||||
-rw-r--r-- | src/peer.c | 16 | ||||
-rw-r--r-- | src/peer.h | 1 |
3 files changed, 43 insertions, 13 deletions
diff --git a/src/fastd.c b/src/fastd.c index 1bb4caa..43dacc7 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -64,26 +64,31 @@ fastd_context_t ctx = {}; -static volatile bool sighup = false; /**< Is set to true when a SIGHUP is received */ -static volatile bool terminate = false; /**< Is set to true when a SIGTERM, SIGQUIT or SIGINT is received */ -static volatile bool sigchld = false; /**< Is set to true when a SIGCHLD is received */ +static volatile bool sig_reload = false; /**< Is set to true when a SIGHUP is received */ +static volatile bool sig_reset = false; /**< Is set to true when a SIGUSR2 is received */ +static volatile bool sig_terminate = false; /**< Is set to true when a SIGTERM, SIGQUIT or SIGINT is received */ +static volatile bool sig_child = false; /**< Is set to true when a SIGCHLD is received */ /** Signal handler; just saves the signals to be handled later */ static void on_signal(int signo) { switch(signo) { case SIGHUP: - sighup = true; + sig_reload = true; + break; + + case SIGUSR2: + sig_reset = true; break; case SIGCHLD: - sigchld = true; + sig_child = true; break; case SIGTERM: case SIGQUIT: case SIGINT: - terminate = true; + sig_terminate = true; break; default: @@ -109,6 +114,8 @@ static void init_signals(void) { action.sa_handler = on_signal; if (sigaction(SIGHUP, &action, NULL)) exit_errno("sigaction"); + if (sigaction(SIGUSR2, &action, NULL)) + exit_errno("sigaction"); if (sigaction(SIGCHLD, &action, NULL)) exit_errno("sigaction"); if (sigaction(SIGTERM, &action, NULL)) @@ -127,8 +134,6 @@ static void init_signals(void) { exit_errno("sigaction"); if (sigaction(SIGUSR1, &action, NULL)) exit_errno("sigaction"); - if (sigaction(SIGUSR2, &action, NULL)) - exit_errno("sigaction"); } @@ -563,16 +568,24 @@ static inline void reap_zombies(void) { /** The \em real signal handlers */ static inline void handle_signals(void) { - if (sighup) { - sighup = false; + if (sig_reload) { + sig_reload = false; pr_info("reconfigure triggered"); fastd_config_load_peer_dirs(); } - if (sigchld) { - sigchld = false; + if (sig_reset) { + sig_reset = false; + + pr_info("triggered reset of all connections"); + + fastd_peer_reset_all(); + } + + if (sig_child) { + sig_child = false; reap_zombies(); } } @@ -640,7 +653,7 @@ static inline void cleanup(void) { int main(int argc, char *argv[]) { init(argc, argv); - while (!terminate) + while (!sig_terminate) run(); cleanup(); @@ -970,3 +970,19 @@ void fastd_peer_maintenance(void) { eth_addr_cleanup(); } + +/** Resets all peers */ +void fastd_peer_reset_all(void) { + size_t i; + for (i = 0; i < VECTOR_LEN(ctx.peers);) { + fastd_peer_t *peer = VECTOR_INDEX(ctx.peers, i); + + if (fastd_peer_is_dynamic(peer)) { + fastd_peer_delete(peer); + } + else { + fastd_peer_reset(peer); + i++; + } + } +} @@ -290,6 +290,7 @@ bool fastd_peer_find_by_eth_addr(const fastd_eth_addr_t addr, fastd_peer_t **pee void fastd_peer_handle_handshake_queue(void); void fastd_peer_maintenance(void); +void fastd_peer_reset_all(void); /** Adds statistics for a single packet of a given size */ static inline void fastd_stats_add(UNUSED fastd_peer_t *peer, UNUSED fastd_stat_type_t stat, UNUSED size_t bytes) { |