<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/8500">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">core: Remove non-critical cleanup from startup aborts.<br><br>When built-in components of Asterisk fail to start they cause the<br>Asterisk startup to abort. In these cases only the most critical<br>cleanup should be performed - closing databases and terminating<br>proceses. These cleanups are registered using ast_register_atexit, all<br>other cleanups should not be run during startup abort.<br><br>The main reason for this change is that these cleanup procedures are<br>untestable from the partially initialized states, if they fail it could<br>prevent us from ever running the critical cleanup with ast_run_atexits.<br><br>Create separate initialization for dns_core.c to be run unconditionally<br>during startup instead of being initialized by the first dns resolver to<br>be registered. This ensures that 'sched' is initialized before it can be<br>potentially used.<br><br>Replace ast_register_atexit with ast_register_cleanup in media_cache.c.<br>There is no reason for this cleanup to happen unconditionally.<br><br>Change-Id: Iecc2df98008b21509925ff16740bd5fa29527db3<br>---<br>M include/asterisk/_private.h<br>M main/asterisk.c<br>M main/cel.c<br>M main/core_local.c<br>M main/devicestate.c<br>M main/dns_core.c<br>M main/dns_system_resolver.c<br>M main/dsp.c<br>M main/features.c<br>M main/features_config.c<br>M main/indications.c<br>M main/media_cache.c<br>M main/pbx_builtins.c<br>M main/sorcery.c<br>14 files changed, 31 insertions(+), 70 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/00/8500/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/include/asterisk/_private.h b/include/asterisk/_private.h<br>index e989b16..b9f552d 100644<br>--- a/include/asterisk/_private.h<br>+++ b/include/asterisk/_private.h<br>@@ -59,6 +59,7 @@<br> int ast_msg_init(void); /*!< Provided by message.c */<br> void ast_msg_shutdown(void); /*!< Provided by message.c */<br> int aco_init(void); /*!< Provided by config_options.c */<br>+int dns_core_init(void); /*!< Provided by dns_core.c */<br> <br> /*!<br> * \brief Initialize the bridging system.<br>diff --git a/main/asterisk.c b/main/asterisk.c<br>index e348b21..bec992f 100644<br>--- a/main/asterisk.c<br>+++ b/main/asterisk.c<br>@@ -4548,6 +4548,7 @@<br> check_init(ast_parking_stasis_init(), "Parking Core");<br> check_init(ast_device_state_engine_init(), "Device State Engine");<br> check_init(ast_presence_state_engine_init(), "Presence State Engine");<br>+ check_init(dns_core_init(), "DNS Resolver Core");<br> check_init(ast_dns_system_resolver_init(), "Default DNS resolver");<br> check_init(ast_security_stasis_init(), "Security Stasis Topic and Events");<br> check_init(ast_image_init(), "Image");<br>diff --git a/main/cel.c b/main/cel.c<br>index e4fae6d..2813e60 100644<br>--- a/main/cel.c<br>+++ b/main/cel.c<br>@@ -1563,7 +1563,6 @@<br> ao2_global_obj_replace_unref(cel_linkedids, container);<br> ao2_cleanup(container);<br> if (!container) {<br>- cel_engine_cleanup();<br> return -1;<br> }<br> <br>@@ -1572,17 +1571,14 @@<br> ao2_global_obj_replace_unref(cel_dialstatus_store, container);<br> ao2_cleanup(container);<br> if (!container) {<br>- cel_engine_cleanup();<br> return -1;<br> }<br> <br> if (STASIS_MESSAGE_TYPE_INIT(cel_generic_type)) {<br>- cel_engine_cleanup();<br> return -1;<br> }<br> <br> if (ast_cli_register(&cli_status)) {<br>- cel_engine_cleanup();<br> return -1;<br> }<br> <br>@@ -1590,12 +1586,10 @@<br> ao2_global_obj_replace_unref(cel_backends, container);<br> ao2_cleanup(container);<br> if (!container) {<br>- cel_engine_cleanup();<br> return -1;<br> }<br> <br> if (aco_info_init(&cel_cfg_info)) {<br>- cel_engine_cleanup();<br> return -1;<br> }<br> <br>@@ -1608,7 +1602,6 @@<br> struct cel_config *cel_cfg = cel_config_alloc();<br> <br> if (!cel_cfg) {<br>- cel_engine_cleanup();<br> return -1;<br> }<br> <br>@@ -1621,12 +1614,10 @@<br> }<br> <br> if (create_subscriptions()) {<br>- cel_engine_cleanup();<br> return -1;<br> }<br> <br> if (ast_cel_check_enabled() && create_routes()) {<br>- cel_engine_cleanup();<br> return -1;<br> }<br> <br>diff --git a/main/core_local.c b/main/core_local.c<br>index 23c7cce..c3fa15f 100644<br>--- a/main/core_local.c<br>+++ b/main/core_local.c<br>@@ -1049,7 +1049,6 @@<br> <br> int ast_local_init(void)<br> {<br>-<br> if (STASIS_MESSAGE_TYPE_INIT(ast_local_optimization_begin_type)) {<br> return -1;<br> }<br>@@ -1069,17 +1068,13 @@<br> <br> locals = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, locals_cmp_cb);<br> if (!locals) {<br>- ao2_cleanup(local_tech.capabilities);<br>- local_tech.capabilities = NULL;<br> return -1;<br> }<br> <br> /* Make sure we can register our channel type */<br> if (ast_channel_register(&local_tech)) {<br> ast_log(LOG_ERROR, "Unable to register channel class 'Local'\n");<br>- ao2_ref(locals, -1);<br>- ao2_cleanup(local_tech.capabilities);<br>- local_tech.capabilities = NULL;<br>+<br> return -1;<br> }<br> ast_cli_register_multiple(cli_local, ARRAY_LEN(cli_local));<br>diff --git a/main/devicestate.c b/main/devicestate.c<br>index 1db9a19..5df3449 100644<br>--- a/main/devicestate.c<br>+++ b/main/devicestate.c<br>@@ -911,24 +911,20 @@<br> }<br> device_state_topic_all = stasis_topic_create("ast_device_state_topic");<br> if (!device_state_topic_all) {<br>- devstate_cleanup();<br> return -1;<br> }<br> device_state_topic_pool = stasis_topic_pool_create(ast_device_state_topic_all());<br> if (!device_state_topic_pool) {<br>- devstate_cleanup();<br> return -1;<br> }<br> device_state_cache = stasis_cache_create_full(device_state_get_id,<br> device_state_aggregate_calc, device_state_aggregate_publish);<br> if (!device_state_cache) {<br>- devstate_cleanup();<br> return -1;<br> }<br> device_state_topic_cached = stasis_caching_topic_create(ast_device_state_topic_all(),<br> device_state_cache);<br> if (!device_state_topic_cached) {<br>- devstate_cleanup();<br> return -1;<br> }<br> <br>@@ -936,7 +932,6 @@<br> devstate_change_cb, NULL);<br> if (!devstate_message_sub) {<br> ast_log(LOG_ERROR, "Failed to create subscription creating uncached device state aggregate events.\n");<br>- devstate_cleanup();<br> return -1;<br> }<br> <br>diff --git a/main/dns_core.c b/main/dns_core.c<br>index 3e270af..13ddc99 100644<br>--- a/main/dns_core.c<br>+++ b/main/dns_core.c<br>@@ -29,6 +29,7 @@<br> <br> #include "asterisk.h"<br> <br>+#include "asterisk/_private.h"<br> #include "asterisk/linkedlists.h"<br> #include "asterisk/astobj2.h"<br> #include "asterisk/strings.h"<br>@@ -537,6 +538,20 @@<br> }<br> }<br> <br>+int dns_core_init(void)<br>+{<br>+ sched = ast_sched_context_create();<br>+ if (!sched) {<br>+ return -1;<br>+ }<br>+<br>+ if (ast_sched_start_thread(sched)) {<br>+ return -1;<br>+ }<br>+<br>+ ast_register_cleanup(dns_shutdown);<br>+}<br>+<br> int ast_dns_resolver_register(struct ast_dns_resolver *resolver)<br> {<br> struct ast_dns_resolver *iter;<br>@@ -558,27 +573,6 @@<br> }<br> <br> AST_RWLIST_WRLOCK(&resolvers);<br>-<br>- /* On the first registration of a resolver start a scheduler for recurring queries */<br>- if (AST_LIST_EMPTY(&resolvers) && !sched) {<br>- sched = ast_sched_context_create();<br>- if (!sched) {<br>- ast_log(LOG_ERROR, "DNS resolver '%s' could not be registered: Failed to create scheduler for recurring DNS queries\n",<br>- resolver->name);<br>- AST_RWLIST_UNLOCK(&resolvers);<br>- return -1;<br>- }<br>-<br>- if (ast_sched_start_thread(sched)) {<br>- ast_log(LOG_ERROR, "DNS resolver '%s' could not be registered: Failed to start thread for recurring DNS queries\n",<br>- resolver->name);<br>- dns_shutdown();<br>- AST_RWLIST_UNLOCK(&resolvers);<br>- return -1;<br>- }<br>-<br>- ast_register_cleanup(dns_shutdown);<br>- }<br> <br> AST_LIST_TRAVERSE(&resolvers, iter, next) {<br> if (!strcmp(iter->name, resolver->name)) {<br>diff --git a/main/dns_system_resolver.c b/main/dns_system_resolver.c<br>index 9358577..8cb92c0 100644<br>--- a/main/dns_system_resolver.c<br>+++ b/main/dns_system_resolver.c<br>@@ -255,7 +255,6 @@<br> <br> /* Return error if the task processor failed to instantiate */<br> if (!dns_system_resolver_tp) {<br>- dns_system_resolver_destroy();<br> return DNS_SYSTEM_RESOLVER_FAILURE;<br> }<br> <br>diff --git a/main/dsp.c b/main/dsp.c<br>index 8b39fe5..66d95ad 100644<br>--- a/main/dsp.c<br>+++ b/main/dsp.c<br>@@ -2402,17 +2402,18 @@<br> <br> int ast_dsp_init(void)<br> {<br>- int res = _dsp_init(0);<br>+ if (_dsp_init(0)) {<br>+ return -1;<br>+ }<br> <br> #ifdef TEST_FRAMEWORK<br>- if (!res) {<br>- AST_TEST_REGISTER(test_dsp_fax_detect);<br>- AST_TEST_REGISTER(test_dsp_dtmf_detect);<br>+ AST_TEST_REGISTER(test_dsp_fax_detect);<br>+ AST_TEST_REGISTER(test_dsp_dtmf_detect);<br> <br>- ast_register_cleanup(test_dsp_shutdown);<br>- }<br>+ ast_register_cleanup(test_dsp_shutdown);<br> #endif<br>- return res;<br>+<br>+ return 0;<br> }<br> <br> int ast_dsp_reload(void)<br>diff --git a/main/features.c b/main/features.c<br>index 516c64a..35039e0 100644<br>--- a/main/features.c<br>+++ b/main/features.c<br>@@ -1164,17 +1164,10 @@<br> int res;<br> <br> res = ast_features_config_init();<br>- if (res) {<br>- return res;<br>- }<br> res |= ast_register_application2(app_bridge, bridge_exec, NULL, NULL, NULL);<br> res |= ast_manager_register_xml_core("Bridge", EVENT_FLAG_CALL, action_bridge);<br> <br>- if (res) {<br>- features_shutdown();<br>- } else {<br>- ast_register_cleanup(features_shutdown);<br>- }<br>+ ast_register_cleanup(features_shutdown);<br> <br> return res;<br> }<br>diff --git a/main/features_config.c b/main/features_config.c<br>index a773f49..195fbac 100644<br>--- a/main/features_config.c<br>+++ b/main/features_config.c<br>@@ -2000,9 +2000,5 @@<br> res |= __ast_custom_function_register(&featuremap_function, NULL);<br> res |= ast_cli_register_multiple(cli_features_config, ARRAY_LEN(cli_features_config));<br> <br>- if (res) {<br>- ast_features_config_shutdown();<br>- }<br>-<br> return res;<br> }<br>diff --git a/main/indications.c b/main/indications.c<br>index bde6e01..8971058 100644<br>--- a/main/indications.c<br>+++ b/main/indications.c<br>@@ -1130,13 +1130,13 @@<br> /*! \brief Load indications module */<br> int ast_indications_init(void)<br> {<br>- if (!(ast_tone_zones = ao2_container_alloc(NUM_TONE_ZONE_BUCKETS,<br>- ast_tone_zone_hash, ast_tone_zone_cmp))) {<br>+ ast_tone_zones = ao2_container_alloc(NUM_TONE_ZONE_BUCKETS,<br>+ ast_tone_zone_hash, ast_tone_zone_cmp);<br>+ if (!ast_tone_zones) {<br> return -1;<br> }<br> <br> if (load_indications(0)) {<br>- indications_shutdown();<br> return -1;<br> }<br> <br>diff --git a/main/media_cache.c b/main/media_cache.c<br>index 90057dc..9313054 100644<br>--- a/main/media_cache.c<br>+++ b/main/media_cache.c<br>@@ -653,7 +653,7 @@<br> <br> int ast_media_cache_init(void)<br> {<br>- ast_register_atexit(media_cache_shutdown);<br>+ ast_register_cleanup(media_cache_shutdown);<br> <br> media_cache = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_MUTEX, AO2_BUCKETS,<br> ast_sorcery_object_id_hash, ast_sorcery_object_id_compare);<br>@@ -662,7 +662,6 @@<br> }<br> <br> if (ast_cli_register_multiple(cli_media_cache, ARRAY_LEN(cli_media_cache))) {<br>- ao2_ref(media_cache, -1);<br> return -1;<br> }<br> <br>diff --git a/main/pbx_builtins.c b/main/pbx_builtins.c<br>index 9d43c10..7f76b97 100644<br>--- a/main/pbx_builtins.c<br>+++ b/main/pbx_builtins.c<br>@@ -1509,7 +1509,6 @@<br> for (x = 0; x < ARRAY_LEN(builtins); x++) {<br> if (ast_register_application2(builtins[x].name, builtins[x].execute, NULL, NULL, NULL)) {<br> ast_log(LOG_ERROR, "Unable to register builtin application '%s'\n", builtins[x].name);<br>- unload_pbx_builtins();<br> return -1;<br> }<br> }<br>diff --git a/main/sorcery.c b/main/sorcery.c<br>index c79675c..9028707 100644<br>--- a/main/sorcery.c<br>+++ b/main/sorcery.c<br>@@ -388,20 +388,17 @@<br> wizards = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, WIZARD_BUCKETS,<br> ast_sorcery_internal_wizard_hash_fn, NULL, ast_sorcery_internal_wizard_cmp_fn);<br> if (!wizards) {<br>- sorcery_cleanup();<br> return -1;<br> }<br> <br> observers = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, NULL, NULL);<br> if (!observers) {<br>- sorcery_cleanup();<br> return -1;<br> }<br> <br> instances = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, INSTANCE_BUCKETS,<br> sorcery_proxy_hash_fn, NULL, sorcery_proxy_cmp_fn);<br> if (!instances) {<br>- sorcery_cleanup();<br> return -1;<br> }<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8500">change 8500</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/8500"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Iecc2df98008b21509925ff16740bd5fa29527db3 </div>
<div style="display:none"> Gerrit-Change-Number: 8500 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>