From: Michal Nowak Date: Thu, 14 May 2026 12:28:06 +0000 (+0000) Subject: Call tzset() after setenv("TZ", ...) in unit tests X-Git-Tag: v9.21.23~34^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c14f7881f232e3dfb4180843dc2672a15d3bbfa6;p=thirdparty%2Fbind9.git Call tzset() after setenv("TZ", ...) in unit tests 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 --- diff --git a/tests/dns/dnstap_test.c b/tests/dns/dnstap_test.c index 4a1c941bb0d..94d17040ee3 100644 --- a/tests/dns/dnstap_test.c +++ b/tests/dns/dnstap_test.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #define UNIT_TESTING @@ -63,6 +64,7 @@ setup(void **state) { * the testdata was originally generated. */ setenv("TZ", "PDT8", 1); + tzset(); setup_loopmgr(state); diff --git a/tests/dns/update_test.c b/tests/dns/update_test.c index 3cbd7daee69..a8f65f9f057 100644 --- a/tests/dns/update_test.c +++ b/tests/dns/update_test.c @@ -50,6 +50,7 @@ setup_test(void **state) { UNUSED(state); setenv("TZ", "", 1); + tzset(); return 0; } diff --git a/tests/isc/time_test.c b/tests/isc/time_test.c index 2bd85a636e3..5dc1834e77e 100644 --- a/tests/isc/time_test.c +++ b/tests/isc/time_test.c @@ -19,6 +19,7 @@ #include #include #include +#include #define UNIT_TESTING #include @@ -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 */