]> Savannah Git Hosting - gnulib.git/commitdiff
mktime: improve thread-safety
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 5 Oct 2024 04:07:09 +0000 (21:07 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 5 Oct 2024 04:14:58 +0000 (21:14 -0700)
* lib/mktime.c (__mktime_internal) [!_LIBC]: Double the number of
probes.  Although this isn’t guaranteed to suffice, it should be
good enough for practical applications, and fixing the problem
in general would require access to the underlying tz state lock
which would be hard to do.

ChangeLog
lib/mktime.c

index cea31f84e6ece2710f4ee3dce725ebd5d4710250..65fd11b2bf36b3f1158e46f7862a0b4548da7e2f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2024-10-04  Paul Eggert  <eggert@cs.ucla.edu>
 
+       mktime: improve thread-safety
+       * lib/mktime.c (__mktime_internal) [!_LIBC]: Double the number of
+       probes.  Although this isn’t guaranteed to suffice, it should be
+       good enough for practical applications, and fixing the problem
+       in general would require access to the underlying tz state lock
+       which would be hard to do.
+
        mktime: fix timegm bug that set tmp->tm_isdst
        * lib/timegm.c (__timegm64): Omit now-unnecessary initialization
        of tm_isdst.  Anyway, the initialization was always wrong, since
index f21dfe3838a64f5992452665361d240bbb372763..7f07abb814308d8ee5d271e2cb8389ebb7d784a3 100644 (file)
@@ -332,6 +332,14 @@ __mktime_internal (struct tm *tp, bool local, mktime_offset_t *offset)
      leap seconds, but some hosts have them anyway.  */
   int remaining_probes = 6;
 
+#ifndef _LIBC
+  /* Gnulib mktime doesn't lock the tz state, so it may need to probe
+     more often if some other thread changes local time while
+     __mktime_internal is probing.  Double the number of probes; this
+     should suffice for practical cases that are at all likely.  */
+  remaining_probes *= 2;
+#endif
+
   /* Time requested.  Copy it in case gmtime/localtime modify *TP;
      this can occur if TP is localtime's returned value and CONVERT is
      localtime.  */