aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-08-28 20:40:26 +0200
committerMax Kellermann <max@duempel.org>2008-08-28 20:40:26 +0200
commit7858081eda955918f9eaae937ed077b1c65ebbbe (patch)
tree2c5bebae120584ddef803cdd9110b93a0cb32fdb
parent5c26e732265c4d50cff5f99a23eac8a3054d5384 (diff)
downloadmpd-7858081eda955918f9eaae937ed077b1c65ebbbe.tar.gz
mpd-7858081eda955918f9eaae937ed077b1c65ebbbe.tar.xz
mpd-7858081eda955918f9eaae937ed077b1c65ebbbe.zip
log.c: thread-safety for warning log
I'm really no fan of the warning log, it's too complex for how little it gets used; but fixing it is another problem.
Diffstat (limited to '')
-rw-r--r--src/log.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/log.c b/src/log.c
index 8a2d48410..e74654c3e 100644
--- a/src/log.c
+++ b/src/log.c
@@ -29,6 +29,7 @@ static unsigned int logLevel = LOG_LEVEL_LOW;
static int warningFlushed;
static int stdout_mode = 1;
static char *warningBuffer;
+static pthread_mutex_t warning_buffer_lock = PTHREAD_MUTEX_INITIALIZER;
static int out_fd = -1;
static int err_fd = -1;
static const char *out_filename;
@@ -80,7 +81,10 @@ static void do_log(FILE *fp, const char *fmt, va_list args)
void flushWarningLog(void)
{
- char *s = warningBuffer;
+ char *s;
+
+ pthread_mutex_lock(&warning_buffer_lock);
+ s = warningBuffer;
DEBUG("flushing warning messages\n");
@@ -97,8 +101,8 @@ void flushWarningLog(void)
warningBuffer = NULL;
}
-
warningFlushed = 1;
+ pthread_mutex_unlock(&warning_buffer_lock);
DEBUG("done flushing warning messages\n");
}
@@ -188,10 +192,14 @@ void WARNING(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
- if (warningFlushed) {
+
+ pthread_mutex_lock(&warning_buffer_lock);
+ if (warningFlushed)
do_log(stderr, fmt, args);
- } else
+ else
buffer_warning(fmt, args);
+ pthread_mutex_unlock(&warning_buffer_lock);
+
va_end(args);
}