aboutsummaryrefslogtreecommitdiffstats
path: root/src/log.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-08-20 01:31:51 -0700
committerEric Wong <normalperson@yhbt.net>2008-08-20 01:31:51 -0700
commit1b197e65232e1a51b853db53985e8eda61f1b196 (patch)
tree2d85ff67ba79e32256a20d2d2bee7222352007fd /src/log.c
parent5a0216af3dc7c9dedc4dacb708191f0fd380bb73 (diff)
parent508ae1c18d3bdc99a1bb06181762e5ec859cf072 (diff)
downloadmpd-1b197e65232e1a51b853db53985e8eda61f1b196.tar.gz
mpd-1b197e65232e1a51b853db53985e8eda61f1b196.tar.xz
mpd-1b197e65232e1a51b853db53985e8eda61f1b196.zip
Merge branch 'core-rewrite' of git://git.musicpd.org/normalperson/mpd
* 'core-rewrite' of git://git.musicpd.org/normalperson/mpd: Remove ob_wait_sync and cleanup triggering in playlist fix output buffer deadlock when daemonizing log.c: thread-safety for warning log core rewrite (decode,player,outputBuffer,playlist)
Diffstat (limited to 'src/log.c')
-rw-r--r--src/log.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/log.c b/src/log.c
index 8a2d48410..2f4c1af0f 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;
@@ -75,12 +76,16 @@ static void do_log(FILE *fp, const char *fmt, va_list args)
{
if (!stdout_mode)
fwrite(log_date(), LOG_DATE_LEN, 1, fp);
+ fprintf(fp, "%08x: ", pthread_self());
vfprintf(fp, fmt, args);
}
void flushWarningLog(void)
{
- char *s = warningBuffer;
+ char *s;
+
+ pthread_mutex_lock(&warning_buffer_lock);
+ s = warningBuffer;
DEBUG("flushing warning messages\n");
@@ -97,8 +102,8 @@ void flushWarningLog(void)
warningBuffer = NULL;
}
-
warningFlushed = 1;
+ pthread_mutex_unlock(&warning_buffer_lock);
DEBUG("done flushing warning messages\n");
}
@@ -188,10 +193,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);
}