summaryrefslogtreecommitdiff
path: root/sysdep/unix/log.c
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2014-02-07 13:09:55 +0100
committerOndrej Zajicek <santiago@crfreenet.org>2014-02-07 13:09:55 +0100
commit4e398e34bf140baf73fe8dceaf81078fb343f65a (patch)
treecef4e19194b5be76f62fb80bb9aaf9e10944159a /sysdep/unix/log.c
parent9ae0f4b78c5e3619ee19969c052c863bf96be6d9 (diff)
Workaround thread-unsafeness of cli_echo().
Diffstat (limited to 'sysdep/unix/log.c')
-rw-r--r--sysdep/unix/log.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c
index 0f4c06e9..66a5581c 100644
--- a/sysdep/unix/log.c
+++ b/sysdep/unix/log.c
@@ -39,14 +39,21 @@ static const int rate_limit_count = 5;
#ifdef USE_PTHREADS
#include <pthread.h>
+
static pthread_mutex_t log_mutex;
static inline void log_lock(void) { pthread_mutex_lock(&log_mutex); }
static inline void log_unlock(void) { pthread_mutex_unlock(&log_mutex); }
+static pthread_t main_thread;
+void main_thread_init(void) { main_thread = pthread_self(); }
+static int main_thread_self(void) { return pthread_equal(pthread_self(), main_thread); }
+
#else
static inline void log_lock(void) { }
static inline void log_unlock(void) { }
+void main_thread_init(void) { }
+static int main_thread_self(void) { return 1; }
#endif
@@ -128,8 +135,9 @@ log_commit(int class, buffer *buf)
}
log_unlock();
- /* FIXME: cli_echo is not thread-safe */
- cli_echo(class, buf->start);
+ /* cli_echo is not thread-safe, so call it just from the main thread */
+ if (main_thread_self())
+ cli_echo(class, buf->start);
buf->pos = buf->start;
}