From e3c17463310b4b3ea2c918259a23fae2844f7466 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 1 Jan 2023 22:40:30 +0200 Subject: [PATCH 41/41] 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 2668ab74cd..fa373a4d96 100644 --- a/client/client_main.c +++ b/client/client_main.c @@ -364,10 +364,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 d0e8e1226e..2814aeca8e 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -224,6 +224,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 */ @@ -3492,8 +3497,6 @@ void server_game_free(void) **************************************************************************/ void fc__noreturn srv_main(void) { - fc_interface_init_server(); - srv_prepare(); /* Run server loop */ diff --git a/tools/civmanual.c b/tools/civmanual.c index e988d011b4..c1cb2e60ac 100644 --- a/tools/civmanual.c +++ b/tools/civmanual.c @@ -777,6 +777,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); @@ -840,10 +847,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 28b6da1619..490601aca1 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 @@ -103,10 +109,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