From 68a9f7aca14dbdade7e53c22f0889228d06c24e6 Mon Sep 17 00:00:00 2001
From: Joshua Colp <jcolp@digium.com>
Date: Mon, 27 Apr 2009 15:18:47 +0000
Subject: [PATCH] Fix a bug where we tried to send events out when no sessions
 container was present.

This commit stops a warning message (user_data is NULL) from getting output when
manager events get sent before manager is initialized. This happens because manager
is initialized *after* modules are loaded and the act of loading modules triggers
manager events.

(issue #14974)
Reported by: pj


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190586 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 main/manager.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/main/manager.c b/main/manager.c
index 09e3c764c9..a43f5518b0 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -3511,7 +3511,6 @@ int __manager_event(int category, const char *event,
 	va_list ap;
 	struct timeval now;
 	struct ast_str *buf;
-	struct ao2_iterator i;
 
 	if (!(buf = ast_str_thread_get(&manager_event_buf, MANAGER_EVENT_BUF_INITSIZE))) {
 		return -1;
@@ -3546,21 +3545,24 @@ int __manager_event(int category, const char *event,
 	append_event(ast_str_buffer(buf), category);
 
 	/* Wake up any sleeping sessions */
-	i = ao2_iterator_init(sessions, 0);
-	while ((session = ao2_iterator_next(&i))) {
-		ao2_lock(session);
-		if (session->waiting_thread != AST_PTHREADT_NULL) {
-			pthread_kill(session->waiting_thread, SIGURG);
-		} else {
-			/* We have an event to process, but the mansession is
-			 * not waiting for it. We still need to indicate that there
-			 * is an event waiting so that get_input processes the pending
-			 * event instead of polling.
-			 */
-			session->pending_event = 1;
+	if (sessions) {
+		struct ao2_iterator i;
+		i = ao2_iterator_init(sessions, 0);
+		while ((session = ao2_iterator_next(&i))) {
+			ao2_lock(session);
+			if (session->waiting_thread != AST_PTHREADT_NULL) {
+				pthread_kill(session->waiting_thread, SIGURG);
+			} else {
+				/* We have an event to process, but the mansession is
+				 * not waiting for it. We still need to indicate that there
+				 * is an event waiting so that get_input processes the pending
+				 * event instead of polling.
+				 */
+				session->pending_event = 1;
+			}
+			ao2_unlock(session);
+			unref_mansession(session);
 		}
-		ao2_unlock(session);
-		unref_mansession(session);
 	}
 
 	AST_RWLIST_RDLOCK(&manager_hooks);
-- 
GitLab