More thread-safety to log_trace

This commit is contained in:
2016-08-09 12:36:37 +03:00
parent 093c2263b1
commit 0d5eeed758

View File

@@ -27,6 +27,7 @@ void log_ssl()
void log_trace(LOG_LEVEL lvl, char *fmt, ... ) void log_trace(LOG_LEVEL lvl, char *fmt, ... )
{ {
LOG_LEVEL cur_lvl = conf.rmps.loglevel - '0'; LOG_LEVEL cur_lvl = conf.rmps.loglevel - '0';
char fmt_with_pfx[1024];
if (conf.isvalid) if (conf.isvalid)
pthread_once(&once, open_logs); pthread_once(&once, open_logs);
@@ -48,19 +49,20 @@ void log_trace(LOG_LEVEL lvl, char *fmt, ... )
conf.rmps.errlog ); conf.rmps.errlog );
fd = stderr; fd = stderr;
} }
fprintf( fd, snprintf( fmt_with_pfx,
"[%d-%02d-%02d %02d:%02d:%02d] %s: ", sizeof(fmt_with_pfx),
"[%d-%02d-%02d %02d:%02d:%02d] %s: %s\n",
tm.tm_year + 1900, tm.tm_year + 1900,
tm.tm_mon + 1, tm.tm_mon + 1,
tm.tm_mday, tm.tm_mday,
tm.tm_hour, tm.tm_hour,
tm.tm_min, tm.tm_min,
tm.tm_sec, tm.tm_sec,
prefixes[lvl-1] ); prefixes[lvl-1],
fmt );
va_start(list, fmt); va_start(list, fmt);
vfprintf(fd, fmt, list); vfprintf(fd, fmt_with_pfx, list);
fprintf(fd, "\n");
fflush(fd); fflush(fd);
va_end(list); va_end(list);
} else } else