mirror of
https://github.com/systemd/systemd
synced 2025-10-06 00:13:24 +02:00
tree-wide: stop assigning colon prefixed timezone to $TZ
glibc (and also musl, though we do not officially support it yet) silently ignores colon prefix in $TZ. Let's always not prefix the timezone. tzset(3) states: > A nonempty value of TZ can be one of two formats, either of which can > be preceded by a colon which is ignored. Addresses https://github.com/systemd/systemd/pull/38876#discussion_r2384347594.
This commit is contained in:
@@ -1022,7 +1022,7 @@ int parse_timestamp(const char *t, usec_t *ret) {
|
|||||||
if (timezone_is_valid(tz, LOG_DEBUG)) {
|
if (timezone_is_valid(tz, LOG_DEBUG)) {
|
||||||
SAVE_TIMEZONE;
|
SAVE_TIMEZONE;
|
||||||
|
|
||||||
if (setenv("TZ", strjoina(":", tz), /* overwrite = */ true) < 0)
|
if (setenv("TZ", tz, /* overwrite = */ true) < 0)
|
||||||
return negative_errno();
|
return negative_errno();
|
||||||
|
|
||||||
return parse_timestamp_impl(t, max_len, /* utc = */ false, /* isdst = */ -1, /* gmtoff = */ 0, ret);
|
return parse_timestamp_impl(t, max_len, /* utc = */ false, /* isdst = */ -1, /* gmtoff = */ 0, ret);
|
||||||
|
@@ -1436,10 +1436,7 @@ int calendar_spec_next_usec(const CalendarSpec *spec, usec_t usec, usec_t *ret_n
|
|||||||
|
|
||||||
SAVE_TIMEZONE;
|
SAVE_TIMEZONE;
|
||||||
|
|
||||||
/* tzset(3) says $TZ should be prefixed with ":" if we reference timezone files */
|
r = RET_NERRNO(setenv("TZ", spec->timezone, /* overwrite = */ true));
|
||||||
const char *colon_tz = strjoina(":", spec->timezone);
|
|
||||||
|
|
||||||
r = RET_NERRNO(setenv("TZ", colon_tz, 1));
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
@@ -13,13 +13,7 @@
|
|||||||
#define TRIAL 100u
|
#define TRIAL 100u
|
||||||
|
|
||||||
static void set_timezone(const char *tz) {
|
static void set_timezone(const char *tz) {
|
||||||
if (!tz)
|
ASSERT_OK(set_unset_env("TZ", tz, /* overwrite = */ true));
|
||||||
ASSERT_OK_ERRNO(unsetenv("TZ"));
|
|
||||||
if (isempty(tz))
|
|
||||||
ASSERT_OK_ERRNO(setenv("TZ", tz, /* overwrite = */ true));
|
|
||||||
else
|
|
||||||
ASSERT_OK_ERRNO(setenv("TZ", strjoina(":", tz), /* overwrite = */ true));
|
|
||||||
|
|
||||||
tzset();
|
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(tzname[0]), strempty(tzname[1]));
|
||||||
}
|
}
|
||||||
@@ -421,7 +415,7 @@ static void test_format_timestamp_impl(usec_t x) {
|
|||||||
* timezone may provide time shifted 1 hour from the original. See
|
* timezone may provide time shifted 1 hour from the original. See
|
||||||
* https://github.com/systemd/systemd/issues/28472 and https://github.com/systemd/systemd/pull/35471 */
|
* https://github.com/systemd/systemd/issues/28472 and https://github.com/systemd/systemd/pull/35471 */
|
||||||
bool ignore =
|
bool ignore =
|
||||||
streq_ptr(getenv("TZ"), ":Africa/Windhoek") &&
|
streq_ptr(getenv("TZ"), "Africa/Windhoek") &&
|
||||||
(x_sec > y_sec ? x_sec - y_sec : y_sec - x_sec) == 3600;
|
(x_sec > y_sec ? x_sec - y_sec : y_sec - x_sec) == 3600;
|
||||||
|
|
||||||
log_full(ignore ? LOG_WARNING : LOG_ERR,
|
log_full(ignore ? LOG_WARNING : LOG_ERR,
|
||||||
@@ -1113,14 +1107,14 @@ TEST(usec_shift_clock) {
|
|||||||
TEST(in_utc_timezone) {
|
TEST(in_utc_timezone) {
|
||||||
SAVE_TIMEZONE;
|
SAVE_TIMEZONE;
|
||||||
|
|
||||||
assert_se(setenv("TZ", ":UTC", 1) >= 0);
|
assert_se(setenv("TZ", "UTC", 1) >= 0);
|
||||||
assert_se(in_utc_timezone());
|
assert_se(in_utc_timezone());
|
||||||
ASSERT_STREQ(tzname[0], "UTC");
|
ASSERT_STREQ(tzname[0], "UTC");
|
||||||
ASSERT_STREQ(tzname[1], "UTC");
|
ASSERT_STREQ(tzname[1], "UTC");
|
||||||
assert_se(timezone == 0);
|
assert_se(timezone == 0);
|
||||||
assert_se(daylight == 0);
|
assert_se(daylight == 0);
|
||||||
|
|
||||||
assert_se(setenv("TZ", ":Europe/Berlin", 1) >= 0);
|
assert_se(setenv("TZ", "Europe/Berlin", 1) >= 0);
|
||||||
assert_se(!in_utc_timezone());
|
assert_se(!in_utc_timezone());
|
||||||
ASSERT_STREQ(tzname[0], "CET");
|
ASSERT_STREQ(tzname[0], "CET");
|
||||||
ASSERT_STREQ(tzname[1], "CEST");
|
ASSERT_STREQ(tzname[1], "CEST");
|
||||||
|
@@ -58,7 +58,6 @@ typedef struct StatusInfo {
|
|||||||
|
|
||||||
static int print_status_info(const StatusInfo *i) {
|
static int print_status_info(const StatusInfo *i) {
|
||||||
_cleanup_(table_unrefp) Table *table = NULL;
|
_cleanup_(table_unrefp) Table *table = NULL;
|
||||||
const char *tz_colon;
|
|
||||||
char a[LINE_MAX];
|
char a[LINE_MAX];
|
||||||
TableCell *cell;
|
TableCell *cell;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
@@ -82,8 +81,7 @@ static int print_status_info(const StatusInfo *i) {
|
|||||||
SAVE_TIMEZONE;
|
SAVE_TIMEZONE;
|
||||||
|
|
||||||
/* Set the new $TZ */
|
/* Set the new $TZ */
|
||||||
tz_colon = strjoina(":", isempty(i->timezone) ? "UTC" : i->timezone);
|
if (setenv("TZ", isempty(i->timezone) ? "UTC" : i->timezone, /* overwrite = */ true) < 0)
|
||||||
if (setenv("TZ", tz_colon, true) < 0)
|
|
||||||
log_warning_errno(errno, "Failed to set TZ environment variable, ignoring: %m");
|
log_warning_errno(errno, "Failed to set TZ environment variable, ignoring: %m");
|
||||||
else
|
else
|
||||||
tzset();
|
tzset();
|
||||||
|
Reference in New Issue
Block a user