summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Janssen <medhefgo@web.de>2021-11-24 18:45:16 +0100
committerJan Janssen <medhefgo@web.de>2021-11-25 14:56:33 +0100
commit4d5ad9d951299c905453ac8e3769dc82b0a09fb4 (patch)
treeaea4b946b047e096de36493a0a7092774afdfe53
parenta40b728e1172cc07a09e12dd56089ab37c8c5924 (diff)
downloadsystemd-4d5ad9d951299c905453ac8e3769dc82b0a09fb4.tar.gz
test-time-util: Properly restore TZ variable
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.
-rw-r--r--src/test/test-time-util.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c
index 53f8114501..0992a31659 100644
--- a/src/test/test-time-util.c
+++ b/src/test/test-time-util.c
@@ -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) {