timedatectl,test: use SAVE_TIMEZONE at more places

This commit is contained in:
Yu Watanabe
2025-09-28 10:10:47 +09:00
parent 672924356f
commit 7d6f1d695c
2 changed files with 3 additions and 18 deletions
+1 -7
View 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)
+2 -11
View 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,