[Asterisk-code-review] core: Ensure that el end is always run when needed. (asterisk[master])

Joshua Colp asteriskteam at digium.com
Wed Nov 14 07:06:38 CST 2018


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/10616 )

Change subject: core: Ensure that el_end is always run when needed.
......................................................................

core: Ensure that el_end is always run when needed.

* Ignore console=yes configuration option in remote console processes.
* Use new flag to tell consolethread to run el_end and exit when needed.

ASTERISK-28158

Change-Id: I9e23b31d4211417ddc88c6bbfd83ea4c9f3e5438
---
M main/asterisk.c
M main/options.c
2 files changed, 17 insertions(+), 9 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
  George Joseph: Looks good to me, approved



diff --git a/main/asterisk.c b/main/asterisk.c
index 1d52567..a751c3b 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -392,6 +392,7 @@
 	 unsigned int need_reload:1;
 	 unsigned int need_quit:1;
 	 unsigned int need_quit_handler:1;
+	 unsigned int need_el_end:1;
 } sig_flags;
 
 #if !defined(LOW_MEMORY)
@@ -2018,10 +2019,9 @@
 			if (el_hist != NULL) {
 				history_end(el_hist);
 			}
-		} else if (mon_sig_flags == pthread_self()) {
-			if (consolethread != AST_PTHREADT_NULL) {
-				pthread_kill(consolethread, SIGURG);
-			}
+		} else {
+			sig_flags.need_el_end = 1;
+			pthread_kill(consolethread, SIGURG);
 		}
 	}
 	active_channels = ast_active_channels();
@@ -2638,7 +2638,7 @@
 		}
 		res = ast_poll(fds, max, -1);
 		if (res < 0) {
-			if (sig_flags.need_quit || sig_flags.need_quit_handler) {
+			if (sig_flags.need_quit || sig_flags.need_quit_handler || sig_flags.need_el_end) {
 				break;
 			}
 			if (errno == EINTR) {
@@ -3166,7 +3166,7 @@
 		sprintf(tmp, "%s%s", prefix, data);
 		if (write(ast_consock, tmp, strlen(tmp) + 1) < 0) {
 			ast_log(LOG_ERROR, "write() failed: %s\n", strerror(errno));
-			if (sig_flags.need_quit || sig_flags.need_quit_handler) {
+			if (sig_flags.need_quit || sig_flags.need_quit_handler || sig_flags.need_el_end) {
 				return;
 			}
 		}
@@ -3198,7 +3198,7 @@
 			char buffer[512] = "", *curline = buffer, *nextline;
 			int not_written = 1;
 
-			if (sig_flags.need_quit || sig_flags.need_quit_handler) {
+			if (sig_flags.need_quit || sig_flags.need_quit_handler || sig_flags.need_el_end) {
 				break;
 			}
 
@@ -3258,7 +3258,7 @@
 	for (;;) {
 		ebuf = (char *)el_gets(el, &num);
 
-		if (sig_flags.need_quit || sig_flags.need_quit_handler) {
+		if (sig_flags.need_quit || sig_flags.need_quit_handler || sig_flags.need_el_end) {
 			break;
 		}
 
@@ -4201,6 +4201,12 @@
 		el_set(el, EL_GETCFN, ast_el_read_char);
 
 		for (;;) {
+			if (sig_flags.need_el_end) {
+				el_end(el);
+
+				return;
+			}
+
 			if (sig_flags.need_quit || sig_flags.need_quit_handler) {
 				quit_handler(0, SHUTDOWN_FAST, 0);
 				break;
diff --git a/main/options.c b/main/options.c
index 4f9b3dc..ea97a6a 100644
--- a/main/options.c
+++ b/main/options.c
@@ -322,7 +322,9 @@
 			ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_QUIET);
 		/* Run as console (-c at startup, implies nofork) */
 		} else if (!strcasecmp(v->name, "console")) {
-			ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_CONSOLE);
+			if (!ast_opt_remote) {
+				ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_CONSOLE);
+			}
 		/* Run with high priority if the O/S permits (-p at startup) */
 		} else if (!strcasecmp(v->name, "highpriority")) {
 			ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_HIGH_PRIORITY);

-- 
To view, visit https://gerrit.asterisk.org/10616
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I9e23b31d4211417ddc88c6bbfd83ea4c9f3e5438
Gerrit-Change-Number: 10616
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2 (1000185)
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181114/0c617923/attachment.html>


More information about the asterisk-code-review mailing list