]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
timedatectl,test: use SAVE_TIMEZONE at more places
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 28 Sep 2025 01:10:47 +0000 (10:10 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 28 Sep 2025 01:10:47 +0000 (10:10 +0900)
src/test/test-calendarspec.c
src/timedate/timedatectl.c

index 9abbde622f015544330a69335d86feacf9c53ddf..0b1cbacd625a2edc563f631d9928972619f6c5a4 100644 (file)
@@ -44,12 +44,9 @@ static void _test_one(int line, const char *input, const char *output) {
 static void _test_next(int line, const char *input, const char *new_tz, usec_t after, usec_t expect) {
         _cleanup_(calendar_spec_freep) CalendarSpec *c = NULL;
         usec_t u;
-        char *old_tz;
         int r;
 
-        old_tz = getenv("TZ");
-        if (old_tz)
-                old_tz = strdupa_safe(old_tz);
+        SAVE_TIMEZONE;
 
         if (!isempty(new_tz) && !strchr(new_tz, ','))
                 new_tz = strjoina(":", new_tz);
@@ -68,9 +65,6 @@ static void _test_next(int line, const char *input, const char *new_tz, usec_t a
                 assert_se(r >= 0 && u == expect);
         else
                 assert_se(r == -ENOENT);
-
-        assert_se(set_unset_env("TZ", old_tz, true) == 0);
-        tzset();
 }
 #define test_next(input, new_tz, after, expect) _test_next(__LINE__, input,new_tz,after,expect)
 
index 0bbc740d4693893b3bd29a091165e498332c6d45..f3a8046bede35b0690a723ffd848b70b02219f81 100644 (file)
@@ -58,7 +58,7 @@ typedef struct StatusInfo {
 
 static int print_status_info(const StatusInfo *i) {
         _cleanup_(table_unrefp) Table *table = NULL;
-        const char *old_tz = NULL, *tz, *tz_colon;
+        const char *tz_colon;
         char a[LINE_MAX];
         TableCell *cell;
         struct tm tm;
@@ -79,9 +79,7 @@ static int print_status_info(const StatusInfo *i) {
         (void) table_set_ellipsize_percent(table, cell, 100);
 
         /* Save the old $TZ */
-        tz = getenv("TZ");
-        if (tz)
-                old_tz = strdupa_safe(tz);
+        SAVE_TIMEZONE;
 
         /* Set the new $TZ */
         tz_colon = strjoina(":", isempty(i->timezone) ? "UTC" : i->timezone);
@@ -158,13 +156,6 @@ static int print_status_info(const StatusInfo *i) {
         if (r < 0)
                 return table_log_add_error(r);
 
-        /* Restore the $TZ */
-        r = set_unset_env("TZ", old_tz, true);
-        if (r < 0)
-                log_warning_errno(r, "Failed to set TZ environment variable, ignoring: %m");
-        else
-                tzset();
-
         r = table_add_many(table,
                            TABLE_FIELD, "System clock synchronized",
                            TABLE_BOOLEAN, i->ntp_synced,