From 8810dbeeac206c7afef5df6ba94500c5ab2129f9 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik <sveinung84@users.sourceforge.net> Date: Tue, 23 Mar 2021 01:20:18 +0100 Subject: [PATCH 9/9] ruleup: set exit status based on what happened. Set the exit status to failure if the ruleset couldn't be loaded. Extend the Fatal option to trigger when the comments couldn't load. Thanks to Marko for clarifying that fatal_assertions not catching log_error() isn't a bug. See osdn #41634 --- tools/ruleup.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tools/ruleup.c b/tools/ruleup.c index afd4152629..6343c95bf9 100644 --- a/tools/ruleup.c +++ b/tools/ruleup.c @@ -67,7 +67,7 @@ static void rup_parse_cmdline(int argc, char *argv[]) cmdhelp_add(help, "F", /* TRANS: "Fatal" is exactly what user must type, do not translate. */ _("Fatal [SIGNAL]"), - _("Raise a signal on failed assertion")); + _("Raise a signal on failed assertion or broken data")); #endif /* FREECIV_NDEBUG */ cmdhelp_add(help, "r", /* TRANS: "ruleset" is exactly what user must type, do not translate. */ @@ -141,6 +141,7 @@ static void conv_log(const char *msg) int main(int argc, char **argv) { enum log_level loglevel = LOG_NORMAL; + int exit_status = EXIT_SUCCESS; /* Load win32 post-crash debugger */ #ifdef FREECIV_MSWINDOWS @@ -197,6 +198,12 @@ int main(int argc, char **argv) /* TRANS: 'Failed to load comments-x.y.txt' where x.y is * freeciv version */ log_error(R__("Failed to load %s."), COMMENTS_FILE_NAME); + + /* Reuse fatal_assertions for failed comment loading. */ + if (0 <= fatal_assertions) { + /* Emit a signal. */ + raise(fatal_assertions); + } } /* Clean up unused entities added during the ruleset upgrade. */ @@ -220,6 +227,9 @@ int main(int argc, char **argv) comments_free(); } else { log_error(_("Can't load ruleset %s"), rs_selected); + + /* Failed to upgrade the ruleset */ + exit_status = EXIT_FAILURE; } registry_module_close(); @@ -228,5 +238,5 @@ int main(int argc, char **argv) free_nls(); cmdline_option_values_free(); - return EXIT_SUCCESS; + return exit_status; } -- 2.20.1