From 824356cc946d7df4ecd43eeefbd7f1ebf0f5de73 Mon Sep 17 00:00:00 2001 From: Chris Rienzo Date: Fri, 22 Mar 2019 16:59:26 +0000 Subject: [PATCH] FS-11725 [core,test] Fix switch_core to allow MINIMAL core to load without freeswitch.xml. Fix test framework to exit if FreeSWITCH core fails to load. --- src/include/test/switch_test.h | 26 ++++++++++++++++++-------- src/switch_core.c | 7 +++++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/include/test/switch_test.h b/src/include/test/switch_test.h index 18656b3e29..31b6ce9183 100644 --- a/src/include/test/switch_test.h +++ b/src/include/test/switch_test.h @@ -66,7 +66,7 @@ static char *fst_getenv_default(const char *env, char *default_value, switch_boo /** * initialize FS core from optional configuration dir */ -static void fst_init_core_and_modload(const char *confdir, const char *basedir, int minimal) +static switch_status_t fst_init_core_and_modload(const char *confdir, const char *basedir, int minimal) { const char *err; // Let FreeSWITCH core pick these @@ -112,12 +112,12 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir, switch_core_set_globals(); if (!minimal) { - switch_core_init_and_modload(0, SWITCH_TRUE, &err); + switch_status_t status = switch_core_init_and_modload(0, SWITCH_TRUE, &err); switch_sleep(1 * 1000000); switch_core_set_variable("sound_prefix", "." SWITCH_PATH_SEPARATOR); - } else { - switch_core_init(SCF_MINIMAL, SWITCH_TRUE, &err); + return status; } + return switch_core_init(SCF_MINIMAL, SWITCH_TRUE, &err); } /** @@ -248,12 +248,17 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir, #define FST_CORE_BEGIN(confdir) \ FCT_BGN() \ { \ - int fst_core = 2; \ + int fst_core = 0; \ switch_time_t fst_time_start = 0; \ switch_timer_t fst_timer = { 0 }; \ switch_memory_pool_t *fst_pool = NULL; \ fst_getenv_default("FST_SUPPRESS_UNUSED_STATIC_WARNING", NULL, SWITCH_FALSE); \ - fst_init_core_and_modload(confdir, NULL, 0); \ + if (fst_init_core_and_modload(confdir, NULL, 0) == SWITCH_STATUS_SUCCESS) { \ + fst_core = 2; \ + } else { \ + fprintf(stderr, "Failed to load FS core\n"); \ + exit(1); \ + } \ { @@ -276,12 +281,17 @@ static void fst_init_core_and_modload(const char *confdir, const char *basedir, #define FST_MINCORE_BEGIN() \ FCT_BGN() \ { \ - int fst_core = 1; \ + int fst_core = 0; \ switch_time_t fst_time_start = 0; \ switch_timer_t fst_timer = { 0 }; \ switch_memory_pool_t *fst_pool = NULL; \ fst_getenv_default("FST_SUPPRESS_UNUSED_STATIC_WARNING", NULL, SWITCH_FALSE); \ - fst_init_core_and_modload(".", NULL, 1); /* minimal load */ \ + if (fst_init_core_and_modload(".", NULL, 1) == SWITCH_STATUS_SUCCESS) { /* minimal load */ \ + fst_core = 1; \ + } else { \ + fprintf(stderr, "Failed to load FS core\n"); \ + exit(1); \ + } \ { #define FST_MINCORE_END FST_CORE_END diff --git a/src/switch_core.c b/src/switch_core.c index 0fb040fbbd..b4128cc19a 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -1992,8 +1992,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc switch_channel_global_init(runtime.memory_pool); if (switch_xml_init(runtime.memory_pool, err) != SWITCH_STATUS_SUCCESS) { - apr_terminate(); - return SWITCH_STATUS_MEMERR; + /* allow missing configuration if MINIMAL */ + if (!(flags & SCF_MINIMAL)) { + apr_terminate(); + return SWITCH_STATUS_MEMERR; + } } if (switch_test_flag((&runtime), SCF_USE_AUTO_NAT)) {