summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-11-12 17:52:35 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-11-13 12:30:22 +0100
commit437f48a471f51ac9dd2697ee3b848a71b4f101df (patch)
treef05a4944d2069c33b52618eea544f9b799414730 /src
parentnspawn: do not emit any warning when $UNIFIED_CGROUP_HIERARCHY is used (diff)
downloadsystemd-437f48a471f51ac9dd2697ee3b848a71b4f101df.tar.xz
systemd-437f48a471f51ac9dd2697ee3b848a71b4f101df.zip
tree-wide: fix how we set $TZ
According to tzset(3) we need to prefix timezone names with ":". Let's do so hence, to avoid any ambiguities and follow documented behaviour.
Diffstat (limited to 'src')
-rw-r--r--src/basic/time-util.c6
-rw-r--r--src/shared/calendarspec.c7
-rw-r--r--src/test/test-calendarspec.c9
-rw-r--r--src/test/test-time-util.c2
-rw-r--r--src/timedate/timedatectl.c5
5 files changed, 21 insertions, 8 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index f5be619ad6..e2c9c47e57 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -832,8 +832,12 @@ int parse_timestamp(const char *t, usec_t *usec) {
}
if (r == 0) {
bool with_tz = true;
+ char *colon_tz;
- if (setenv("TZ", tz, 1) != 0) {
+ /* tzset(3) says $TZ should be prefixed with ":" if we reference timezone files */
+ colon_tz = strjoina(":", tz);
+
+ if (setenv("TZ", colon_tz, 1) != 0) {
shared->return_value = negative_errno();
_exit(EXIT_FAILURE);
}
diff --git a/src/shared/calendarspec.c b/src/shared/calendarspec.c
index aa0d6a8224..217ab3fbaf 100644
--- a/src/shared/calendarspec.c
+++ b/src/shared/calendarspec.c
@@ -1352,7 +1352,12 @@ int calendar_spec_next_usec(const CalendarSpec *spec, usec_t usec, usec_t *ret_n
return r;
}
if (r == 0) {
- if (setenv("TZ", spec->timezone, 1) != 0) {
+ char *colon_tz;
+
+ /* tzset(3) says $TZ should be prefixed with ":" if we reference timezone files */
+ colon_tz = strjoina(":", spec->timezone);
+
+ if (setenv("TZ", colon_tz, 1) != 0) {
shared->return_value = negative_errno();
_exit(EXIT_FAILURE);
}
diff --git a/src/test/test-calendarspec.c b/src/test/test-calendarspec.c
index 899e4b5d27..9c2be7f445 100644
--- a/src/test/test-calendarspec.c
+++ b/src/test/test-calendarspec.c
@@ -43,9 +43,12 @@ static void test_next(const char *input, const char *new_tz, usec_t after, usec_
if (old_tz)
old_tz = strdupa(old_tz);
- if (new_tz)
- assert_se(setenv("TZ", new_tz, 1) >= 0);
- else
+ if (new_tz) {
+ char *colon_tz;
+
+ colon_tz = strjoina(":", new_tz);
+ assert_se(setenv("TZ", colon_tz, 1) >= 0);
+ } else
assert_se(unsetenv("TZ") >= 0);
tzset();
diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c
index d05bb61429..a422cc8ddc 100644
--- a/src/test/test-time-util.c
+++ b/src/test/test-time-util.c
@@ -475,7 +475,7 @@ static void test_in_utc_timezone(void) {
assert_se(timezone == 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(streq(tzname[0], "CET"));
assert_se(streq(tzname[1], "CEST"));
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index 2f9073c3dc..2a98c48987 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -46,7 +46,7 @@ typedef struct StatusInfo {
} StatusInfo;
static void print_status_info(const StatusInfo *i) {
- const char *old_tz = NULL, *tz;
+ const char *old_tz = NULL, *tz, *tz_colon;
bool have_time = false;
char a[LINE_MAX];
struct tm tm;
@@ -62,7 +62,8 @@ static void print_status_info(const StatusInfo *i) {
old_tz = strdupa(tz);
/* Set the new $TZ */
- if (setenv("TZ", isempty(i->timezone) ? "UTC" : i->timezone, true) < 0)
+ tz_colon = strjoina(":", isempty(i->timezone) ? "UTC" : i->timezone);
+ if (setenv("TZ", tz_colon, true) < 0)
log_warning_errno(errno, "Failed to set TZ environment variable, ignoring: %m");
else
tzset();