From: Richard Mudgett Date: Tue, 11 Dec 2012 00:34:46 +0000 (+0000) Subject: Cleanup dnsmgr on exit. X-Git-Tag: 11.3.0-rc1~3^2~91 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6368a140a03607f710801cf5e285232c2ec1e5b3;p=thirdparty%2Fasterisk.git Cleanup dnsmgr on exit. * Cleanup dnsmgr thread and CLI commands on exit. (issue ASTERISK-20649) Reported by: Corey Farrell Patches: dnsmgr-cleanup-1_8.patch (license #5909) patch uploaded by Corey Farrell dnsmgr-cleanup-10-11-trunk.patch (license #5909) patch uploaded by Corey Farrell Modified ........ Merged revisions 377704 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 377705 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@377706 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/main/dnsmgr.c b/main/dnsmgr.c index d4b9d94d2d..3d01a3157f 100644 --- a/main/dnsmgr.c +++ b/main/dnsmgr.c @@ -397,6 +397,26 @@ static struct ast_cli_entry cli_reload = AST_CLI_DEFINE(handle_cli_reload, "Relo static struct ast_cli_entry cli_refresh = AST_CLI_DEFINE(handle_cli_refresh, "Performs an immediate refresh"); static struct ast_cli_entry cli_status = AST_CLI_DEFINE(handle_cli_status, "Display the DNS manager status"); +static void dnsmgr_shutdown(void) +{ + ast_cli_unregister(&cli_reload); + ast_cli_unregister(&cli_status); + ast_cli_unregister(&cli_refresh); + + /* Destroy refresh thread. */ + ast_mutex_lock(&refresh_lock); + if (refresh_thread != AST_PTHREADT_NULL) { + /* wake up the thread so it will exit */ + pthread_cancel(refresh_thread); + pthread_kill(refresh_thread, SIGURG); + pthread_join(refresh_thread, NULL); + refresh_thread = AST_PTHREADT_NULL; + } + ast_mutex_unlock(&refresh_lock); + + ast_sched_context_destroy(sched); +} + int dnsmgr_init(void) { if (!(sched = ast_sched_context_create())) { @@ -406,6 +426,9 @@ int dnsmgr_init(void) ast_cli_register(&cli_reload); ast_cli_register(&cli_status); ast_cli_register(&cli_refresh); + + ast_register_atexit(dnsmgr_shutdown); + return do_reload(1); }