]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-time-util: Properly restore TZ variable
authorJan Janssen <medhefgo@web.de>
Wed, 24 Nov 2021 17:45:16 +0000 (18:45 +0100)
committerJan Janssen <medhefgo@web.de>
Thu, 25 Nov 2021 13:56:33 +0000 (14:56 +0100)
The test fails to call tzset() after unsetting TZ variable, which
could break other tests. Also, let's be nicer and actually restore
the TZ to its original value.

src/test/test-time-util.c

index 53f811450170d1347390cfe171a109cdcac3af6a..0992a316598086456c48d13dfa2026ba5a79018c 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+#include "env-util.h"
 #include "random-util.h"
 #include "serialize.h"
 #include "string-util.h"
@@ -570,6 +571,8 @@ static void test_usec_shift_clock(void) {
 static void test_in_utc_timezone(void) {
         log_info("/* %s */", __func__);
 
+        const char *tz = getenv("TZ");
+
         assert_se(setenv("TZ", ":UTC", 1) >= 0);
         assert_se(in_utc_timezone());
         assert_se(streq(tzname[0], "UTC"));
@@ -582,7 +585,8 @@ static void test_in_utc_timezone(void) {
         assert_se(streq(tzname[0], "CET"));
         assert_se(streq(tzname[1], "CEST"));
 
-        assert_se(unsetenv("TZ") == 0);
+        assert_se(set_unset_env("TZ", tz, true) == 0);
+        tzset();
 }
 
 static void test_map_clock_usec(void) {