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
This commit is contained in:
parent
15c2aa765a
commit
057a483710
27
src/log.c
27
src/log.c
@ -84,11 +84,11 @@ static void buffer_warning(const char *fmt, va_list args)
|
|||||||
va_end(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)
|
if (!stdout_mode)
|
||||||
xwrite(fd, log_date(), 15);
|
fwrite(log_date(), 15, 1, fp);
|
||||||
vfdprintf(fd, fmt, args);
|
vfprintf(fp, fmt, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void flushWarningLog(void)
|
void flushWarningLog(void)
|
||||||
@ -102,7 +102,7 @@ void flushWarningLog(void)
|
|||||||
|
|
||||||
s = strtok(warningBuffer, "\n");
|
s = strtok(warningBuffer, "\n");
|
||||||
while (s != NULL) {
|
while (s != NULL) {
|
||||||
fdprintf(STDERR_FILENO, "%s\n", s);
|
vfprintf(stderr, "%s\n", s);
|
||||||
s = strtok(NULL, "\n");
|
s = strtok(NULL, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,6 +115,9 @@ void initLog(const int verbose)
|
|||||||
{
|
{
|
||||||
ConfigParam *param;
|
ConfigParam *param;
|
||||||
|
|
||||||
|
/* unbuffer stdout, stderr is unbuffered by default, leave it */
|
||||||
|
setvbuf(stdout, (char *)NULL, _IONBF, 0);
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
logLevel = LOG_LEVEL_DEBUG;
|
logLevel = LOG_LEVEL_DEBUG;
|
||||||
return;
|
return;
|
||||||
@ -171,23 +174,23 @@ void setup_log_output(const int use_stdout)
|
|||||||
redirect_stdin();
|
redirect_stdin();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define log_func(func,level,fd) \
|
#define log_func(func,level,fp) \
|
||||||
mpd_printf void func(const char *fmt, ...) \
|
mpd_printf void func(const char *fmt, ...) \
|
||||||
{ \
|
{ \
|
||||||
if (logLevel >= level) { \
|
if (logLevel >= level) { \
|
||||||
va_list args; \
|
va_list args; \
|
||||||
va_start(args, fmt); \
|
va_start(args, fmt); \
|
||||||
do_log(fd, fmt, args); \
|
do_log(fp, fmt, args); \
|
||||||
va_end(args); \
|
va_end(args); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
log_func(ERROR, 0, STDERR_FILENO)
|
log_func(ERROR, 0, stderr)
|
||||||
log_func(LOG, 0, STDOUT_FILENO)
|
log_func(LOG, 0, stdout)
|
||||||
log_func(SECURE, LOG_LEVEL_SECURE, STDOUT_FILENO)
|
log_func(SECURE, LOG_LEVEL_SECURE, stdout)
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
log_func(DEBUG, LOG_LEVEL_DEBUG, STDOUT_FILENO)
|
log_func(DEBUG, LOG_LEVEL_DEBUG, stdout)
|
||||||
#endif /* NDEBUG */
|
#endif /* NDEBUG */
|
||||||
|
|
||||||
#undef log_func
|
#undef log_func
|
||||||
@ -197,7 +200,7 @@ void WARNING(const char *fmt, ...)
|
|||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
if (warningFlushed) {
|
if (warningFlushed) {
|
||||||
do_log(STDERR_FILENO, fmt, args);
|
do_log(stderr, fmt, args);
|
||||||
} else
|
} else
|
||||||
buffer_warning(fmt, args);
|
buffer_warning(fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
@ -207,7 +210,7 @@ mpd_printf mpd_noreturn void FATAL(const char *fmt, ...)
|
|||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
do_log(STDERR_FILENO, fmt, args);
|
do_log(stderr, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user