From 54e73a376ee09b96977fc03237ce497fd573048f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 30 Sep 2023 00:16:46 +0300 Subject: [PATCH 50/50] Free signal_timer See osdn #44899 Signed-off-by: Marko Lindqvist --- server/srv_main.c | 2 ++ server/srv_signal.c | 25 ++++++++++++++++++------- server/srv_signal.h | 1 + 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/server/srv_main.c b/server/srv_main.c index 9975f769ef..10a311a763 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -115,6 +115,7 @@ #include "settings.h" #include "spacerace.h" #include "srv_log.h" +#include "srv_signal.h" #include "stdinhand.h" #include "techtools.h" #include "unithand.h" @@ -1930,6 +1931,7 @@ void fc__noreturn server_quit(void) con_log_close(); cmdline_option_values_free(); readline_atexit(); + signal_timer_free(); exit(EXIT_SUCCESS); } diff --git a/server/srv_signal.c b/server/srv_signal.c index d41a8c680b..9328d68654 100644 --- a/server/srv_signal.c +++ b/server/srv_signal.c @@ -50,31 +50,31 @@ if (S_S_RUNNING == server_state()) { \ } \ exit(EXIT_SUCCESS); +static struct timer *signal_timer = NULL; + /**********************************************************************//** This function is called when a SIGINT (ctrl-c) is received. It will exit only if two SIGINTs are received within a second. **************************************************************************/ static void signal_handler(int sig) { - static struct timer *timer = NULL; - switch (sig) { case SIGINT: - if (timer && timer_read_seconds(timer) <= 1.0) { + if (signal_timer != NULL && timer_read_seconds(signal_timer) <= 1.0) { save_and_exit(SIGINT); } else { if (game.info.timeout == -1) { log_normal(_("Setting timeout to 0. Autogame will stop.")); game.info.timeout = 0; } - if (!timer) { + if (signal_timer == NULL) { log_normal(_("You must interrupt Freeciv twice " "within one second to make it exit.")); } } - timer = timer_renew(timer, TIMER_USER, TIMER_ACTIVE, - timer != NULL ? NULL : "ctrlc"); - timer_start(timer); + signal_timer = timer_renew(signal_timer, TIMER_USER, TIMER_ACTIVE, + signal_timer != NULL ? NULL : "ctrlc"); + timer_start(signal_timer); break; #ifdef SIGHUP @@ -142,3 +142,14 @@ void setup_interrupt_handlers(void) #endif /* SIGPIPE */ #endif /* USE_INTERRUPT_HANDLERS */ } + +/**********************************************************************//** + Free signal timer +**************************************************************************/ +void signal_timer_free(void) +{ + if (signal_timer != NULL) { + timer_destroy(signal_timer); + signal_timer = NULL; + } +} diff --git a/server/srv_signal.h b/server/srv_signal.h index 428063f971..1386f18fa9 100644 --- a/server/srv_signal.h +++ b/server/srv_signal.h @@ -14,5 +14,6 @@ #define FC__SRV_SIGNAL_H void setup_interrupt_handlers(void); +void signal_timer_free(void); #endif /* FC__SRV_SIGNAL_H */ -- 2.40.1