From be406efa25f7b8ca13a7fd43aee810c6124237a6 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 1 Jan 2023 23:12:17 +0200 Subject: [PATCH 29/29] 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 | 7 +++++-- tools/civmanual.c | 11 +++++++---- tools/ruledit/ruledit.cpp | 10 +++++++--- tools/ruleup.c | 11 +++++++---- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/client/client_main.c b/client/client_main.c index b1cd561d52..d4bdc95fcc 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 86c196753a..a41ca6aed4 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -223,6 +223,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 */ @@ -3429,8 +3434,6 @@ void server_game_free(void) **************************************************************************/ void srv_main(void) { - fc_interface_init_server(); - srv_prepare(); /* Run server loop */ diff --git a/tools/civmanual.c b/tools/civmanual.c index 5c3545108d..f08449fbd6 100644 --- a/tools/civmanual.c +++ b/tools/civmanual.c @@ -775,6 +775,13 @@ int main(int argc, char **argv) int retval = EXIT_SUCCESS; struct tag_types *tag_info = &html_tags; + /* 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); @@ -838,10 +845,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 f29e64ba7d..fbc3b95ac0 100644 --- a/tools/ruledit/ruledit.cpp +++ b/tools/ruledit/ruledit.cpp @@ -77,6 +77,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 @@ -106,10 +112,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 852f9f66d1..fda350bfc4 100644 --- a/tools/ruleup.c +++ b/tools/ruleup.c @@ -154,13 +154,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(); @@ -170,9 +176,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