From 9daccab8badf7a6d820b498735686ef3150bba88 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 21 Jan 2024 00:36:39 +0100 Subject: [PATCH] shutdown_handler: really shutdown when we are last If we are a master and we don't have peers, there is no use keeping the sessions alive, when we'll restart we will have forgotten them all. Better gracefully close them, so they can be quickly respawn on restart, instead of having to wait for timeouts. --- cluster.c | 8 ++++++++ cluster.h | 1 + l2tpns.c | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cluster.c b/cluster.c index e31e234..2ebe4b3 100644 --- a/cluster.c +++ b/cluster.c @@ -754,6 +754,14 @@ void cluster_check_master(void) // should also update. } +// +// Returns whether we have peers. +// +int cluster_have_peers(void) +{ + return num_peers > 0; +} + // // Check that our session table is validly matching what the diff --git a/cluster.h b/cluster.h index 57bae9e..2bbe991 100644 --- a/cluster.h +++ b/cluster.h @@ -92,6 +92,7 @@ void cluster_send_ping(time_t basetime); void cluster_heartbeat(void); void cluster_check_master(void); void cluster_check_slaves(void); +int cluster_have_peers(void); int cmd_show_cluster(struct cli_def *cli, const char *command, char **argv, int argc); int master_forward_pppoe_packet(uint8_t *data, int size, uint8_t codepad); diff --git a/l2tpns.c b/l2tpns.c index 382a349..ce8454e 100644 --- a/l2tpns.c +++ b/l2tpns.c @@ -5337,7 +5337,7 @@ static void sighup_handler(int sig) static void shutdown_handler(int sig) { - main_quit = (sig == SIGQUIT) ? QUIT_SHUTDOWN : QUIT_FAILOVER; + main_quit = (sig == SIGQUIT || (config->cluster_iam_master && !cluster_have_peers())) ? QUIT_SHUTDOWN : QUIT_FAILOVER; } static void sigchild_handler(int sig)