summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAutomerge script <automerge@asterisk.org>2012-11-23 00:20:55 +0000
committerAutomerge script <automerge@asterisk.org>2012-11-23 00:20:55 +0000
commit37ae4ad43f801be2f573084365beb756be2db7dc (patch)
treee2bda754d89b6d789db746fa364f9f581b14f7bc
parentd16d0200d29e1b99693a8c04ae6d1d5ede6d2823 (diff)
Merged revisions 376589 via svnmerge from
file:///srv/subversion/repos/asterisk/trunk ................ r376589 | mjordan | 2012-11-22 18:02:23 -0600 (Thu, 22 Nov 2012) | 29 lines 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 ........ Merged revisions 376588 from http://svn.asterisk.org/svn/asterisk/branches/11 ................ git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376596 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--include/asterisk/lock.h16
-rw-r--r--main/lock.c2
-rw-r--r--main/logger.c11
3 files changed, 25 insertions, 4 deletions
diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h
index 573fc0c00..cffd1a9ac 100644
--- a/include/asterisk/lock.h
+++ b/include/asterisk/lock.h
@@ -428,12 +428,24 @@ int ast_find_lock_info(void *lock_addr, char *filename, size_t filename_size, in
static inline void ast_reentrancy_lock(struct ast_lock_track *lt)
{
- pthread_mutex_lock(&lt->reentr_mutex);
+ int res;
+ if ((res = pthread_mutex_lock(&lt->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(&lt->reentr_mutex);
+ int res;
+ if ((res = pthread_mutex_unlock(&lt->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)
diff --git a/main/lock.c b/main/lock.c
index eef5d8621..3c9fbd4db 100644
--- a/main/lock.c
+++ b/main/lock.c
@@ -51,8 +51,8 @@ int __ast_pthread_mutex_init(int tracking, const char *filename, int lineno, con
int res;
pthread_mutexattr_t attr;
- t->track = NULL;
#ifdef DEBUG_THREADS
+ t->track = NULL;
#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) && defined(CAN_COMPARE_MUTEX_TO_INIT_VALUE)
if ((t->mutex) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) {
/*
diff --git a/main/logger.c b/main/logger.c
index 945a453d0..aad1c9869 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -1226,8 +1226,17 @@ int init_logger(void)
/* auto rotate if sig SIGXFSZ comes a-knockin */
sigaction(SIGXFSZ, &handle_SIGXFSZ, NULL);
- /* start logger thread */
+ /* 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 */
if (ast_pthread_create(&logthread, NULL, logger_thread, NULL) < 0) {
ast_cond_destroy(&logcond);
return -1;