From aa5ac809192d3c4b900dc550845ceefb7092ee7a Mon Sep 17 00:00:00 2001 From: Matthew Jordan Date: Tue, 2 Oct 2012 21:23:01 +0000 Subject: [PATCH] Ensure Shutdown AMI event is still fired during Asterisk shutdown Richard pointed out that having the manager dispose of itself gracefully during shutdown meant that the Shutdown event will no longer get fired. This patch moves the AMI event just prior to running the atexit callbacks. ........ Merged revisions 374230 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 374231 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@374248 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/asterisk.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/main/asterisk.c b/main/asterisk.c index 6a04cf3a1b..382b558d0d 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -1783,11 +1783,10 @@ static void really_quit(int num, shutdown_nice_t niceness, int restart) } } } - ast_verb(0, "Executing last minute cleanups\n"); - ast_run_atexits(); - /* Called on exit */ - ast_verb(0, "Asterisk %s ending (%d).\n", ast_active_channels() ? "uncleanly" : "cleanly", num); - ast_debug(1, "Asterisk ending (%d).\n", num); + /* The manager event for shutdown must happen prior to ast_run_atexits, as + * the manager interface will dispose of its sessions as part of its + * shutdown. + */ /*** DOCUMENTATION Raised when Asterisk is shutdown or restarted. @@ -1807,7 +1806,16 @@ static void really_quit(int num, shutdown_nice_t niceness, int restart) ***/ - manager_event(EVENT_FLAG_SYSTEM, "Shutdown", "Shutdown: %s\r\nRestart: %s\r\n", ast_active_channels() ? "Uncleanly" : "Cleanly", restart ? "True" : "False"); + manager_event(EVENT_FLAG_SYSTEM, "Shutdown", "Shutdown: %s\r\n" + "Restart: %s\r\n", + ast_active_channels() ? "Uncleanly" : "Cleanly", + restart ? "True" : "False"); + + ast_verb(0, "Executing last minute cleanups\n"); + ast_run_atexits(); + /* Called on exit */ + ast_verb(0, "Asterisk %s ending (%d).\n", ast_active_channels() ? "uncleanly" : "cleanly", num); + ast_debug(1, "Asterisk ending (%d).\n", num); if (ast_socket > -1) { pthread_cancel(lthread); close(ast_socket);