]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Call tzset() after setenv("TZ", ...) in unit tests 12099/head
authorMichal Nowak <mnowak@isc.org>
Thu, 14 May 2026 12:28:06 +0000 (12:28 +0000)
committerMichal Nowak <mnowak@isc.org>
Tue, 26 May 2026 15:09:11 +0000 (17:09 +0200)
POSIX does not require localtime_r() to behave as if tzset() was called,
so the TZ environment change isn't picked up if some library has already
primed libc's tz cache.  Loading pkcs11-provider during OpenSSL init
does exactly that, causing the time and dnstap cmocka tests to format
timestamps in UTC instead of the requested zone.

Assisted-by: Claude:claude-opus-4-7
(cherry picked from commit c14f7881f232e3dfb4180843dc2672a15d3bbfa6)

tests/dns/dnstap_test.c
tests/dns/update_test.c
tests/isc/time_test.c

index b2d1d01019c10c7a05eb90dd7bf90d6bb7d8f869..4c5133a855ed6d5b01abb4a51155dec0d4040c21 100644 (file)
@@ -18,6 +18,7 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <unistd.h>
 
 #define UNIT_TESTING
@@ -61,6 +62,7 @@ setup(void **state) {
         * the testdata was originally generated.
         */
        setenv("TZ", "PDT8", 1);
+       tzset();
 
        setup_loopmgr(state);
 
index 496d5cdb45d452179f743f121bbdc69baed8aed2..eee86283d52b0d5a6ae78181a27ca750e163eee8 100644 (file)
@@ -48,6 +48,7 @@ setup_test(void **state) {
        UNUSED(state);
 
        setenv("TZ", "", 1);
+       tzset();
 
        return 0;
 }
index 18b42e5098cd51f9147c1cf3afb87f3af972d16e..de68b1fa477c888c1084912488d90a5bf7a09144 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 
 #define UNIT_TESTING
 #include <cmocka.h>
@@ -144,6 +145,7 @@ ISC_RUN_TEST_IMPL(isc_time_parsehttptimestamp_test) {
        UNUSED(state);
 
        setenv("TZ", "America/Los_Angeles", 1);
+       tzset();
        t = isc_time_now();
 
        isc_time_formathttptimestamp(&t, buf, sizeof(buf));
@@ -161,6 +163,7 @@ ISC_RUN_TEST_IMPL(isc_time_formatISO8601_test) {
        UNUSED(state);
 
        setenv("TZ", "America/Los_Angeles", 1);
+       tzset();
        t = isc_time_now();
 
        /* check formatting: yyyy-mm-ddThh:mm:ssZ */
@@ -195,6 +198,7 @@ ISC_RUN_TEST_IMPL(isc_time_formatISO8601ms_test) {
        UNUSED(state);
 
        setenv("TZ", "America/Los_Angeles", 1);
+       tzset();
        t = isc_time_now();
 
        /* check formatting: yyyy-mm-ddThh:mm:ss.sssZ */
@@ -230,6 +234,7 @@ ISC_RUN_TEST_IMPL(isc_time_formatISO8601us_test) {
        UNUSED(state);
 
        setenv("TZ", "America/Los_Angeles", 1);
+       tzset();
        t = isc_time_now_hires();
 
        /* check formatting: yyyy-mm-ddThh:mm:ss.ssssssZ */
@@ -265,6 +270,7 @@ ISC_RUN_TEST_IMPL(isc_time_formatISO8601L_test) {
        UNUSED(state);
 
        setenv("TZ", "America/Los_Angeles", 1);
+       tzset();
        t = isc_time_now();
 
        /* check formatting: yyyy-mm-ddThh:mm:ss */
@@ -298,6 +304,7 @@ ISC_RUN_TEST_IMPL(isc_time_formatISO8601Lms_test) {
        UNUSED(state);
 
        setenv("TZ", "America/Los_Angeles", 1);
+       tzset();
        t = isc_time_now();
 
        /* check formatting: yyyy-mm-ddThh:mm:ss.sss */
@@ -332,6 +339,7 @@ ISC_RUN_TEST_IMPL(isc_time_formatISO8601Lus_test) {
        UNUSED(state);
 
        setenv("TZ", "America/Los_Angeles", 1);
+       tzset();
        t = isc_time_now_hires();
 
        /* check formatting: yyyy-mm-ddThh:mm:ss.ssssss */
@@ -366,6 +374,7 @@ ISC_RUN_TEST_IMPL(isc_time_formatshorttimestamp_test) {
        UNUSED(state);
 
        setenv("TZ", "America/Los_Angeles", 1);
+       tzset();
        t = isc_time_now();
 
        /* check formatting: yyyymmddhhmmsssss */