[PATCH] tzset_internal: do not reset old_tz if no change from default value
Dominique Martinet
asmadeus@codewreck.org
Thu Feb 27 15:14:06 GMT 2025
tzset_internal returns early if tz is already set and did not change from old_tz,
but in case of default value it always reprocesses the value.
This was noticed because of a program crashing calling mktime in many threads
at once; such program will now be less likely to crash.
This should also slightly speed up programs heavily relying on this if
they do not have the TZ environment variable set
---
I've checked the patch on el9 (applying on top of
glibc-2.34-125.el9_5.1.src.rpm) and did not notice any obvious ill
effect.
Now I'm not entierly sure if mktime() ought to be considered thread
safe; the man page I have on my system says "MT-Safe env locale" so I
guess that ought to be considered a bug?
Regardless, I think it's the right thing to do.
FWIW, the actual program that crashed along with user report and
investigations:
https://github.com/phobos-storage/lustre-hsm-phobos/issues/6
time/tzset.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/time/tzset.c b/time/tzset.c
index 0ddc20328717..8e0de0f13e8e 100644
--- a/time/tzset.c
+++ b/time/tzset.c
@@ -390,10 +390,15 @@ tzset_internal (int always)
/* No change, simply return. */
return;
- if (tz == NULL)
+ if (tz == NULL) {
/* No user specification; use the site-wide default. */
tz = TZDEFAULT;
+ /* Recheck if no change from default value... */
+ if (old_tz != NULL && tz != NULL && strcmp (tz, old_tz) == 0)
+ return;
+ }
+
tz_rules[0].name = NULL;
tz_rules[1].name = NULL;
--
2.48.1
More information about the Libc-alpha
mailing list