From 2301580ba83c32002b50cfc06b4d8427e7c6ce19 Mon Sep 17 00:00:00 2001 From: Corey Farrell <git@cfware.com> Date: Sun, 11 Nov 2018 08:34:53 -0500 Subject: [PATCH] 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 --- main/asterisk.c | 22 ++++++++++++++-------- main/options.c | 4 +++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/main/asterisk.c b/main/asterisk.c index b4f4e11ca3..174f9f7bf5 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -391,6 +391,7 @@ static struct { 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) @@ -2136,10 +2137,9 @@ static void really_quit(int num, shutdown_nice_t niceness, int restart) 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(); @@ -2773,7 +2773,7 @@ static int ast_el_read_char(EditLine *editline, CHAR_T_LIBEDIT *cp) } 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) { @@ -3316,7 +3316,7 @@ static void ast_remotecontrol(char *data) 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; } } @@ -3348,7 +3348,7 @@ static void ast_remotecontrol(char *data) 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; } @@ -3408,7 +3408,7 @@ static void ast_remotecontrol(char *data) 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; } @@ -4341,6 +4341,12 @@ static void asterisk_daemon(int isroot, const char *runuser, const char *rungrou 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 a79bdf6b2d..b4b7c8ca93 100644 --- a/main/options.c +++ b/main/options.c @@ -314,7 +314,9 @@ void load_asterisk_conf(void) 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); -- GitLab