aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2006-08-03 03:29:02 +0000
committerEric Wong <normalperson@yhbt.net>2006-08-03 03:29:02 +0000
commit057a483710a43598efe59b77e865caf67716a2cc (patch)
tree6e042fcb80ccd64df3dc1dc99fadeb3a8c55d4c0 /src
parent15c2aa765a864e05eea5ef7eb570701b3be62d87 (diff)
downloadmpd-057a483710a43598efe59b77e865caf67716a2cc.tar.gz
mpd-057a483710a43598efe59b77e865caf67716a2cc.tar.xz
mpd-057a483710a43598efe59b77e865caf67716a2cc.zip
log: switch to using FILE * for logging, since fdprintf isn't reentrant
(and fdprintf was never meant to be reentrant, either) A huge thanks to welshbyte for reporting the bug and being very helpful in helping me fix it. git-svn-id: https://svn.musicpd.org/mpd/trunk@4537 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/log.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/log.c b/src/log.c
index 490913bd4..a7f097dce 100644
--- a/src/log.c
+++ b/src/log.c
@@ -84,11 +84,11 @@ static void buffer_warning(const char *fmt, va_list args)
va_end(args);
}
-static void do_log(const int fd, const char *fmt, va_list args)
+static void do_log(FILE *fp, const char *fmt, va_list args)
{
if (!stdout_mode)
- xwrite(fd, log_date(), 15);
- vfdprintf(fd, fmt, args);
+ fwrite(log_date(), 15, 1, fp);
+ vfprintf(fp, fmt, args);
}
void flushWarningLog(void)
@@ -102,7 +102,7 @@ void flushWarningLog(void)
s = strtok(warningBuffer, "\n");
while (s != NULL) {
- fdprintf(STDERR_FILENO, "%s\n", s);
+ vfprintf(stderr, "%s\n", s);
s = strtok(NULL, "\n");
}
@@ -115,6 +115,9 @@ void initLog(const int verbose)
{
ConfigParam *param;
+ /* unbuffer stdout, stderr is unbuffered by default, leave it */
+ setvbuf(stdout, (char *)NULL, _IONBF, 0);
+
if (verbose) {
logLevel = LOG_LEVEL_DEBUG;
return;
@@ -171,23 +174,23 @@ void setup_log_output(const int use_stdout)
redirect_stdin();
}
-#define log_func(func,level,fd) \
+#define log_func(func,level,fp) \
mpd_printf void func(const char *fmt, ...) \
{ \
if (logLevel >= level) { \
va_list args; \
va_start(args, fmt); \
- do_log(fd, fmt, args); \
+ do_log(fp, fmt, args); \
va_end(args); \
} \
}
-log_func(ERROR, 0, STDERR_FILENO)
-log_func(LOG, 0, STDOUT_FILENO)
-log_func(SECURE, LOG_LEVEL_SECURE, STDOUT_FILENO)
+log_func(ERROR, 0, stderr)
+log_func(LOG, 0, stdout)
+log_func(SECURE, LOG_LEVEL_SECURE, stdout)
#ifndef NDEBUG
-log_func(DEBUG, LOG_LEVEL_DEBUG, STDOUT_FILENO)
+log_func(DEBUG, LOG_LEVEL_DEBUG, stdout)
#endif /* NDEBUG */
#undef log_func
@@ -197,7 +200,7 @@ void WARNING(const char *fmt, ...)
va_list args;
va_start(args, fmt);
if (warningFlushed) {
- do_log(STDERR_FILENO, fmt, args);
+ do_log(stderr, fmt, args);
} else
buffer_warning(fmt, args);
va_end(args);
@@ -207,7 +210,7 @@ mpd_printf mpd_noreturn void FATAL(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
- do_log(STDERR_FILENO, fmt, args);
+ do_log(stderr, fmt, args);
va_end(args);
exit(EXIT_FAILURE);
}