I liked having the DST information. It is a pity glibc doesn't export
this information.
---
src/timedate/timedatectl.c | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index ab5c8a1..8daae54 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -74,7 +74,7 @@ typedef struct StatusInfo {
static void print_status_info(const StatusInfo *i) {
char a[FORMAT_TIMESTAMP_MAX];
- struct tm tm;
+ struct tm localtime, gmtime;
time_t sec;
bool have_time = false;
_cleanup_free_ char *zc = NULL, *zn = NULL;
@@ -84,13 +84,18 @@ static void print_status_info(const StatusInfo *i) {
/* Enforce the values of /etc/localtime */
if (getenv("TZ")) {
- fprintf(stderr, "Warning: Ignoring the TZ variable.\n\n");
+ fprintf(stderr, "Warning: Ignoring the %s variable.\n\n",
"TZ");
unsetenv("TZ");
}
+ if (getenv("TZDIR")) {
+ fprintf(stderr, "Warning: Ignoring the %s variable.\n\n",
"TZDIR");
+ unsetenv("TZDIR");
+ }
+
r = setenv("TZ", i->timezone, false);
if (r < 0) {
- log_error_errno(errno, "Failed to set TZ environment variable:
%m");
+ log_error_errno(errno, "Failed to set %s environment variable:
%m", "TZ");
exit(EXIT_FAILURE);
}
tzset();
@@ -105,27 +110,30 @@ static void print_status_info(const StatusInfo *i) {
fprintf(stderr, "Warning: Could not get time from timedated
and not operating locally.\n\n");
if (have_time) {
- xstrftime(a, "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&sec,
&tm));
+ localtime_r(&sec, &localtime);
+ gmtime_r(&sec, &gmtime);
+
+ xstrftime(a, "%a %Y-%m-%d %H:%M:%S %Z", localtime);
printf(" Local time: %.*s\n", (int) sizeof(a), a);
- xstrftime(a, "%a %Y-%m-%d %H:%M:%S UTC", gmtime_r(&sec, &tm));
+ xstrftime(a, "%a %Y-%m-%d %H:%M:%S UTC", gmtime);
printf(" Universal time: %.*s\n", (int) sizeof(a), a);
} else {
- printf(" Local time: %s\n", "n/a");
- printf(" Universal time: %s\n", "n/a");
+ printf(" Local time: %.*s\n", (int) strlen("n/a"), "n/a");
+ printf(" Universal time: %.*s\n", (int) strlen("n/a"), "n/a");
}
if (i->rtc_time > 0) {
time_t rtc_sec;
rtc_sec = (time_t)(i->rtc_time / USEC_PER_SEC);
- xstrftime(a, "%a %Y-%m-%d %H:%M:%S", gmtime_r(&rtc_sec, &tm));
+ xstrftime(a, "%a %Y-%m-%d %H:%M:%S", gmtime);
printf(" RTC time: %.*s\n", (int) sizeof(a), a);
} else
printf(" RTC time: %s\n", "n/a");
if (have_time)
- xstrftime(a, "%Z, %z", localtime_r(&sec, &tm));
+ xstrftime(a, "%Z, %z", localtime);
printf(" Time zone: %s (%.*s)\n"
" NTP enabled: %s\n"
@@ -142,7 +150,8 @@ static void print_status_info(const StatusInfo *i) {
" mode can not be fully supported. It will
create various problems with time\n"
" zone changes and daylight saving time
adjustments. The RTC time is never updated,\n"
" it relies on external facilities to maintain
it. If at all possible, use\n"
- " RTC in UTC by calling 'timedatectl
set-local-rtc 0'" ANSI_HIGHLIGHT_OFF ".\n", stdout);
+ " RTC in UTC by calling 'timedatectl
set-local-rtc 0'\n
+ " For more details see
http://www.cl.cam.ac.uk/~mgk25/mswish/ut-rtc.html" ANSI_HIGHLIGHT_OFF ".\n",
stdout);
}
static int show_status(sd_bus *bus, char **args, unsigned n) {
--
2.2.1.209.g41e5f3a
_______________________________________________
systemd-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/systemd-devel