From 9a69e4e83adb5d23a04a03fddfbef37f4850d0d0 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 17 May 2006 23:20:29 +0000 Subject: - Better log handling when things are fast and furious --- daemon/misc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'daemon/misc.c') diff --git a/daemon/misc.c b/daemon/misc.c index bb88d06..7b60422 100644 --- a/daemon/misc.c +++ b/daemon/misc.c @@ -32,6 +32,8 @@ extern int g_debuglevel; extern int g_daemonized; extern pthread_mutex_t g_mutex; +/* For printing out sane logs */ +static pthread_mutex_t g_log_mutex = PTHREAD_MUTEX_INITIALIZER; /* ----------------------------------------------------------------------- * Error Handling @@ -98,18 +100,26 @@ void ha_messagex(const ha_request_t* rq, int level, const char* msg, ...) { va_list ap; + pthread_mutex_lock (&g_log_mutex); + va_start(ap, msg); vmessage(rq, level, 0, msg, ap); va_end(ap); + + pthread_mutex_unlock (&g_log_mutex); } void ha_message(const ha_request_t* rq, int level, const char* msg, ...) { va_list ap; + pthread_mutex_lock (&g_log_mutex); + va_start(ap, msg); vmessage(rq, level, 1, msg, ap); va_end(ap); + + pthread_mutex_unlock (&g_log_mutex); } @@ -201,7 +211,7 @@ void ha_lock(pthread_mutex_t* mtx) if(r == EBUSY) { wait = 1; - ha_message(NULL, LOG_DEBUG, "thread will block: %d", pthread_self()); + ha_messagex(NULL, LOG_DEBUG, "thread will block: %d", pthread_self()); r = pthread_mutex_lock(mtx); } -- cgit v1.2.3