[asterisk-commits] mjordan: branch 11 r376588 - in /branches/11: ./ include/asterisk/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Nov 22 17:58:12 CST 2012
Author: mjordan
Date: Thu Nov 22 17:58:08 2012
New Revision: 376588
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=376588
Log:
Re-initialize logmsgs mutex upon logger initialization to prevent lock errors
Similar to the patch that moved the fork earlier in the startup sequence to
prevent mutex errors in the recursive mutex surrounding the read/write thread
registration lock, this patch re-initializes the logmsgs mutex. Part of the
start up sequence before forking the process into the background includes
reading asterisk.conf; this has to occur prior to the call to daemon in order
to read startup parameters. When reading in a conf file, log statements can
be generated. Since this can't be avoided, the mutex instead is
re-initialized to ensure a reset of any thread tracking information.
This patch also includes some additional debugging to catch errors when
locking or unlocking the recursive mutex that surrounds locks when the
DEBUG_THREADS build option is enabled. DO_CRASH or THREAD_CRASH will
cause an abort() if a mutex error is detected.
(issue ASTERISK-19463)
Reported by: mjordan
Tesetd by: mjordan
........
Merged revisions 376586 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 376587 from http://svn.asterisk.org/svn/asterisk/branches/10
Modified:
branches/11/ (props changed)
branches/11/include/asterisk/lock.h
branches/11/main/lock.c
branches/11/main/logger.c
Propchange: branches/11/
------------------------------------------------------------------------------
Binary property 'branch-10-merged' - no diff available.
Modified: branches/11/include/asterisk/lock.h
URL: http://svnview.digium.com/svn/asterisk/branches/11/include/asterisk/lock.h?view=diff&rev=376588&r1=376587&r2=376588
==============================================================================
--- branches/11/include/asterisk/lock.h (original)
+++ branches/11/include/asterisk/lock.h Thu Nov 22 17:58:08 2012
@@ -428,12 +428,24 @@
static inline void ast_reentrancy_lock(struct ast_lock_track *lt)
{
- pthread_mutex_lock(<->reentr_mutex);
+ int res;
+ if ((res = pthread_mutex_lock(<->reentr_mutex))) {
+ fprintf(stderr, "ast_reentrancy_lock failed: '%s' (%d)\n", strerror(res), res);
+#if defined(DO_CRASH) || defined(THREAD_CRASH)
+ abort();
+#endif
+ }
}
static inline void ast_reentrancy_unlock(struct ast_lock_track *lt)
{
- pthread_mutex_unlock(<->reentr_mutex);
+ int res;
+ if ((res = pthread_mutex_unlock(<->reentr_mutex))) {
+ fprintf(stderr, "ast_reentrancy_unlock failed: '%s' (%d)\n", strerror(res), res);
+#if defined(DO_CRASH) || defined(THREAD_CRASH)
+ abort();
+#endif
+ }
}
static inline void ast_reentrancy_init(struct ast_lock_track **plt)
Modified: branches/11/main/lock.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/main/lock.c?view=diff&rev=376588&r1=376587&r2=376588
==============================================================================
--- branches/11/main/lock.c (original)
+++ branches/11/main/lock.c Thu Nov 22 17:58:08 2012
@@ -51,8 +51,8 @@
int res;
pthread_mutexattr_t attr;
+#ifdef DEBUG_THREADS
t->track = NULL;
-#ifdef DEBUG_THREADS
#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
if ((t->mutex) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
/*
Modified: branches/11/main/logger.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/main/logger.c?view=diff&rev=376588&r1=376587&r2=376588
==============================================================================
--- branches/11/main/logger.c (original)
+++ branches/11/main/logger.c Thu Nov 22 17:58:08 2012
@@ -1211,8 +1211,17 @@
/* auto rotate if sig SIGXFSZ comes a-knockin */
sigaction(SIGXFSZ, &handle_SIGXFSZ, NULL);
+ /* Re-initialize the logmsgs mutex. The recursive mutex can be accessed prior
+ * to Asterisk being forked into the background, which can cause the thread
+ * ID tracked by the underlying pthread mutex to be different than the ID of
+ * the thread that unlocks the mutex. Since init_logger is called after the
+ * fork, it is safe to initialize the mutex here for future accesses.
+ */
+ ast_mutex_destroy(&logmsgs.lock);
+ ast_mutex_init(&logmsgs.lock);
+ ast_cond_init(&logcond, NULL);
+
/* start logger thread */
- ast_cond_init(&logcond, NULL);
if (ast_pthread_create(&logthread, NULL, logger_thread, NULL) < 0) {
ast_cond_destroy(&logcond);
return -1;
More information about the asterisk-commits
mailing list