From c12a800aeac341c0fdeba12a7ccb0c69c97c8d3b Mon Sep 17 00:00:00 2001
From: Richard Mudgett <rmudgett@digium.com>
Date: Mon, 22 Dec 2014 20:31:18 +0000
Subject: [PATCH] queue_log: Post QUEUESTART entry when Asterisk fully boots.

The QUEUESTART log entry has historically acted like a fully booted event
for the queue_log file.  When the QUEUESTART entry was posted to the log
was broken by the change made by ASTERISK-15863.

* Made post the QUEUESTART queue_log entry when Asterisk fully boots.
This restores the intent of that log entry and happens after realtime has
had a chance to load.

AST-1444 #close
Reported by: Denis Martinez

Review: https://reviewboard.asterisk.org/r/4282/
........

Merged revisions 430009 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: https://origsvn.digium.com/svn/asterisk/certified/branches/11.6@430029 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 include/asterisk/_private.h |  1 +
 main/asterisk.c             |  2 ++
 main/logger.c               | 42 +++++++++++++++++++++++--------------
 3 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/include/asterisk/_private.h b/include/asterisk/_private.h
index a7ed68136f..1bc24337f0 100644
--- a/include/asterisk/_private.h
+++ b/include/asterisk/_private.h
@@ -19,6 +19,7 @@ int load_modules(unsigned int);		/*!< Provided by loader.c */
 int load_pbx(void);			/*!< Provided by pbx.c */
 int init_logger(void);			/*!< Provided by logger.c */
 void close_logger(void);		/*!< Provided by logger.c */
+void logger_queue_start(void);		/*!< Provided by logger.c */
 void clean_time_zones(void);			/*!< Provided by localtime.c */
 int init_framer(void);			/*!< Provided by frame.c */
 int ast_term_init(void);		/*!< Provided by term.c */
diff --git a/main/asterisk.c b/main/asterisk.c
index 60b6f34c7c..eac6b8c3d3 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -4357,6 +4357,8 @@ int main(int argc, char *argv[])
 
 	run_startup_commands();
 
+	logger_queue_start();
+
 	if (ast_opt_console) {
 		/* Console stuff now... */
 		/* Register our quit function */
diff --git a/main/logger.c b/main/logger.c
index 34577aa171..a70ac6572c 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -235,8 +235,6 @@ AST_THREADSTORAGE(verbose_buf);
 AST_THREADSTORAGE(log_buf);
 #define LOG_BUF_INIT_SIZE       256
 
-static void logger_queue_init(void);
-
 static void make_components(struct logchannel *chan)
 {
 	char *w;
@@ -539,20 +537,8 @@ void ast_queue_log(const char *queuename, const char *callid, const char *agent,
 		return;
 	}
 	if (!queuelog_init) {
-		AST_RWLIST_WRLOCK(&logchannels);
-		if (!queuelog_init) {
-			/*
-			 * We have delayed initializing the queue logging system so
-			 * preloaded realtime modules can get up.  We must initialize
-			 * now since someone is trying to log something.
-			 */
-			logger_queue_init();
-			queuelog_init = 1;
-			AST_RWLIST_UNLOCK(&logchannels);
-			ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", "");
-		} else {
-			AST_RWLIST_UNLOCK(&logchannels);
-		}
+		/* We must initialize now since someone is trying to log something. */
+		logger_queue_start();
 	}
 
 	if (ast_check_realtime("queue_log")) {
@@ -1223,6 +1209,30 @@ static void logger_queue_init(void)
 	}
 }
 
+/*!
+ * \brief Start the ast_queue_log() logger.
+ *
+ * \note Called when the system is fully booted after startup
+ * so preloaded realtime modules can get up.
+ *
+ * \return Nothing
+ */
+void logger_queue_start(void)
+{
+	/* Must not be called before the logger is initialized. */
+	ast_assert(logger_initialized);
+
+	AST_RWLIST_WRLOCK(&logchannels);
+	if (!queuelog_init) {
+		logger_queue_init();
+		queuelog_init = 1;
+		AST_RWLIST_UNLOCK(&logchannels);
+		ast_queue_log("NONE", "NONE", "NONE", "QUEUESTART", "%s", "");
+	} else {
+		AST_RWLIST_UNLOCK(&logchannels);
+	}
+}
+
 int init_logger(void)
 {
 	/* auto rotate if sig SIGXFSZ comes a-knockin */
-- 
GitLab