From: Corey Farrell Date: Thu, 26 Mar 2015 22:16:31 +0000 (+0000) Subject: Replace most uses of ast_register_atexit with ast_register_cleanup. X-Git-Tag: 11.18.0-rc1~94 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aad1694fd49734e0a0fe4c5be442013a86735824;p=thirdparty%2Fasterisk.git 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/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@433495 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/include/asterisk.h b/include/asterisk.h index dc1e521bc6..0ba913c63b 100644 --- a/include/asterisk.h +++ b/include/asterisk.h @@ -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)); diff --git a/main/aoc.c b/main/aoc.c index 1e21dd8207..a9e6d7bedb 100644 --- a/main/aoc.c +++ b/main/aoc.c @@ -1611,6 +1611,6 @@ static void aoc_shutdown(void) } int ast_aoc_cli_init(void) { - 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 55d35e2387..ca85363516 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -4374,7 +4374,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(); diff --git a/main/astfd.c b/main/astfd.c index b2dfd12ee6..bb658635ac 100644 --- a/main/astfd.c +++ b/main/astfd.c @@ -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); } diff --git a/main/astmm.c b/main/astmm.c index 5ef5799b86..04feae43ed 100644 --- a/main/astmm.c +++ b/main/astmm.c @@ -1429,7 +1429,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) */ diff --git a/main/astobj2.c b/main/astobj2.c index 6aff3b4ced..3128328dbb 100644 --- a/main/astobj2.c +++ b/main/astobj2.c @@ -1748,7 +1748,7 @@ int astobj2_init(void) ast_cli_register_multiple(cli_astobj2, ARRAY_LEN(cli_astobj2)); #endif - ast_register_atexit(astobj2_cleanup); + ast_register_cleanup(astobj2_cleanup); return 0; } diff --git a/main/ccss.c b/main/ccss.c index feee7cc8f4..7203889afe 100644 --- a/main/ccss.c +++ b/main/ccss.c @@ -4583,7 +4583,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; } diff --git a/main/cel.c b/main/cel.c index 83a1b16216..ca7186694c 100644 --- a/main/cel.c +++ b/main/cel.c @@ -892,7 +892,7 @@ int ast_cel_engine_init(void) return -1; } - ast_register_atexit(ast_cel_engine_term); + ast_register_cleanup(ast_cel_engine_term); return 0; } diff --git a/main/channel.c b/main/channel.c index c89cd725e4..0d640755ad 100644 --- a/main/channel.c +++ b/main/channel.c @@ -8666,7 +8666,7 @@ void ast_channels_init(void) ast_plc_reload(); - ast_register_atexit(channels_shutdown); + ast_register_cleanup(channels_shutdown); } /*! \brief Print call group and pickup group ---*/ diff --git a/main/cli.c b/main/cli.c index 4066224913..535c7fca94 100644 --- a/main/cli.c +++ b/main/cli.c @@ -2000,7 +2000,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); } /*! diff --git a/main/config.c b/main/config.c index 8f886e0792..c49f82c977 100644 --- a/main/config.c +++ b/main/config.c @@ -3368,7 +3368,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; } diff --git a/main/data.c b/main/data.c index e17b80a4b8..8b3846b2e1 100644 --- a/main/data.c +++ b/main/data.c @@ -3343,7 +3343,7 @@ int ast_data_init(void) 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 3d01a3157f..352d6381b0 100644 --- a/main/dnsmgr.c +++ b/main/dnsmgr.c @@ -427,7 +427,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); } diff --git a/main/event.c b/main/event.c index 317a151bea..4b2844be2c 100644 --- a/main/event.c +++ b/main/event.c @@ -1882,7 +1882,7 @@ int ast_event_init(void) ast_cli_register_multiple(event_cli, ARRAY_LEN(event_cli)); - ast_register_atexit(event_shutdown); + ast_register_cleanup(event_shutdown); return 0; diff --git a/main/features.c b/main/features.c index 7473e20f3d..82b7b2fe9b 100644 --- a/main/features.c +++ b/main/features.c @@ -9108,7 +9108,7 @@ int ast_features_init(void) res |= AST_TEST_REGISTER(features_test); #endif /* defined(TEST_FRAMEWORK) */ - ast_register_atexit(features_shutdown); + ast_register_cleanup(features_shutdown); return res; } diff --git a/main/file.c b/main/file.c index 97584a5337..436aae9124 100644 --- a/main/file.c +++ b/main/file.c @@ -1594,6 +1594,6 @@ static void file_shutdown(void) int ast_file_init(void) { 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 681d1a4344..e3c5bc5065 100644 --- a/main/format.c +++ b/main/format.c @@ -1113,7 +1113,7 @@ int ast_format_list_init(void) goto init_list_cleanup; } - ast_register_atexit(format_list_shutdown); + ast_register_cleanup(format_list_shutdown); return 0; init_list_cleanup: diff --git a/main/http.c b/main/http.c index c9704ca74b..533397be02 100644 --- a/main/http.c +++ b/main/http.c @@ -1312,7 +1312,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); } diff --git a/main/image.c b/main/image.c index 08620d734c..9bd47ae1b1 100644 --- a/main/image.c +++ b/main/image.c @@ -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; } diff --git a/main/indications.c b/main/indications.c index 750198dc7b..967cae98cf 100644 --- a/main/indications.c +++ b/main/indications.c @@ -1184,7 +1184,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; } diff --git a/main/manager.c b/main/manager.c index 7873e11a91..a979e3d7e3 100644 --- a/main/manager.c +++ b/main/manager.c @@ -7635,7 +7635,7 @@ static int __init_manager(int reload, int by_external_config) struct ao2_container *temp_event_docs; #endif - ast_register_atexit(manager_shutdown); + ast_register_cleanup(manager_shutdown); /* Register default actions */ ast_manager_register_xml_core("Ping", 0, action_ping); diff --git a/main/message.c b/main/message.c index bc4c0a38f0..a3a86b3808 100644 --- a/main/message.c +++ b/main/message.c @@ -1379,7 +1379,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; } diff --git a/main/named_acl.c b/main/named_acl.c index 9929ee12ce..6f712f7cdc 100644 --- a/main/named_acl.c +++ b/main/named_acl.c @@ -567,7 +567,7 @@ int ast_named_acl_init() { ast_cli_register_multiple(cli_named_acl, ARRAY_LEN(cli_named_acl)); - ast_register_atexit(named_acl_cleanup); + ast_register_cleanup(named_acl_cleanup); if (aco_info_init(&cfg_info)) { return 0; diff --git a/main/pbx.c b/main/pbx.c index 783716f8e2..f2c328fbd0 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -12054,7 +12054,7 @@ int load_pbx(void) { int x; - ast_register_atexit(unload_pbx); + ast_register_cleanup(unload_pbx); /* Initialize the PBX */ ast_verb(1, "Asterisk PBX Core Initializing\n"); @@ -12480,7 +12480,7 @@ int ast_pbx_init(void) hintdevices = ao2_container_alloc(HASH_EXTENHINT_SIZE, hintdevice_hash_cb, hintdevice_cmp_multiple); statecbs = ao2_container_alloc(1, NULL, statecbs_cmp); - ast_register_atexit(pbx_shutdown); + ast_register_cleanup(pbx_shutdown); return (hints && hintdevices && statecbs) ? 0 : -1; } diff --git a/main/stun.c b/main/stun.c index e0a25594f6..f5bdc9ad4d 100644 --- a/main/stun.c +++ b/main/stun.c @@ -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); } diff --git a/main/taskprocessor.c b/main/taskprocessor.c index ad2e15c3ca..60fc3229c1 100644 --- a/main/taskprocessor.c +++ b/main/taskprocessor.c @@ -145,7 +145,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; } diff --git a/main/test.c b/main/test.c index 3770ecf70e..e1925f7f5e 100644 --- a/main/test.c +++ b/main/test.c @@ -943,7 +943,7 @@ int ast_test_init() #ifdef TEST_FRAMEWORK /* Register cli commands */ ast_cli_register_multiple(test_cli, ARRAY_LEN(test_cli)); - ast_register_atexit(test_shutdown); + ast_register_cleanup(test_shutdown); #endif return 0; diff --git a/main/threadstorage.c b/main/threadstorage.c index 349cb4ecdf..4c46a0f585 100644 --- a/main/threadstorage.c +++ b/main/threadstorage.c @@ -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) */ diff --git a/main/timing.c b/main/timing.c index 84bff081bd..335c269b1d 100644 --- a/main/timing.c +++ b/main/timing.c @@ -313,7 +313,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)); } diff --git a/main/translate.c b/main/translate.c index c14ad019c3..d12925709c 100644 --- a/main/translate.c +++ b/main/translate.c @@ -1420,6 +1420,6 @@ int ast_translate_init(void) ast_rwlock_init(&tablelock); res = matrix_resize(1); res |= ast_cli_register_multiple(cli_translate, ARRAY_LEN(cli_translate)); - ast_register_atexit(translate_shutdown); + ast_register_cleanup(translate_shutdown); return res; } diff --git a/main/udptl.c b/main/udptl.c index ef74c8b5ce..b7abb17e14 100644 --- a/main/udptl.c +++ b/main/udptl.c @@ -1524,5 +1524,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); } diff --git a/main/utils.c b/main/utils.c index dedb6740ff..deb6d7e602 100644 --- a/main/utils.c +++ b/main/utils.c @@ -2285,7 +2285,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; } diff --git a/main/xmldoc.c b/main/xmldoc.c index 4689c40f86..fa471e9fa6 100644 --- a/main/xmldoc.c +++ b/main/xmldoc.c @@ -2396,7 +2396,7 @@ int ast_xmldoc_load_documentation(void) ast_xml_init(); /* 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 */