summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--man/systemd.time.xml5
-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
6 files changed, 23 insertions, 11 deletions
diff --git a/man/systemd.time.xml b/man/systemd.time.xml
index c7d5f24b3c..dc1e78a187 100644
--- a/man/systemd.time.xml
+++ b/man/systemd.time.xml
@@ -136,9 +136,8 @@
evaluated relative to the UNIX time epoch 1st Jan, 1970,
00:00.</para>
- <para>Examples for valid timestamps and their normalized form
- (assuming the current time was 2012-11-23 18:15:22 and the timezone
- was UTC+8, for example TZ=Asia/Shanghai):</para>
+ <para>Examples for valid timestamps and their normalized form (assuming the current time was 2012-11-23
+ 18:15:22 and the timezone was UTC+8, for example <literal>TZ=:Asia/Shanghai</literal>):</para>
<programlisting> Fri 2012-11-23 11:12:13 → Fri 2012-11-23 11:12:13
2012-11-23 11:12:13 → Fri 2012-11-23 11:12:13
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();