From efc8c7531d912234558859efb32ca24f8f997941 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 1 Jan 2023 23:19:34 +0200 Subject: [PATCH 15/15] Initialize mutexes of the low level fallback functions earlier Make sure fallback fc_vsnprintf() mutes is initialized before it's needed. See osdn #46418 Signed-off-by: Marko Lindqvist --- client/client_main.c | 7 +++++-- server/srv_main.c | 6 +++++- tools/civmanual.c | 11 +++++++---- tools/ruledit/ruledit.cpp | 10 +++++++--- tools/ruleup.c | 11 +++++++---- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/client/client_main.c b/client/client_main.c index 792b0e34d0..16ef08c325 100644 --- a/client/client_main.c +++ b/client/client_main.c @@ -363,10 +363,13 @@ int client_main(int argc, char *argv[], bool postpone_tileset) # endif /* FREECIV_NDEBUG */ #endif /* FREECIV_MSWINDOWS */ - i_am_client(); /* Tell to libfreeciv that we are client */ - + /* fc_interface_init() includes low level support like + * guaranteeing that fc_vsnprintf() will work after it, + * so this need to be early. */ fc_interface_init_client(); + i_am_client(); /* Tell to libfreeciv that we are client */ + game.client.ruleset_init = FALSE; /* Ensure that all AIs are initialized to unused state diff --git a/server/srv_main.c b/server/srv_main.c index 8e09e39ab0..c8c9dba294 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -220,6 +220,11 @@ void init_game_seed(void) **************************************************************************/ void srv_init(void) { + /* fc_interface_init() includes low level support like + * guaranteeing that fc_vsnprintf() will work after it, + * so this need to be early. */ + fc_interface_init_server(); + i_am_server(); /* Tell to libfreeciv that we are server */ /* NLS init */ @@ -3377,7 +3382,6 @@ void server_game_free(void) **************************************************************************/ void srv_main(void) { - fc_interface_init_server(); advisors_init(); srv_prepare(); diff --git a/tools/civmanual.c b/tools/civmanual.c index a25b3ddd57..3bc44b9386 100644 --- a/tools/civmanual.c +++ b/tools/civmanual.c @@ -689,6 +689,13 @@ int main(int argc, char **argv) char *option = NULL; int retval = EXIT_SUCCESS; + /* Initialize the fc_interface functions needed to generate the help + * text. + * fc_interface_init() includes low level support like + * guaranteeing that fc_vsnprintf() will work after it, + * so this need to be early. */ + fc_interface_init_tool(); + init_nls(); registry_module_init(); init_character_encodings(FC_DEFAULT_DATA_ENCODING, FALSE); @@ -750,10 +757,6 @@ int main(int argc, char **argv) /* Get common code to treat us as a tool. */ i_am_tool(); - /* Initialize the fc_interface functions needed to generate the help - * text. */ - fc_interface_init_tool(); - /* Initialize game with default values */ game_init(FALSE); diff --git a/tools/ruledit/ruledit.cpp b/tools/ruledit/ruledit.cpp index 7732b5ac40..96f44bb0da 100644 --- a/tools/ruledit/ruledit.cpp +++ b/tools/ruledit/ruledit.cpp @@ -76,6 +76,12 @@ int main(int argc, char **argv) # endif /* FREECIV_NDEBUG */ #endif /* FREECIV_MSWINDOWS */ + /* Initialize the fc_interface functions needed to understand rules. + * fc_interface_init() includes low level support like + * guaranteeing that fc_vsnprintf() will work after it, + * so this need to be early. */ + fc_interface_init_tool(); + init_nls(); #ifdef ENABLE_NLS @@ -105,10 +111,8 @@ int main(int argc, char **argv) game.info.aifill = 0; game_init(FALSE); - i_am_tool(); - /* Initialize the fc_interface functions needed to understand rules. */ - fc_interface_init_tool(); + i_am_tool(); if (comments_load()) { ruledit_qt_run(ui_options, argv); diff --git a/tools/ruleup.c b/tools/ruleup.c index 30f05184f4..233ea9e0b3 100644 --- a/tools/ruleup.c +++ b/tools/ruleup.c @@ -148,13 +148,19 @@ int main(int argc, char **argv) # endif /* FREECIV_NDEBUG */ #endif /* FREECIV_MSWINDOWS */ + /* Initialize the fc_interface functions needed to understand rules. + * fc_interface_init() includes low level support like + * guaranteeing that fc_vsnprintf() will work after it, + * so this need to be early. */ + fc_interface_init_tool(); + init_nls(); registry_module_init(); init_character_encodings(FC_DEFAULT_DATA_ENCODING, FALSE); rup_parse_cmdline(argc, argv); - + log_init(NULL, loglevel, NULL, NULL, fatal_assertions); init_connections(); @@ -164,9 +170,6 @@ int main(int argc, char **argv) game_init(FALSE); i_am_tool(); - /* Initialize the fc_interface functions needed to understand rules. */ - fc_interface_init_tool(); - /* Set ruleset user requested to use */ if (rs_selected == NULL) { rs_selected = GAME_DEFAULT_RULESETDIR; -- 2.39.0