]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix logger deadlock on Asterisk shutdown.
authorRichard Mudgett <rmudgett@digium.com>
Fri, 30 Mar 2012 21:29:43 +0000 (21:29 +0000)
committerRichard Mudgett <rmudgett@digium.com>
Fri, 30 Mar 2012 21:29:43 +0000 (21:29 +0000)
The logger_thread() had an exit path that failed to release the logmsgs
list lock.

* Make logger_thread() exit path unlock the logmsgs list lock.

* Made ast_log() not queue any messages to the logmsgs list if the
close_logger_thread flag is set.

(issue ASTERISK-19463)
Reported by: Matt Jordan
........

Merged revisions 360933 from http://svn.asterisk.org/svn/asterisk/branches/1.8

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

main/logger.c

index 4d88aa688987b419bba98de0caa8f7e48d57def2..91d716ce0c499a66ab9356def18bfb29f79a2e5d 100644 (file)
@@ -1053,6 +1053,7 @@ static void *logger_thread(void *data)
                AST_LIST_LOCK(&logmsgs);
                if (AST_LIST_EMPTY(&logmsgs)) {
                        if (close_logger_thread) {
+                               AST_LIST_UNLOCK(&logmsgs);
                                break;
                        } else {
                                ast_cond_wait(&logcond, &logmsgs.lock);
@@ -1170,8 +1171,6 @@ void close_logger(void)
        closelog(); /* syslog */
 
        AST_RWLIST_UNLOCK(&logchannels);
-
-       return;
 }
 
 /*!
@@ -1258,15 +1257,18 @@ void ast_log(int level, const char *file, int line, const char *function, const
        /* If the logger thread is active, append it to the tail end of the list - otherwise skip that step */
        if (logthread != AST_PTHREADT_NULL) {
                AST_LIST_LOCK(&logmsgs);
-               AST_LIST_INSERT_TAIL(&logmsgs, logmsg, list);
-               ast_cond_signal(&logcond);
+               if (close_logger_thread) {
+                       /* Logger is either closing or closed.  We cannot log this message. */
+                       ast_free(logmsg);
+               } else {
+                       AST_LIST_INSERT_TAIL(&logmsgs, logmsg, list);
+                       ast_cond_signal(&logcond);
+               }
                AST_LIST_UNLOCK(&logmsgs);
        } else {
                logger_print_normal(logmsg);
                ast_free(logmsg);
        }
-
-       return;
 }
 
 #ifdef HAVE_BKTR