]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Avoid race with consolethread on shutdown (on parallel processors).
authorTilghman Lesher <tilghman@meg.abyt.es>
Fri, 23 Jul 2010 16:42:25 +0000 (16:42 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Fri, 23 Jul 2010 16:42:25 +0000 (16:42 +0000)
(closes issue #17080)
 Reported by: sybasesql
 Patches:
       20100721__issue17080.diff.txt uploaded by tilghman (license 14)
 Tested by: sybasesql

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@278981 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/asterisk.c

index 33aaaf2fcdf71a1462c70a43af72b7169e63a06b..c62447089a8cb441c4817b3623c611806504fe45 100644 (file)
@@ -1320,14 +1320,21 @@ static void quit_handler(int num, int nice, int safeshutdown, int restart)
                        ast_module_shutdown();
        }
        if (ast_opt_console || ast_opt_remote) {
-               if (getenv("HOME")) 
+               if (getenv("HOME")) {
                        snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
-               if (!ast_strlen_zero(filename))
+               }
+               if (!ast_strlen_zero(filename)) {
                        ast_el_write_history(filename);
-               if (el != NULL)
-                       el_end(el);
-               if (el_hist != NULL)
-                       history_end(el_hist);
+               }
+               if (consolethread == AST_PTHREADT_NULL || consolethread == pthread_self()) {
+                       /* Only end if we are the consolethread, otherwise there's a race with that thread. */
+                       if (el != NULL) {
+                               el_end(el);
+                       }
+                       if (el_hist != NULL) {
+                               history_end(el_hist);
+                       }
+               }
        }
        if (option_verbose)
                ast_verbose("Executing last minute cleanups\n");