[asterisk-commits] Replace most uses of ast register atexit with ast register c... (asterisk[certified/13.1])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Oct 23 06:49:04 CDT 2015


Joshua Colp has submitted this change and it was merged.

Change subject: Replace most uses of ast_register_atexit with ast_register_cleanup.
......................................................................


Replace most uses of ast_register_atexit with ast_register_cleanup.

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

Change-Id: I6a67336050dea74327d79cdd6f7c7ea34d0b473e
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@433497
---
M include/asterisk.h
M main/aoc.c
M main/asterisk.c
M main/astfd.c
M main/astmm.c
M main/astobj2.c
M main/astobj2_container.c
M main/bridge.c
M main/ccss.c
M main/cel.c
M main/channel.c
M main/cli.c
M main/codec.c
M main/config.c
M main/config_options.c
M main/core_local.c
M main/data.c
M main/dnsmgr.c
M main/features.c
M main/file.c
M main/format.c
M main/format_cache.c
M main/http.c
M main/image.c
M main/indications.c
M main/manager.c
M main/manager_bridges.c
M main/manager_channels.c
M main/manager_endpoints.c
M main/manager_mwi.c
M main/manager_system.c
M main/message.c
M main/pbx.c
M main/pickup.c
M main/rtp_engine.c
M main/sorcery.c
M main/sounds_index.c
M main/stasis.c
M main/stun.c
M main/taskprocessor.c
M main/threadstorage.c
M main/timing.c
M main/udptl.c
M main/utils.c
M main/xmldoc.c
45 files changed, 65 insertions(+), 110 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Richard Mudgett: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved



diff --git a/include/asterisk.h b/include/asterisk.h
index 9059a54..c501c44 100644
--- a/include/asterisk.h
+++ b/include/asterisk.h
@@ -86,6 +86,11 @@
  *
  * \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));
 
diff --git a/main/aoc.c b/main/aoc.c
index de43efc..ff764ae 100644
--- a/main/aoc.c
+++ b/main/aoc.c
@@ -1947,6 +1947,6 @@
 	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));
 }
diff --git a/main/asterisk.c b/main/asterisk.c
index 959fb95..5e63b25 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -4680,7 +4680,7 @@
 	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();
 
diff --git a/main/astfd.c b/main/astfd.c
index e64177b..d9119c9 100644
--- a/main/astfd.c
+++ b/main/astfd.c
@@ -281,7 +281,7 @@
 
 int ast_fd_init(void)
 {
-	ast_register_atexit(fd_shutdown);
+	ast_register_cleanup(fd_shutdown);
 	return ast_cli_register(&cli_show_fd);
 }
 
diff --git a/main/astmm.c b/main/astmm.c
index 6143280..5812174 100644
--- a/main/astmm.c
+++ b/main/astmm.c
@@ -1493,7 +1493,7 @@
 		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) */
diff --git a/main/astobj2.c b/main/astobj2.c
index 7f7d9bd..4ee1734 100644
--- a/main/astobj2.c
+++ b/main/astobj2.c
@@ -914,7 +914,7 @@
 	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;
 }
diff --git a/main/astobj2_container.c b/main/astobj2_container.c
index 4d4e474..dc6f5e5 100644
--- a/main/astobj2_container.c
+++ b/main/astobj2_container.c
@@ -1211,7 +1211,7 @@
 	}
 
 	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;
diff --git a/main/bridge.c b/main/bridge.c
index 00ea602..a63f745 100644
--- a/main/bridge.c
+++ b/main/bridge.c
@@ -5267,29 +5267,19 @@
 
 /*!
  * \internal
- * \brief Shutdown the bridging system.  Stuff to always do.
- * \since 12.0.0
- *
- * \return Nothing
- */
-static void bridge_shutdown(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.
+ * \brief Shutdown the bridging system.  Stuff to do on graceful shutdown.
  * \since 13.3.0
  *
  * \return Nothing
  */
 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");
+
 	ao2_cleanup(bridges);
 	bridges = NULL;
 	ao2_cleanup(bridge_manager);
@@ -5299,7 +5289,6 @@
 int ast_bridging_init(void)
 {
 	ast_register_cleanup(bridge_cleanup);
-	ast_register_atexit(bridge_shutdown);
 
 	if (ast_stasis_bridging_init()) {
 		return -1;
diff --git a/main/ccss.c b/main/ccss.c
index 571aa6d..a7b27c0 100644
--- a/main/ccss.c
+++ b/main/ccss.c
@@ -4686,7 +4686,7 @@
 	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;
 }
diff --git a/main/cel.c b/main/cel.c
index 9463603..93655c7 100644
--- a/main/cel.c
+++ b/main/cel.c
@@ -1513,22 +1513,13 @@
 	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);
 	ao2_global_obj_release(cel_dialstatus_store);
 	ao2_global_obj_release(cel_linkedids);
 	ao2_global_obj_release(cel_backends);
-}
-
-static void cel_engine_abort(void)
-{
-	cel_engine_cleanup();
-	cel_engine_atexit();
 }
 
 /*!
@@ -1714,7 +1705,7 @@
 	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 @@
 	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 @@
 	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 @@
 		struct cel_config *cel_cfg = cel_config_alloc();
 
 		if (!cel_cfg) {
-			cel_engine_abort();
+			cel_engine_cleanup();
 			return -1;
 		}
 
@@ -1772,16 +1763,15 @@
 	}
 
 	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;
 }
diff --git a/main/channel.c b/main/channel.c
index d84bf72..4c1b206 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -7648,7 +7648,7 @@
 
 	ast_plc_reload();
 
-	ast_register_atexit(channels_shutdown);
+	ast_register_cleanup(channels_shutdown);
 
 }
 
diff --git a/main/cli.c b/main/cli.c
index f0eb30e..f505fd8 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -2027,7 +2027,7 @@
 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);
 }
 
 /*!
diff --git a/main/codec.c b/main/codec.c
index 19e78fa..f29e996 100644
--- a/main/codec.c
+++ b/main/codec.c
@@ -245,7 +245,7 @@
 	}
 
 	ast_cli_register_multiple(codec_cli, ARRAY_LEN(codec_cli));
-	ast_register_atexit(codec_shutdown);
+	ast_register_cleanup(codec_shutdown);
 
 	return 0;
 }
diff --git a/main/config.c b/main/config.c
index 6f6f7ca..2ebdc83 100644
--- a/main/config.c
+++ b/main/config.c
@@ -3824,7 +3824,7 @@
 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;
 }
 
diff --git a/main/config_options.c b/main/config_options.c
index 89b19e0..0cc2dda 100644
--- a/main/config_options.c
+++ b/main/config_options.c
@@ -1281,7 +1281,7 @@
 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;
diff --git a/main/core_local.c b/main/core_local.c
index 54915ec..10bd839 100644
--- a/main/core_local.c
+++ b/main/core_local.c
@@ -1001,22 +1001,11 @@
  */
 static void local_shutdown(void)
 {
-	struct local_pvt *p;
-	struct ao2_iterator it;
-
 	/* First, take us out of the channel loop */
 	ast_cli_unregister_multiple(cli_local, ARRAY_LEN(cli_local));
 	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;
 
@@ -1066,6 +1055,6 @@
 	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;
 }
diff --git a/main/data.c b/main/data.c
index 16571c8..33a7c04 100644
--- a/main/data.c
+++ b/main/data.c
@@ -3342,7 +3342,7 @@
 
 	AST_TEST_REGISTER(test_data_get);
 
-	ast_register_atexit(data_shutdown);
+	ast_register_cleanup(data_shutdown);
 
 	return res;
 }
diff --git a/main/dnsmgr.c b/main/dnsmgr.c
index d642cd6..b5bfd17 100644
--- a/main/dnsmgr.c
+++ b/main/dnsmgr.c
@@ -438,7 +438,7 @@
 	ast_cli_register(&cli_status);
 	ast_cli_register(&cli_refresh);
 
-	ast_register_atexit(dnsmgr_shutdown);
+	ast_register_cleanup(dnsmgr_shutdown);
 
 	return do_reload(1);
 }
diff --git a/main/features.c b/main/features.c
index 845d535..bb7f3d6 100644
--- a/main/features.c
+++ b/main/features.c
@@ -1163,7 +1163,7 @@
 	if (res) {
 		features_shutdown();
 	} else {
-		ast_register_atexit(features_shutdown);
+		ast_register_cleanup(features_shutdown);
 	}
 
 	return res;
diff --git a/main/file.c b/main/file.c
index 37930fd..b0d5011 100644
--- a/main/file.c
+++ b/main/file.c
@@ -1785,6 +1785,6 @@
 	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;
 }
diff --git a/main/format.c b/main/format.c
index 09d7ef0..b666157 100644
--- a/main/format.c
+++ b/main/format.c
@@ -126,7 +126,7 @@
 		return -1;
 	}
 
-	ast_register_atexit(format_shutdown);
+	ast_register_cleanup(format_shutdown);
 
 	return 0;
 }
diff --git a/main/format_cache.c b/main/format_cache.c
index 07e4d8f..9b83a3b 100644
--- a/main/format_cache.c
+++ b/main/format_cache.c
@@ -341,7 +341,7 @@
 		return -1;
 	}
 
-	ast_register_atexit(format_cache_shutdown);
+	ast_register_cleanup(format_cache_shutdown);
 
 	return 0;
 }
diff --git a/main/http.c b/main/http.c
index 3f92197..5363a15 100644
--- a/main/http.c
+++ b/main/http.c
@@ -2284,7 +2284,7 @@
 	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);
 }
diff --git a/main/image.c b/main/image.c
index 53638f3..118cd17 100644
--- a/main/image.c
+++ b/main/image.c
@@ -214,6 +214,6 @@
 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;
 }
diff --git a/main/indications.c b/main/indications.c
index 27d2b53..af9cfc8 100644
--- a/main/indications.c
+++ b/main/indications.c
@@ -1186,7 +1186,7 @@
 
 	ast_cli_register_multiple(cli_indications, ARRAY_LEN(cli_indications));
 
-	ast_register_atexit(indications_shutdown);
+	ast_register_cleanup(indications_shutdown);
 	return 0;
 }
 
diff --git a/main/manager.c b/main/manager.c
index 9f3331a..23bdaa9 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -8578,7 +8578,7 @@
 #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) {
diff --git a/main/manager_bridges.c b/main/manager_bridges.c
index 26b0e78..1b4e97d 100644
--- a/main/manager_bridges.c
+++ b/main/manager_bridges.c
@@ -577,10 +577,7 @@
 {
 	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");
@@ -598,7 +595,6 @@
 		return 0;
 	}
 
-	ast_register_atexit(manager_bridging_shutdown);
 	ast_register_cleanup(manager_bridging_cleanup);
 
 	manager_topic = ast_manager_get_topic();
@@ -642,7 +638,7 @@
 	 * thing and fail it.
 	 */
 	if (ret) {
-		manager_bridging_shutdown();
+		manager_bridging_cleanup();
 		return -1;
 	}
 
diff --git a/main/manager_channels.c b/main/manager_channels.c
index c9f048d..d4e0224 100644
--- a/main/manager_channels.c
+++ b/main/manager_channels.c
@@ -1161,7 +1161,7 @@
 		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);
diff --git a/main/manager_endpoints.c b/main/manager_endpoints.c
index b5f5b31..0d08660 100644
--- a/main/manager_endpoints.c
+++ b/main/manager_endpoints.c
@@ -61,7 +61,7 @@
 		return 0;
 	}
 
-	ast_register_atexit(manager_endpoints_shutdown);
+	ast_register_cleanup(manager_endpoints_shutdown);
 
 	endpoint_topic = ast_endpoint_topic_all_cached();
 	if (!endpoint_topic) {
diff --git a/main/manager_mwi.c b/main/manager_mwi.c
index 849c315..8facc90 100644
--- a/main/manager_mwi.c
+++ b/main/manager_mwi.c
@@ -176,7 +176,7 @@
 		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(),
diff --git a/main/manager_system.c b/main/manager_system.c
index f4e7e9e..b852c52 100644
--- a/main/manager_system.c
+++ b/main/manager_system.c
@@ -67,7 +67,7 @@
 		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.
diff --git a/main/message.c b/main/message.c
index 4100c0f..01a1c9b 100644
--- a/main/message.c
+++ b/main/message.c
@@ -1524,7 +1524,7 @@
 	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;
 }
diff --git a/main/pbx.c b/main/pbx.c
index 8708e40..3e0d8c8 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -12236,7 +12236,7 @@
 	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");
diff --git a/main/pickup.c b/main/pickup.c
index 125ec93..6f1e0f1 100644
--- a/main/pickup.c
+++ b/main/pickup.c
@@ -403,7 +403,7 @@
 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;
 }
diff --git a/main/rtp_engine.c b/main/rtp_engine.c
index 9915801..feb2de3 100644
--- a/main/rtp_engine.c
+++ b/main/rtp_engine.c
@@ -2096,7 +2096,7 @@
 	}
 	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);
diff --git a/main/sorcery.c b/main/sorcery.c
index d0b46c5..15ef77f 100644
--- a/main/sorcery.c
+++ b/main/sorcery.c
@@ -416,16 +416,11 @@
 	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 @@
 	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 @@
 		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;
 }
diff --git a/main/sounds_index.c b/main/sounds_index.c
index 8ca5967..c7f9f4d 100644
--- a/main/sounds_index.c
+++ b/main/sounds_index.c
@@ -322,7 +322,7 @@
 		return -1;
 	}
 
-	ast_register_atexit(sounds_cleanup);
+	ast_register_cleanup(sounds_cleanup);
 	return 0;
 }
 
diff --git a/main/stasis.c b/main/stasis.c
index dbb6e4c..c2d552e 100644
--- a/main/stasis.c
+++ b/main/stasis.c
@@ -1533,16 +1533,11 @@
 
 /*! @} */
 
-/*! \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 @@
 
 	/* 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;
diff --git a/main/stun.c b/main/stun.c
index e0a2559..f5bdc9a 100644
--- a/main/stun.c
+++ b/main/stun.c
@@ -516,5 +516,5 @@
 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);
 }
diff --git a/main/taskprocessor.c b/main/taskprocessor.c
index ad471a8..8a078f1 100644
--- a/main/taskprocessor.c
+++ b/main/taskprocessor.c
@@ -278,7 +278,7 @@
 
 	ast_cli_register_multiple(taskprocessor_clis, ARRAY_LEN(taskprocessor_clis));
 
-	ast_register_atexit(tps_shutdown);
+	ast_register_cleanup(tps_shutdown);
 
 	return 0;
 }
diff --git a/main/threadstorage.c b/main/threadstorage.c
index 349cb4e..4c46a0f 100644
--- a/main/threadstorage.c
+++ b/main/threadstorage.c
@@ -258,7 +258,7 @@
 {
 	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) */
diff --git a/main/timing.c b/main/timing.c
index 5318ded..ae8c3eb 100644
--- a/main/timing.c
+++ b/main/timing.c
@@ -289,7 +289,7 @@
 		return -1;
 	}
 
-	ast_register_atexit(timing_shutdown);
+	ast_register_cleanup(timing_shutdown);
 
 	return ast_cli_register_multiple(cli_timing, ARRAY_LEN(cli_timing));
 }
diff --git a/main/udptl.c b/main/udptl.c
index 89ea0a8..4974628 100644
--- a/main/udptl.c
+++ b/main/udptl.c
@@ -1403,5 +1403,5 @@
 
 	ast_cli_register_multiple(cli_udptl, ARRAY_LEN(cli_udptl));
 
-	ast_register_atexit(udptl_shutdown);
+	ast_register_cleanup(udptl_shutdown);
 }
diff --git a/main/utils.c b/main/utils.c
index 8305faa..6a2caf0 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -2606,7 +2606,7 @@
 	ast_cli_register_multiple(utils_cli, ARRAY_LEN(utils_cli));
 #endif
 #endif
-	ast_register_atexit(utils_shutdown);
+	ast_register_cleanup(utils_shutdown);
 	return 0;
 }
 
diff --git a/main/xmldoc.c b/main/xmldoc.c
index 0374aef..50ed16b 100644
--- a/main/xmldoc.c
+++ b/main/xmldoc.c
@@ -2959,7 +2959,7 @@
 
 	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 */
 

-- 
To view, visit https://gerrit.asterisk.org/1466
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6a67336050dea74327d79cdd6f7c7ea34d0b473e
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: certified/13.1
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>



More information about the asterisk-commits mailing list