From 7d06282b9ecb99aa68e30b3133a527df158dc7c3 Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Sun, 5 Oct 2014 00:41:16 +0000 Subject: [PATCH] Release AMI connections on shutdown. ASTERISK-24378 #close Reported by: Corey Farrell Review: https://reviewboard.asterisk.org/r/4037/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@424578 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/manager.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main/manager.c b/main/manager.c index acaff116f1..90163b9516 100644 --- a/main/manager.c +++ b/main/manager.c @@ -1028,6 +1028,9 @@ static char global_realm[MAXHOSTNAMELEN]; /*!< Default realm */ static int unauth_sessions = 0; static struct ast_event_sub *acl_change_event_subscription; +/*! \brief Fake event class used to end sessions at shutdown */ +#define EVENT_FLAG_SHUTDOWN -1 + /*! \brief * Descriptor for a manager session, either on the AMI socket or over HTTP. * @@ -4875,6 +4878,10 @@ static int process_events(struct mansession *s) struct eventqent *eqe = s->session->last_ev; while ((eqe = advance_event(eqe))) { + if (eqe->category == EVENT_FLAG_SHUTDOWN) { + ast_debug(3, "Received CloseSession event\n"); + ret = -1; + } if (!ret && s->session->authenticated && (s->session->readperm & eqe->category) == eqe->category && (s->session->send_events & eqe->category) == eqe->category) { @@ -5793,7 +5800,7 @@ int __ast_manager_event_multichan(int category, const char *event, int chancount ao2_iterator_destroy(&i); } - if (!AST_RWLIST_EMPTY(&manager_hooks)) { + if (category != EVENT_FLAG_SHUTDOWN && !AST_RWLIST_EMPTY(&manager_hooks)) { AST_RWLIST_RDLOCK(&manager_hooks); AST_RWLIST_TRAVERSE(&manager_hooks, hook, list) { hook->helper(category, event, ast_str_buffer(buf)); @@ -7503,6 +7510,9 @@ static void manager_shutdown(void) { struct ast_manager_user *user; + /* This event is not actually transmitted, but causes all TCP sessions to be closed */ + manager_event(EVENT_FLAG_SHUTDOWN, "CloseSession", "CloseSession: true\r\n"); + ast_manager_unregister("Ping"); ast_manager_unregister("Events"); ast_manager_unregister("Logoff");