]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
core: Remove non-critical cleanup from startup aborts.
authorCorey Farrell <git@cfware.com>
Sat, 10 Mar 2018 09:33:33 +0000 (04:33 -0500)
committerCorey Farrell <git@cfware.com>
Sat, 10 Mar 2018 09:33:33 +0000 (04:33 -0500)
When built-in components of Asterisk fail to start they cause the
Asterisk startup to abort.  In these cases only the most critical
cleanup should be performed - closing databases and terminating
proceses.  These cleanups are registered using ast_register_atexit, all
other cleanups should not be run during startup abort.

The main reason for this change is that these cleanup procedures are
untestable from the partially initialized states, if they fail it could
prevent us from ever running the critical cleanup with ast_run_atexits.

Change-Id: Iecc2df98008b21509925ff16740bd5fa29527db3

main/cel.c
main/core_local.c
main/devicestate.c
main/dsp.c
main/features.c
main/features_config.c
main/indications.c
main/pbx_builtins.c
main/sorcery.c

index 31cd04542a5aa127f73a6a5fec33b1007d901854..45726e07026fc164122c6cd3f6a94fadbee1c21a 100644 (file)
@@ -1565,7 +1565,6 @@ int ast_cel_engine_init(void)
        ao2_global_obj_replace_unref(cel_linkedids, container);
        ao2_cleanup(container);
        if (!container) {
-               cel_engine_cleanup();
                return -1;
        }
 
@@ -1574,17 +1573,14 @@ int ast_cel_engine_init(void)
        ao2_global_obj_replace_unref(cel_dialstatus_store, container);
        ao2_cleanup(container);
        if (!container) {
-               cel_engine_cleanup();
                return -1;
        }
 
        if (STASIS_MESSAGE_TYPE_INIT(cel_generic_type)) {
-               cel_engine_cleanup();
                return -1;
        }
 
        if (ast_cli_register(&cli_status)) {
-               cel_engine_cleanup();
                return -1;
        }
 
@@ -1592,12 +1588,10 @@ int ast_cel_engine_init(void)
        ao2_global_obj_replace_unref(cel_backends, container);
        ao2_cleanup(container);
        if (!container) {
-               cel_engine_cleanup();
                return -1;
        }
 
        if (aco_info_init(&cel_cfg_info)) {
-               cel_engine_cleanup();
                return -1;
        }
 
@@ -1610,7 +1604,6 @@ int ast_cel_engine_init(void)
                struct cel_config *cel_cfg = cel_config_alloc();
 
                if (!cel_cfg) {
-                       cel_engine_cleanup();
                        return -1;
                }
 
@@ -1623,12 +1616,10 @@ int ast_cel_engine_init(void)
        }
 
        if (create_subscriptions()) {
-               cel_engine_cleanup();
                return -1;
        }
 
        if (ast_cel_check_enabled() && create_routes()) {
-               cel_engine_cleanup();
                return -1;
        }
 
index a5918f525ca0f111b2648569300053aad463ddb3..12e41f99ef0f3ac57f55ad6a93effdb5739e46e6 100644 (file)
@@ -1074,7 +1074,6 @@ static void local_shutdown(void)
 
 int ast_local_init(void)
 {
-
        if (STASIS_MESSAGE_TYPE_INIT(ast_local_optimization_begin_type)) {
                return -1;
        }
@@ -1094,17 +1093,13 @@ int ast_local_init(void)
 
        locals = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, locals_cmp_cb);
        if (!locals) {
-               ao2_cleanup(local_tech.capabilities);
-               local_tech.capabilities = NULL;
                return -1;
        }
 
        /* Make sure we can register our channel type */
        if (ast_channel_register(&local_tech)) {
                ast_log(LOG_ERROR, "Unable to register channel class 'Local'\n");
-               ao2_ref(locals, -1);
-               ao2_cleanup(local_tech.capabilities);
-               local_tech.capabilities = NULL;
+
                return -1;
        }
        ast_cli_register_multiple(cli_local, ARRAY_LEN(cli_local));
index faba144aa482346cdc4231cdb788c7346527cb18..4bc0bed3997e73786c6156f65878166cb42105d8 100644 (file)
@@ -913,24 +913,20 @@ int devstate_init(void)
        }
        device_state_topic_all = stasis_topic_create("ast_device_state_topic");
        if (!device_state_topic_all) {
-               devstate_cleanup();
                return -1;
        }
        device_state_topic_pool = stasis_topic_pool_create(ast_device_state_topic_all());
        if (!device_state_topic_pool) {
-               devstate_cleanup();
                return -1;
        }
        device_state_cache = stasis_cache_create_full(device_state_get_id,
                device_state_aggregate_calc, device_state_aggregate_publish);
        if (!device_state_cache) {
-               devstate_cleanup();
                return -1;
        }
        device_state_topic_cached = stasis_caching_topic_create(ast_device_state_topic_all(),
                device_state_cache);
        if (!device_state_topic_cached) {
-               devstate_cleanup();
                return -1;
        }
 
@@ -938,7 +934,6 @@ int devstate_init(void)
                devstate_change_cb, NULL);
        if (!devstate_message_sub) {
                ast_log(LOG_ERROR, "Failed to create subscription creating uncached device state aggregate events.\n");
-               devstate_cleanup();
                return -1;
        }
 
index 0609256d47ed0a39e0bac7ba6dc2d023b9b1c107..e3e192438308664482640a70bf79a48460ab4d86 100644 (file)
@@ -2404,17 +2404,18 @@ static void test_dsp_shutdown(void)
 
 int ast_dsp_init(void)
 {
-       int res = _dsp_init(0);
+       if (_dsp_init(0)) {
+               return -1;
+       }
 
 #ifdef TEST_FRAMEWORK
-       if (!res) {
-               AST_TEST_REGISTER(test_dsp_fax_detect);
-               AST_TEST_REGISTER(test_dsp_dtmf_detect);
+       AST_TEST_REGISTER(test_dsp_fax_detect);
+       AST_TEST_REGISTER(test_dsp_dtmf_detect);
 
-               ast_register_cleanup(test_dsp_shutdown);
-       }
+       ast_register_cleanup(test_dsp_shutdown);
 #endif
-       return res;
+
+       return 0;
 }
 
 int ast_dsp_reload(void)
index 2ca56bcd32907c9010e12b241370e9d1c94710a6..21e6c22b52dea22a5557b6db8b1a9c6782c902a1 100644 (file)
@@ -1167,17 +1167,10 @@ int ast_features_init(void)
        int res;
 
        res = ast_features_config_init();
-       if (res) {
-               return res;
-       }
        res |= ast_register_application2(app_bridge, bridge_exec, NULL, NULL, NULL);
        res |= ast_manager_register_xml_core("Bridge", EVENT_FLAG_CALL, action_bridge);
 
-       if (res) {
-               features_shutdown();
-       } else {
-               ast_register_cleanup(features_shutdown);
-       }
+       ast_register_cleanup(features_shutdown);
 
        return res;
 }
index e2d405740f995494e67dea35f9d5ee845a7e566a..3dac8272e05a52a0bd00760a38bffaf8f22f4e21 100644 (file)
@@ -2000,9 +2000,5 @@ int ast_features_config_init(void)
        res |= __ast_custom_function_register(&featuremap_function, NULL);
        res |= ast_cli_register_multiple(cli_features_config, ARRAY_LEN(cli_features_config));
 
-       if (res) {
-               ast_features_config_shutdown();
-       }
-
        return res;
 }
index 4888680761c00b48b55f34a3f99d7b52a5a678e9..8ca106813122e1b9db387127e1c34f5c6b216cfe 100644 (file)
@@ -1173,13 +1173,13 @@ static void indications_shutdown(void)
 /*! \brief Load indications module */
 int ast_indications_init(void)
 {
-       if (!(ast_tone_zones = ao2_container_alloc(NUM_TONE_ZONE_BUCKETS,
-                       ast_tone_zone_hash, ast_tone_zone_cmp))) {
+       ast_tone_zones = ao2_container_alloc(NUM_TONE_ZONE_BUCKETS,
+                       ast_tone_zone_hash, ast_tone_zone_cmp);
+       if (!ast_tone_zones) {
                return -1;
        }
 
        if (load_indications(0)) {
-               indications_shutdown();
                return -1;
        }
 
index 605e0c97e6a97af70566f5a5e805ce329e09d0b4..44418b8add5cbe7713bc61919b6644351ef892ab 100644 (file)
@@ -1433,7 +1433,6 @@ int load_pbx_builtins(void)
        for (x = 0; x < ARRAY_LEN(builtins); x++) {
                if (ast_register_application2(builtins[x].name, builtins[x].execute, NULL, NULL, NULL)) {
                        ast_log(LOG_ERROR, "Unable to register builtin application '%s'\n", builtins[x].name);
-                       unload_pbx_builtins();
                        return -1;
                }
        }
index c20854f88b19e8ad319531a362554653f7e4116e..2418ce3eed7e025b2ff40def4187b351e5850001 100644 (file)
@@ -383,20 +383,17 @@ int ast_sorcery_init(void)
        wizards = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, WIZARD_BUCKETS,
                ast_sorcery_internal_wizard_hash_fn, NULL, ast_sorcery_internal_wizard_cmp_fn);
        if (!wizards) {
-               sorcery_cleanup();
                return -1;
        }
 
        observers = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, NULL, NULL);
        if (!observers) {
-               sorcery_cleanup();
                return -1;
        }
 
        instances = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, INSTANCE_BUCKETS,
                ast_sorcery_hash_fn, NULL, ast_sorcery_cmp_fn);
        if (!instances) {
-               sorcery_cleanup();
                return -1;
        }