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
}
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);
}
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);
}
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();
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"));
} 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;
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();