]> mj.ucw.cz Git - libucw.git/commitdiff
It seems that signal safety of time-related functions is even more subtle
authorMartin Mares <mj@ucw.cz>
Fri, 20 Jan 2006 19:47:21 +0000 (19:47 +0000)
committerMartin Mares <mj@ucw.cz>
Fri, 20 Jan 2006 19:47:21 +0000 (19:47 +0000)
than I thought -- strftime() and localtime_r() can deadlock each other,
probably due to access to time zone information. Replaced strftime() by
a mere sprintf.

lib/log.c

index e513cbe6d4719c448423a1de13768f0efe1406a8..713fa768c0c6acb91806d52319d4802d52d05962 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
@@ -45,7 +45,9 @@ vlog_msg(unsigned int cat, const char *msg, va_list args)
     {
       p = buf = alloca(buflen);
       *p++ = cat;
-      p += strftime(p, buflen, " %Y-%m-%d %H:%M:%S", &tm);
+      /* We cannot use strftime() here, because it's not re-entrant */
+      p += sprintf(p, " %4d-%02d-%02d %02d:%02d:%02d", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
+                  tm.tm_hour, tm.tm_min, tm.tm_sec);
       if (log_precise_timings)
         p += sprintf(p, ".%06d", (int)tv.tv_usec);
       *p++ = ' ';