From: Yu Watanabe Date: Tue, 11 Nov 2025 18:35:45 +0000 (+0900) Subject: musl: time-util: introduce get_tzname() helper function X-Git-Tag: v259-rc1~81^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6431f2e072eef1c706b716d3a902fefcb1e63c40;p=thirdparty%2Fsystemd.git musl: time-util: introduce get_tzname() helper function musl leaves the DST timezone name unset if there is no DST. The helper function maps that back to no DST. --- diff --git a/src/basic/time-util.c b/src/basic/time-util.c index c09c9fd6d02..8e0d4cc0304 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -625,6 +625,14 @@ char* format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) { return buf; } +const char* get_tzname(bool dst) { + /* musl leaves the DST timezone name unset if there is no DST, map this back to no DST */ + if (dst && isempty(tzname[1])) + dst = false; + + return empty_to_null(tzname[dst]); +} + int parse_gmtoff(const char *t, long *ret) { int r; @@ -1078,10 +1086,7 @@ int parse_timestamp(const char *t, usec_t *ret) { * not follow the timezone change in the current area. */ tzset(); for (int j = 0; j <= 1; j++) { - if (isempty(tzname[j])) - continue; - - if (!streq(tz, tzname[j])) + if (!streq_ptr(tz, get_tzname(j))) continue; /* The specified timezone matches tzname[] of the local timezone. */ diff --git a/src/basic/time-util.h b/src/basic/time-util.h index 322a2ece6b2..b5530e3e921 100644 --- a/src/basic/time-util.h +++ b/src/basic/time-util.h @@ -149,6 +149,7 @@ static inline char* format_timestamp(char *buf, size_t l, usec_t t) { #define FORMAT_TIMESTAMP_STYLE(t, style) \ format_timestamp_style((char[FORMAT_TIMESTAMP_MAX]){}, FORMAT_TIMESTAMP_MAX, t, style) +const char* get_tzname(bool dst); int parse_gmtoff(const char *t, long *ret); int parse_timestamp(const char *t, usec_t *ret); diff --git a/src/core/manager.c b/src/core/manager.c index 90a3f25aebd..b501d3f1c5b 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -3208,7 +3208,7 @@ static int manager_dispatch_timezone_change( /* Read the new timezone */ tzset(); - log_debug("Timezone has been changed (now: %s).", tzname[daylight]); + log_debug("Timezone has been changed (now: %s).", get_tzname(daylight)); HASHMAP_FOREACH(u, m->units) if (UNIT_VTABLE(u)->timezone_change) diff --git a/src/shared/calendarspec.c b/src/shared/calendarspec.c index 0e12e55a977..ed8e202a2ee 100644 --- a/src/shared/calendarspec.c +++ b/src/shared/calendarspec.c @@ -370,9 +370,10 @@ int calendar_spec_to_string(const CalendarSpec *c, char **ret) { tzset(); - if (!isempty(tzname[c->dst])) { + const char *z = get_tzname(c->dst); + if (z) { fputc(' ', f); - fputs(tzname[c->dst], f); + fputs(z, f); } } @@ -897,10 +898,11 @@ int calendar_spec_from_string(const char *p, CalendarSpec **ret) { /* Check if the local timezone was specified? */ for (j = 0; j <= 1; j++) { - if (isempty(tzname[j])) + const char *z = get_tzname(j); + if (!z) continue; - e = endswith_no_case(p, tzname[j]); + e = endswith_no_case(p, z); if (!e) continue; if (e == p) diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c index 7bcf0ae7ee3..8f5d8bd5a8d 100644 --- a/src/test/test-time-util.c +++ b/src/test/test-time-util.c @@ -15,7 +15,7 @@ static void set_timezone(const char *tz) { ASSERT_OK(set_unset_env("TZ", tz, /* overwrite = */ true)); tzset(); - log_info("TZ=%s, tzname[0]=%s, tzname[1]=%s", strna(getenv("TZ")), strempty(tzname[0]), strempty(tzname[1])); + log_info("TZ=%s, tzname[0]=%s, tzname[1]=%s", strna(getenv("TZ")), strempty(get_tzname(/* dst= */ false)), strempty(get_tzname(/* dst= */ true))); } TEST(parse_sec) { @@ -1109,15 +1109,15 @@ TEST(in_utc_timezone) { assert_se(setenv("TZ", "UTC", 1) >= 0); assert_se(in_utc_timezone()); - ASSERT_STREQ(tzname[0], "UTC"); - ASSERT_STREQ(tzname[1], "UTC"); + ASSERT_STREQ(get_tzname(/* dst= */ false), "UTC"); + ASSERT_STREQ(get_tzname(/* dst= */ true), "UTC"); assert_se(timezone == 0); assert_se(daylight == 0); assert_se(setenv("TZ", "Europe/Berlin", 1) >= 0); assert_se(!in_utc_timezone()); - ASSERT_STREQ(tzname[0], "CET"); - ASSERT_STREQ(tzname[1], "CEST"); + ASSERT_STREQ(get_tzname(/* dst= */ false), "CET"); + ASSERT_STREQ(get_tzname(/* dst= */ true), "CEST"); } TEST(map_clock_usec) { diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index 6e21d1a73ab..9016f6c4a6d 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -733,9 +733,9 @@ static int method_set_timezone(sd_bus_message *m, void *userdata, sd_bus_error * log_struct(LOG_INFO, LOG_MESSAGE_ID(SD_MESSAGE_TIMEZONE_CHANGE_STR), LOG_ITEM("TIMEZONE=%s", c->zone), - LOG_ITEM("TIMEZONE_SHORTNAME=%s", tzname[daylight]), + LOG_ITEM("TIMEZONE_SHORTNAME=%s", get_tzname(daylight)), LOG_ITEM("DAYLIGHT=%i", daylight), - LOG_MESSAGE("Changed time zone to '%s' (%s).", c->zone, tzname[daylight])); + LOG_MESSAGE("Changed time zone to '%s' (%s).", c->zone, get_tzname(daylight))); (void) sd_bus_emit_properties_changed(sd_bus_message_get_bus(m), "/org/freedesktop/timedate1", "org.freedesktop.timedate1", "Timezone",