]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Call tzset() after setenv("TZ", ...) in unit tests 9543/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 13:52:59 +0000 (15:52 +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
tests/dns/dnstap_test.c
tests/dns/update_test.c
tests/isc/time_test.c

index 4a1c941bb0d80fc7228b1a283bc5209a9a5129b0..94d17040ee32d020be45ef730240bf2414d68b6f 100644 (file)
@@ -18,6 +18,7 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <unistd.h>
 
 #define UNIT_TESTING
@@ -63,6 +64,7 @@ setup(void **state) {
         * the testdata was originally generated.
         */
        setenv("TZ", "PDT8", 1);
+       tzset();
 
        setup_loopmgr(state);
 
index 3cbd7daee695879a796e9ef1335aef40579f23aa..a8f65f9f057a14904dd52bc6a89b91a33f3427a6 100644 (file)
@@ -50,6 +50,7 @@ setup_test(void **state) {
        UNUSED(state);
 
        setenv("TZ", "", 1);
+       tzset();
 
        return 0;
 }
index 2bd85a636e3aa609b15f4f52ba01f471663fa570..5dc1834e77edb6fe4d37ef6d85d2e84fbf6b0a11 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 
 #define UNIT_TESTING
 #include <cmocka.h>
@@ -145,6 +146,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));
@@ -162,6 +164,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 */
@@ -196,6 +199,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 */
@@ -231,6 +235,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 */
@@ -266,6 +271,7 @@ ISC_RUN_TEST_IMPL(isc_time_formatISO8601TZms_test) {
        UNUSED(state);
 
        setenv("TZ", "America/Los_Angeles", 1);
+       tzset();
        t = isc_time_now();
 
        /* check formatting: yyyy-mm-ddThh:mm:ss.sss */
@@ -304,6 +310,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 */
@@ -338,6 +345,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 */