diff options
author | jpeeler <jpeeler@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-10-08 02:35:29 +0000 |
---|---|---|
committer | jpeeler <jpeeler@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-10-08 02:35:29 +0000 |
commit | 8dc2231e144c23ea0b98e1c817194f8569c04147 (patch) | |
tree | 7fd7dda1b86475f4ef532e9371708a3e4ee241f8 | |
parent | 2f5a43b512c0cb9b79fb461f01e38e35af191009 (diff) |
Ensure editline cleanup occurs when Ctrl-C is pressed at control console.
A recent change was made to avoid a race condition on shutdown which only called
the end functions from the console thread. However, when pressing Ctrl-C the
quit handler is called from the signal handler thread.
(closes issue #17698)
Reported by: jmls
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@290862 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r-- | main/asterisk.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/main/asterisk.c b/main/asterisk.c index a5fd88a05..754ae1a1d 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -245,6 +245,7 @@ static char *_argv[256]; static int shuttingdown; static int restartnow; static pthread_t consolethread = AST_PTHREADT_NULL; +static pthread_t mon_sig_flags; static char randompool[256]; @@ -1321,14 +1322,15 @@ static void quit_handler(int num, int nice, int safeshutdown, int restart) ast_module_shutdown(); } if (ast_opt_console || ast_opt_remote) { + pthread_t thisthread = pthread_self(); if (getenv("HOME")) { snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME")); } if (!ast_strlen_zero(filename)) { ast_el_write_history(filename); } - if (consolethread == AST_PTHREADT_NULL || consolethread == pthread_self()) { - /* Only end if we are the consolethread, otherwise there's a race with that thread. */ + if (consolethread == AST_PTHREADT_NULL || consolethread == thisthread || mon_sig_flags == thisthread) { + /* Only end if we are the consolethread or signal handler, otherwise there's a race with that thread. */ if (el != NULL) { el_end(el); } @@ -3290,11 +3292,10 @@ int main(int argc, char *argv[]) /* Register our quit function */ char title[256]; pthread_attr_t attr; - pthread_t dont_care; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - ast_pthread_create(&dont_care, &attr, monitor_sig_flags, NULL); + ast_pthread_create(&mon_sig_flags, &attr, monitor_sig_flags, NULL); pthread_attr_destroy(&attr); set_icon("Asterisk"); |