]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Replace most uses of ast_register_atexit with ast_register_cleanup.
authorCorey Farrell <git@cfware.com>
Thu, 26 Mar 2015 22:24:26 +0000 (22:24 +0000)
committerCorey Farrell <git@cfware.com>
Thu, 26 Mar 2015 22:24:26 +0000 (22:24 +0000)
Since 'core stop now' and 'core restart now' do not stop modules,
it is unsafe for most of the core to run cleanups.  Originally all
cleanups used ast_register_atexit, and were only changed when it
was shown to be unsafe.  ast_register_atexit is now used only when
absolutely required to prevent corruption and close child processes.

Exceptions that need to use ast_register_atexit:
* CDR: Flush records.
* res_musiconhold: Kill external applications.
* AstDB: Close the DB.
* canary_exit: Kill canary process.

ASTERISK-24142 #close
Reported by: David Brillert

ASTERISK-24683 #close
Reported by: Peter Katzmann

ASTERISK-24805 #close
Reported by: Badalian Vyacheslav

ASTERISK-24881 #close
Reported by: Corey Farrell

Review: https://reviewboard.asterisk.org/r/4500/
Review: https://reviewboard.asterisk.org/r/4501/
........

Merged revisions 433495 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 433497 from http://svn.asterisk.org/svn/asterisk/branches/13

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@433498 65c4cc65-6c06-0410-ace0-fbb531ad65f3

45 files changed:
include/asterisk.h
main/aoc.c
main/asterisk.c
main/astfd.c
main/astmm.c
main/astobj2.c
main/astobj2_container.c
main/bridge.c
main/ccss.c
main/cel.c
main/channel.c
main/cli.c
main/codec.c
main/config.c
main/config_options.c
main/core_local.c
main/data.c
main/dnsmgr.c
main/features.c
main/file.c
main/format.c
main/format_cache.c
main/http.c
main/image.c
main/indications.c
main/manager.c
main/manager_bridges.c
main/manager_channels.c
main/manager_endpoints.c
main/manager_mwi.c
main/manager_system.c
main/message.c
main/pbx.c
main/pickup.c
main/rtp_engine.c
main/sorcery.c
main/sounds_index.c
main/stasis.c
main/stun.c
main/taskprocessor.c
main/threadstorage.c
main/timing.c
main/udptl.c
main/utils.c
main/xmldoc.c

index edb100b6befaca492fdb798b34531aa3aa25e5da..9a0264e8ceed2c469ca7ed23927836dfdc67e365 100644 (file)
@@ -86,6 +86,11 @@ int ast_pbx_init(void);                              /*!< Provided by pbx.c */
  *
  * \retval 0 on success.
  * \retval -1 on error.
+ *
+ * \note This function should be rarely used in situations where
+ * something must be shutdown to avoid corruption, excessive data
+ * loss, or when external programs must be stopped.  All other
+ * cleanup in the core should use ast_register_cleanup.
  */
 int ast_register_atexit(void (*func)(void));
 
index b66f2dea8096733590ffe99effe4daab2b1c2219..5bce0665155e776da6601ff7b179165a78605e81 100644 (file)
@@ -2011,6 +2011,6 @@ int ast_aoc_cli_init(void)
        STASIS_MESSAGE_TYPE_INIT(aoc_d_type);
        STASIS_MESSAGE_TYPE_INIT(aoc_e_type);
 
-       ast_register_atexit(aoc_shutdown);
+       ast_register_cleanup(aoc_shutdown);
        return ast_cli_register_multiple(aoc_cli, ARRAY_LEN(aoc_cli));
 }
index ab010774d526a2da38f1c7f5c183879e3efbf2b8..3eaaf183d479c43d378689561c414c2899a1c95b 100644 (file)
@@ -4684,7 +4684,7 @@ int main(int argc, char *argv[])
        ast_lastreloadtime = ast_startuptime = ast_tvnow();
        ast_cli_register_multiple(cli_asterisk_shutdown, ARRAY_LEN(cli_asterisk_shutdown));
        ast_cli_register_multiple(cli_asterisk, ARRAY_LEN(cli_asterisk));
-       ast_register_atexit(main_atexit);
+       ast_register_cleanup(main_atexit);
 
        run_startup_commands();
 
index e64177bbcfdff904485bb524ca251a9cb5893780..d9119c9688341a99a64e521c5d8e2b41505fcb4f 100644 (file)
@@ -281,7 +281,7 @@ static void fd_shutdown(void)
 
 int ast_fd_init(void)
 {
-       ast_register_atexit(fd_shutdown);
+       ast_register_cleanup(fd_shutdown);
        return ast_cli_register(&cli_show_fd);
 }
 
index 6143280d62ef1aad6a7d0925317c478f2fbd7349..5812174d5caf782e25261beac515afa1856b9f7f 100644 (file)
@@ -1493,7 +1493,7 @@ void __ast_mm_init_phase_2(void)
                ast_log(LOG_ERROR, "Could not open malloc debug log file: %s\n", filename);
        }
 
-       ast_register_atexit(mm_atexit_ast);
+       ast_register_cleanup(mm_atexit_ast);
 }
 
 #endif /* defined(__AST_DEBUG_MALLOC) */
index 7f7d9bd9283589c51dc424d8bdcbf044aef1809c..4ee1734da73c52750c7c85f99623cf823126b017 100644 (file)
@@ -914,7 +914,7 @@ int astobj2_init(void)
        ast_cli_register_multiple(cli_astobj2, ARRAY_LEN(cli_astobj2));
 #endif /* defined(AO2_DEBUG) */
 
-       ast_register_atexit(astobj2_cleanup);
+       ast_register_cleanup(astobj2_cleanup);
 
        return 0;
 }
index 4d4e4749d3be82cc36c1b3527f17ab83d0977e95..dc6f5e5c552e506585f1b283394bb7339815bec2 100644 (file)
@@ -1211,7 +1211,7 @@ int container_init(void)
        }
 
        ast_cli_register_multiple(cli_astobj2, ARRAY_LEN(cli_astobj2));
-       ast_register_atexit(container_cleanup);
+       ast_register_cleanup(container_cleanup);
 #endif /* defined(AO2_DEBUG) */
 
        return 0;
index 4bfd58377496fe275fd0ee5184265fde908f355d..2c0776191c20109260b45c95bb144016130db5d6 100644 (file)
@@ -5320,29 +5320,19 @@ static void bridge_prnt_obj(void *v_obj, void *where, ao2_prnt_fn *prnt)
 
 /*!
  * \internal
- * \brief Shutdown the bridging system.  Stuff to always do.
- * \since 12.0.0
+ * \brief Shutdown the bridging system.  Stuff to do on graceful shutdown.
+ * \since 13.3.0
  *
  * \return Nothing
  */
-static void bridge_shutdown(void)
+static void bridge_cleanup(void)
 {
        ast_manager_unregister("BridgeTechnologyList");
        ast_manager_unregister("BridgeTechnologySuspend");
        ast_manager_unregister("BridgeTechnologyUnsuspend");
        ast_cli_unregister_multiple(bridge_cli, ARRAY_LEN(bridge_cli));
        ao2_container_unregister("bridges");
-}
 
-/*!
- * \internal
- * \brief Shutdown the bridging system.  More stuff to do on graceful shutdown.
- * \since 13.3.0
- *
- * \return Nothing
- */
-static void bridge_cleanup(void)
-{
        ao2_cleanup(bridges);
        bridges = NULL;
        ao2_cleanup(bridge_manager);
@@ -5352,7 +5342,6 @@ static void bridge_cleanup(void)
 int ast_bridging_init(void)
 {
        ast_register_cleanup(bridge_cleanup);
-       ast_register_atexit(bridge_shutdown);
 
        if (ast_stasis_bridging_init()) {
                return -1;
index 3626f3d38b9cb21bacd6a3f0d5823cf5792773d3..7f6369009256442ffe894beb57d5506883611416 100644 (file)
@@ -4688,7 +4688,7 @@ int ast_cc_init(void)
        initialize_cc_devstate_map();
        res |= ast_devstate_prov_add("ccss", ccss_device_state);
 
-       ast_register_atexit(cc_shutdown);
+       ast_register_cleanup(cc_shutdown);
 
        return res;
 }
index 9463603e6e8a41a0fe65e51a952f8fca015f7f36..93655c741b2fad6730c8de5597a1e4f4c0c7afcd 100644 (file)
@@ -1513,10 +1513,7 @@ static void cel_engine_cleanup(void)
        destroy_routes();
        destroy_subscriptions();
        STASIS_MESSAGE_TYPE_CLEANUP(cel_generic_type);
-}
 
-static void cel_engine_atexit(void)
-{
        ast_cli_unregister(&cli_status);
        aco_info_destroy(&cel_cfg_info);
        ao2_global_obj_release(cel_configs);
@@ -1525,12 +1522,6 @@ static void cel_engine_atexit(void)
        ao2_global_obj_release(cel_backends);
 }
 
-static void cel_engine_abort(void)
-{
-       cel_engine_cleanup();
-       cel_engine_atexit();
-}
-
 /*!
  * \brief Create the Stasis subscriptions for CEL
  */
@@ -1714,7 +1705,7 @@ int ast_cel_engine_init(void)
        ao2_global_obj_replace_unref(cel_linkedids, container);
        ao2_cleanup(container);
        if (!container) {
-               cel_engine_abort();
+               cel_engine_cleanup();
                return -1;
        }
 
@@ -1723,17 +1714,17 @@ int ast_cel_engine_init(void)
        ao2_global_obj_replace_unref(cel_dialstatus_store, container);
        ao2_cleanup(container);
        if (!container) {
-               cel_engine_abort();
+               cel_engine_cleanup();
                return -1;
        }
 
        if (STASIS_MESSAGE_TYPE_INIT(cel_generic_type)) {
-               cel_engine_abort();
+               cel_engine_cleanup();
                return -1;
        }
 
        if (ast_cli_register(&cli_status)) {
-               cel_engine_abort();
+               cel_engine_cleanup();
                return -1;
        }
 
@@ -1741,12 +1732,12 @@ int ast_cel_engine_init(void)
        ao2_global_obj_replace_unref(cel_backends, container);
        ao2_cleanup(container);
        if (!container) {
-               cel_engine_abort();
+               cel_engine_cleanup();
                return -1;
        }
 
        if (aco_info_init(&cel_cfg_info)) {
-               cel_engine_abort();
+               cel_engine_cleanup();
                return -1;
        }
 
@@ -1759,7 +1750,7 @@ int ast_cel_engine_init(void)
                struct cel_config *cel_cfg = cel_config_alloc();
 
                if (!cel_cfg) {
-                       cel_engine_abort();
+                       cel_engine_cleanup();
                        return -1;
                }
 
@@ -1772,16 +1763,15 @@ int ast_cel_engine_init(void)
        }
 
        if (create_subscriptions()) {
-               cel_engine_abort();
+               cel_engine_cleanup();
                return -1;
        }
 
        if (ast_cel_check_enabled() && create_routes()) {
-               cel_engine_abort();
+               cel_engine_cleanup();
                return -1;
        }
 
-       ast_register_atexit(cel_engine_atexit);
        ast_register_cleanup(cel_engine_cleanup);
        return 0;
 }
index 58daf5732d9fd8872dec79790fe6b2c6971fc754..aedb9463eccb87b4ed571c02ed6bee8361ee2682 100644 (file)
@@ -7645,7 +7645,7 @@ void ast_channels_init(void)
 
        ast_plc_reload();
 
-       ast_register_atexit(channels_shutdown);
+       ast_register_cleanup(channels_shutdown);
 
 }
 
index 1edb1f49feba7eacdbefb3437c215bfecb8667fc..42f56fcfde1bf21bbf03f71d839f9cf90fa06bca 100644 (file)
@@ -2026,7 +2026,7 @@ static void cli_shutdown(void)
 void ast_builtins_init(void)
 {
        ast_cli_register_multiple(cli_cli, ARRAY_LEN(cli_cli));
-       ast_register_atexit(cli_shutdown);
+       ast_register_cleanup(cli_shutdown);
 }
 
 /*!
index 45f2edf2baf7c2902602a070c9ea7c14a9fa0f9b..543d4d0bde6dc9e8df51cace5d546dbe06c59926 100644 (file)
@@ -245,7 +245,7 @@ int ast_codec_init(void)
        }
 
        ast_cli_register_multiple(codec_cli, ARRAY_LEN(codec_cli));
-       ast_register_atexit(codec_shutdown);
+       ast_register_cleanup(codec_shutdown);
 
        return 0;
 }
index 517b33bfdae6a244af6156f721ff2f5deaaca7e2..4a9d0c1814ece7d23b056a87be5fc8abf75b5ec9 100644 (file)
@@ -3836,7 +3836,7 @@ static void config_shutdown(void)
 int register_config_cli(void)
 {
        ast_cli_register_multiple(cli_config, ARRAY_LEN(cli_config));
-       ast_register_atexit(config_shutdown);
+       ast_register_cleanup(config_shutdown);
        return 0;
 }
 
index 89b19e05b9f4515c5292b4078a085cd366253737..0cc2dda3e5740f6e1ccbc58e9a47cceeac455cea 100644 (file)
@@ -1281,7 +1281,7 @@ static void aco_deinit(void)
 int aco_init(void)
 {
 #ifdef AST_XML_DOCS
-       ast_register_atexit(aco_deinit);
+       ast_register_cleanup(aco_deinit);
        if (!(xmldocs = ast_xmldoc_build_documentation("configInfo"))) {
                ast_log(LOG_ERROR, "Couldn't build config documentation\n");
                return -1;
index 934cf86bf163bf5e92d5a09cd78aaa60a79ffe62..8d8e6fc55de6bc0d588770155a26d0ea06b3f412 100644 (file)
@@ -1006,14 +1006,6 @@ static void local_shutdown(void)
        ast_manager_unregister("LocalOptimizeAway");
        ast_channel_unregister(&local_tech);
 
-       it = ao2_iterator_init(locals, 0);
-       while ((p = ao2_iterator_next(&it))) {
-               if (p->base.owner) {
-                       ast_softhangup(p->base.owner, AST_SOFTHANGUP_APPUNLOAD);
-               }
-               ao2_ref(p, -1);
-       }
-       ao2_iterator_destroy(&it);
        ao2_ref(locals, -1);
        locals = NULL;
 
@@ -1063,6 +1055,6 @@ int ast_local_init(void)
        ast_cli_register_multiple(cli_local, ARRAY_LEN(cli_local));
        ast_manager_register_xml_core("LocalOptimizeAway", EVENT_FLAG_SYSTEM|EVENT_FLAG_CALL, manager_optimize_away);
 
-       ast_register_atexit(local_shutdown);
+       ast_register_cleanup(local_shutdown);
        return 0;
 }
index 16571c8e49630f36c3e0c0c7d79ee3f84b99bbed..33a7c040fdf187fba314d571c1f7b26d5fbe72bd 100644 (file)
@@ -3342,7 +3342,7 @@ int ast_data_init(void)
 
        AST_TEST_REGISTER(test_data_get);
 
-       ast_register_atexit(data_shutdown);
+       ast_register_cleanup(data_shutdown);
 
        return res;
 }
index d642cd616df322af0445a1f0aab1e445c1fc7f6b..b5bfd17bea0b2d15151e9a10595d552339ed8a16 100644 (file)
@@ -438,7 +438,7 @@ int dnsmgr_init(void)
        ast_cli_register(&cli_status);
        ast_cli_register(&cli_refresh);
 
-       ast_register_atexit(dnsmgr_shutdown);
+       ast_register_cleanup(dnsmgr_shutdown);
 
        return do_reload(1);
 }
index f5993d3f762e02400e097b670fd9cc9a7f3f23f5..ac599c7c8dec6773573a9d03d89635e41fde57ce 100644 (file)
@@ -1184,7 +1184,7 @@ int ast_features_init(void)
        if (res) {
                features_shutdown();
        } else {
-               ast_register_atexit(features_shutdown);
+               ast_register_cleanup(features_shutdown);
        }
 
        return res;
index e580d9c569c52f4be4e8f330b7b7ef66a9124c8b..c32de2811857cb0a554a11f7da6b749828b5995d 100644 (file)
@@ -1780,6 +1780,6 @@ int ast_file_init(void)
        STASIS_MESSAGE_TYPE_INIT(ast_format_register_type);
        STASIS_MESSAGE_TYPE_INIT(ast_format_unregister_type);
        ast_cli_register_multiple(cli_file, ARRAY_LEN(cli_file));
-       ast_register_atexit(file_shutdown);
+       ast_register_cleanup(file_shutdown);
        return 0;
 }
index 09d7ef0c507af937c676352851fbc8623a67af07..b6661574e5e649b2df8f2c6cadf1fb9f0e3440fa 100644 (file)
@@ -126,7 +126,7 @@ int ast_format_init(void)
                return -1;
        }
 
-       ast_register_atexit(format_shutdown);
+       ast_register_cleanup(format_shutdown);
 
        return 0;
 }
index 07e4d8fbbda462d42f8c7a87257dca79aaf509fa..9b83a3b8dc32d84b318f4c0d0d319d435a4ef7e2 100644 (file)
@@ -341,7 +341,7 @@ int ast_format_cache_init(void)
                return -1;
        }
 
-       ast_register_atexit(format_cache_shutdown);
+       ast_register_cleanup(format_cache_shutdown);
 
        return 0;
 }
index 1ac6c737a2e12da670efe9f70740783421e7e929..26e218ba0bd38fbbefe4469a12051c4d4e9f4e01 100644 (file)
@@ -2338,7 +2338,7 @@ int ast_http_init(void)
        ast_http_uri_link(&statusuri);
        ast_http_uri_link(&staticuri);
        ast_cli_register_multiple(cli_http, ARRAY_LEN(cli_http));
-       ast_register_atexit(http_shutdown);
+       ast_register_cleanup(http_shutdown);
 
        return __ast_http_load(0);
 }
index 53638f30c51e37b658bdbdaf32e887a29530772d..118cd17c2449e9fb43edc1bf8a1d96009517f703 100644 (file)
@@ -214,6 +214,6 @@ static void image_shutdown(void)
 int ast_image_init(void)
 {
        ast_cli_register_multiple(cli_image, ARRAY_LEN(cli_image));
-       ast_register_atexit(image_shutdown);
+       ast_register_cleanup(image_shutdown);
        return 0;
 }
index 27d2b535677e160ce1108865ff0d872f194d42dc..af9cfc8ef7c5903d45c36baadfd274ec6e145145 100644 (file)
@@ -1186,7 +1186,7 @@ int ast_indications_init(void)
 
        ast_cli_register_multiple(cli_indications, ARRAY_LEN(cli_indications));
 
-       ast_register_atexit(indications_shutdown);
+       ast_register_cleanup(indications_shutdown);
        return 0;
 }
 
index 6b1eda0ea8f7acdb78892bea4338713fa3d6deb5..1896f05bb41c89d4aac43ea7c8373ed5da0ef1c5 100644 (file)
@@ -8621,7 +8621,7 @@ static int __init_manager(int reload, int by_external_config)
 #endif
                int res;
 
-               ast_register_atexit(manager_shutdown);
+               ast_register_cleanup(manager_shutdown);
 
                res = STASIS_MESSAGE_TYPE_INIT(ast_manager_get_generic_type);
                if (res != 0) {
index fe022cb577680aa00627009384c4e179f1d6fa18..e190baa83c453a57a15bf6bc793a70c4ab203dc1 100644 (file)
@@ -591,10 +591,7 @@ static void manager_bridging_cleanup(void)
 {
        stasis_forward_cancel(topic_forwarder);
        topic_forwarder = NULL;
-}
 
-static void manager_bridging_shutdown(void)
-{
        ast_manager_unregister("BridgeList");
        ast_manager_unregister("BridgeInfo");
        ast_manager_unregister("BridgeDestroy");
@@ -612,7 +609,6 @@ int manager_bridging_init(void)
                return 0;
        }
 
-       ast_register_atexit(manager_bridging_shutdown);
        ast_register_cleanup(manager_bridging_cleanup);
 
        manager_topic = ast_manager_get_topic();
@@ -656,7 +652,7 @@ int manager_bridging_init(void)
         * thing and fail it.
         */
        if (ret) {
-               manager_bridging_shutdown();
+               manager_bridging_cleanup();
                return -1;
        }
 
index c12d94ee9cbe9b1ccc9df501d80e41f22518787c..f6dc46cec4b33d98b71c19096fb0684f7c029221 100644 (file)
@@ -1136,7 +1136,7 @@ int manager_channels_init(void)
                return -1;
        }
 
-       ast_register_atexit(manager_channels_shutdown);
+       ast_register_cleanup(manager_channels_shutdown);
 
        ret |= stasis_message_router_add_cache_update(message_router,
                ast_channel_snapshot_type(), channel_snapshot_update, NULL);
index b5f5b31c282f61266ca2c16f7eee222ff6ee256f..0d0866016199a4e4973acbcd3d8a2a9f9f42f972 100644 (file)
@@ -61,7 +61,7 @@ int manager_endpoints_init(void)
                return 0;
        }
 
-       ast_register_atexit(manager_endpoints_shutdown);
+       ast_register_cleanup(manager_endpoints_shutdown);
 
        endpoint_topic = ast_endpoint_topic_all_cached();
        if (!endpoint_topic) {
index 849c315e130bf13a20314183d87144073e890525..8facc9093616447b910acc88cb5f19ca6a11f6da 100644 (file)
@@ -176,7 +176,7 @@ int manager_mwi_init(void)
                return -1;
        }
 
-       ast_register_atexit(manager_mwi_shutdown);
+       ast_register_cleanup(manager_mwi_shutdown);
 
        ret |= stasis_message_router_add(message_router,
                                         ast_mwi_state_type(),
index f4e7e9e0bb70ddcb64932ce38276074b34ca4fc3..b852c52e6b3bc6951809b1cc105eef41ea8eb95a 100644 (file)
@@ -67,7 +67,7 @@ int manager_system_init(void)
                return -1;
        }
 
-       ast_register_atexit(manager_system_shutdown);
+       ast_register_cleanup(manager_system_shutdown);
 
        /* If somehow we failed to add any routes, just shut down the whole
         * thing and fail it.
index ff88c2f6da13947d85bad0eaf117711c85e99296..581487fcd70c820499fe6240c36b2c3f7f742780 100644 (file)
@@ -1516,7 +1516,7 @@ int ast_msg_init(void)
        res |= ast_register_application2(app_msg_send, msg_send_exec, NULL, NULL, NULL);
        res |= ast_manager_register_xml_core("MessageSend", EVENT_FLAG_MESSAGE, action_messagesend);
 
-       ast_register_atexit(message_shutdown);
+       ast_register_cleanup(message_shutdown);
 
        return res;
 }
index 498acf79b60ccb79de422cc7d8aefea6be8604dd..0573ab076795d7ab1975483398e127f81013f185 100644 (file)
@@ -12102,7 +12102,7 @@ int load_pbx(void)
        int res = 0;
        int x;
 
-       ast_register_atexit(unload_pbx);
+       ast_register_cleanup(unload_pbx);
 
        /* Initialize the PBX */
        ast_verb(1, "Asterisk PBX Core Initializing\n");
index 125ec9359cfcea9311380d3ce2fb633a617a84c4..6f1e0f12f6eee70f62be8db0ccd12b321ce8ea5e 100644 (file)
@@ -403,7 +403,7 @@ static void pickup_shutdown(void)
 int ast_pickup_init(void)
 {
        STASIS_MESSAGE_TYPE_INIT(ast_call_pickup_type);
-       ast_register_atexit(pickup_shutdown);
+       ast_register_cleanup(pickup_shutdown);
 
        return 0;
 }
index 8c3367b6f8a033a00472701d740ace704d004fd9..e3ab52d3b7e4454595d074c0b3a81a1f3e21b134 100644 (file)
@@ -2092,7 +2092,7 @@ int ast_rtp_engine_init()
        }
        STASIS_MESSAGE_TYPE_INIT(ast_rtp_rtcp_sent_type);
        STASIS_MESSAGE_TYPE_INIT(ast_rtp_rtcp_received_type);
-       ast_register_atexit(rtp_engine_shutdown);
+       ast_register_cleanup(rtp_engine_shutdown);
 
        /* Define all the RTP mime types available */
        set_next_mime_type(ast_format_g723, 0, "audio", "G723", 8000);
index 879723be4b2cd752b2c2c8f127e742f50bb89b34..d3d6f3d7d2ddc1c1a4348b1da9e61530db098401 100644 (file)
@@ -416,16 +416,11 @@ static int object_type_field_cmp(void *obj, void *arg, int flags)
        return CMP_MATCH;
 }
 
-/*! \brief Cleanup function */
-static void sorcery_exit(void)
-{
-       ast_threadpool_shutdown(threadpool);
-       threadpool = NULL;
-}
-
 /*! \brief Cleanup function for graceful shutdowns */
 static void sorcery_cleanup(void)
 {
+       ast_threadpool_shutdown(threadpool);
+       threadpool = NULL;
        ao2_cleanup(wizards);
        wizards = NULL;
        ao2_cleanup(observers);
@@ -507,7 +502,6 @@ int ast_sorcery_init(void)
        observers = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, NULL, NULL);
        if (!observers) {
                sorcery_cleanup();
-               sorcery_exit();
                return -1;
        }
 
@@ -515,12 +509,10 @@ int ast_sorcery_init(void)
                sorcery_instance_hash, sorcery_instance_cmp);
        if (!instances) {
                sorcery_cleanup();
-               sorcery_exit();
                return -1;
        }
 
        ast_register_cleanup(sorcery_cleanup);
-       ast_register_atexit(sorcery_exit);
 
        return 0;
 }
index 8ca5967e4d48f68d58d55971462e0fd219eca6e6..c7f9f4dd950ec28c577d4e4fb6f74609b2b571dc 100644 (file)
@@ -322,7 +322,7 @@ int ast_sounds_index_init(void)
                return -1;
        }
 
-       ast_register_atexit(sounds_cleanup);
+       ast_register_cleanup(sounds_cleanup);
        return 0;
 }
 
index dbb6e4c12820df77384697be54836ec0d9168776..c2d552e4bebd5a91b628782a9f668ca7bd6b242e 100644 (file)
@@ -1533,16 +1533,11 @@ STASIS_MESSAGE_TYPE_DEFN(ast_multi_user_event_type,
 
 /*! @} */
 
-/*! \brief Shutdown function */
-static void stasis_exit(void)
-{
-       ast_threadpool_shutdown(pool);
-       pool = NULL;
-}
-
 /*! \brief Cleanup function for graceful shutdowns */
 static void stasis_cleanup(void)
 {
+       ast_threadpool_shutdown(pool);
+       pool = NULL;
        STASIS_MESSAGE_TYPE_CLEANUP(stasis_subscription_change_type);
        STASIS_MESSAGE_TYPE_CLEANUP(ast_multi_user_event_type);
        aco_info_destroy(&cfg_info);
@@ -1557,7 +1552,6 @@ int stasis_init(void)
 
        /* Be sure the types are cleaned up after the message bus */
        ast_register_cleanup(stasis_cleanup);
-       ast_register_atexit(stasis_exit);
 
        if (aco_info_init(&cfg_info)) {
                return -1;
index e0a25594f63d321d95ab8ec62f33b3b667d686ea..f5bdc9ad4db482503b9b89f9c8d71278bc178301 100644 (file)
@@ -516,5 +516,5 @@ static void stun_shutdown(void)
 void ast_stun_init(void)
 {
        ast_cli_register_multiple(cli_stun, sizeof(cli_stun) / sizeof(struct ast_cli_entry));
-       ast_register_atexit(stun_shutdown);
+       ast_register_cleanup(stun_shutdown);
 }
index 5fbbca571d2d5171193263d4bd43f515c12ce3f8..dd416dbae6aec324df31957e828c5c500f450c5c 100644 (file)
@@ -278,7 +278,7 @@ int ast_tps_init(void)
 
        ast_cli_register_multiple(taskprocessor_clis, ARRAY_LEN(taskprocessor_clis));
 
-       ast_register_atexit(tps_shutdown);
+       ast_register_cleanup(tps_shutdown);
 
        return 0;
 }
index 349cb4ecdf7cbd2a4509eb93177f7c780d4ec36e..4c46a0f585b6651d778c9ec0effd06c18be18cd3 100644 (file)
@@ -258,7 +258,7 @@ void threadstorage_init(void)
 {
        pthread_mutex_init(&threadstoragelock, NULL);
        ast_cli_register_multiple(cli, ARRAY_LEN(cli));
-       ast_register_atexit(threadstorage_shutdown);
+       ast_register_cleanup(threadstorage_shutdown);
 }
 
 #endif /* !defined(DEBUG_THREADLOCALS) */
index 5318ded0614615f6959b8f5c8525394ec78ce5f3..ae8c3ebff6e77de4437906fd93909b3eb0881bd9 100644 (file)
@@ -289,7 +289,7 @@ int ast_timing_init(void)
                return -1;
        }
 
-       ast_register_atexit(timing_shutdown);
+       ast_register_cleanup(timing_shutdown);
 
        return ast_cli_register_multiple(cli_timing, ARRAY_LEN(cli_timing));
 }
index d8b02b02376ee3354ec0b174b5e3d68ce8be624a..91458489d846a82bf5e78dbf7a3c7950a000fb63 100644 (file)
@@ -1403,5 +1403,5 @@ void ast_udptl_init(void)
 
        ast_cli_register_multiple(cli_udptl, ARRAY_LEN(cli_udptl));
 
-       ast_register_atexit(udptl_shutdown);
+       ast_register_cleanup(udptl_shutdown);
 }
index d7bf4d797a388b53fcaccbfb27a1bfe7ca2de42c..888aaab81071d83f86cfa46066831f188611e9bc 100644 (file)
@@ -2476,7 +2476,7 @@ int ast_utils_init(void)
        ast_cli_register_multiple(utils_cli, ARRAY_LEN(utils_cli));
 #endif
 #endif
-       ast_register_atexit(utils_shutdown);
+       ast_register_cleanup(utils_shutdown);
        return 0;
 }
 
index 2f4f063b9ae6a5eb29d403d6eac81baaa8a86bdd..fcf1b2cacb197eff120edb2b2ad4e55945d1a05b 100644 (file)
@@ -2962,7 +2962,7 @@ int ast_xmldoc_load_documentation(void)
 
        ast_cli_register(&cli_dump_xmldocs);
        /* register function to be run when asterisk finish. */
-       ast_register_atexit(xmldoc_unload_documentation);
+       ast_register_cleanup(xmldoc_unload_documentation);
 
        globbuf.gl_offs = 0;    /* slots to reserve in gl_pathv */