Switching all use of gmtime and localtime to use reentrant variants.

This was causing occasional problems with the time on processes
running lots of threads.  The use of gmtime in the json
formatter is the likely culprit due to the fact that the
json formatter runs in threads.  More evidence for this is that
the problem only appears to exhibit when logs are being written
as JSON.
This commit is contained in:
Seth Hall 2016-05-07 01:22:38 -04:00
parent 209c8936d1
commit 40e9724de7
3 changed files with 35 additions and 13 deletions

View file

@ -571,7 +571,14 @@ const char* fmt_access_time(double t)
{
static char buf[256];
time_t time = (time_t) t;
strftime(buf, sizeof(buf), "%d/%m-%H:%M", localtime(&time));
struct tm ts;
if ( ! localtime_r(&time, &ts) )
{
reporter->InternalError("unable to get time");
}
strftime(buf, sizeof(buf), "%d/%m-%H:%M", &ts);
return buf;
}