summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Landden <shawn@churchofgit.com>2013-12-12 10:00:03 -0800
committerLennart Poettering <lennart@poettering.net>2013-12-12 20:00:45 +0100
commit9ff09bcb86fb125768667aca9bc0b10b1745370a (patch)
tree4ad6667f4616ee5f691af30330496dab8fb895df
parent189b2384d6d2f049fe84ac88d7b85d03d277561f (diff)
timedatectl: work with old timedated
Which does have TimeUSec. Should we specifically check for this method instead of assuming time=0 means it doesn't exist? Before: shawn@debian-T61:~/git/systemd$ ./timedatectl Local time: Wed 1969-12-31 16:00:00 PST Universal time: Thu 1970-01-01 00:00:00 UTC RTC time: n/a Timezone: America/Los_Angeles (PST, -0800) NTP enabled: n/a NTP synchronized: no RTC in local TZ: no DST active: no Last DST change: DST ended at Sun 1969-10-26 01:59:59 PDT Sun 1969-10-26 01:00:00 PST Next DST change: DST begins (the clock jumps one hour forward) at Sun 1970-04-26 01:59:59 PST Sun 1970-04-26 03:00:00 PDT After: shawn@debian-T61:~/git/systemd$ ./timedatectl Local time: Wed 2013-12-11 14:03:21 PST Universal time: Wed 2013-12-11 22:03:21 UTC RTC time: n/a Timezone: America/Los_Angeles (PST, -0800) NTP enabled: n/a NTP synchronized: no RTC in local TZ: no DST active: no Last DST change: DST ended at Sun 2013-11-03 01:59:59 PDT Sun 2013-11-03 01:00:00 PST Next DST change: DST begins (the clock jumps one hour forward) at Sun 2014-03-09 01:59:59 PST Sun 2014-03-09 03:00:00 PDT
-rw-r--r--src/timedate/timedatectl.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index 9b81513c75..2c24b78458 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -98,6 +98,7 @@ static void print_status_info(const StatusInfo *i) {
char s[32];
struct tm tm;
time_t sec;
+ bool have_time = false;
char *zc, *zn;
time_t t, tc, tn;
int dn;
@@ -112,17 +113,29 @@ static void print_status_info(const StatusInfo *i) {
unsetenv("TZ");
}
- sec = (time_t) (i->time / USEC_PER_SEC);
+ if (i->time != 0) {
+ sec = (time_t) (i->time / USEC_PER_SEC);
+ have_time = true;
+ } else if (arg_transport == BUS_TRANSPORT_LOCAL) {
+ sec = time(NULL);
+ have_time = true;
+ } else
+ fprintf(stderr, "Warning: could not get time from timedated and not operating locally.\n\n");
- zero(tm);
- assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&sec, &tm)) > 0);
- char_array_0(a);
- printf(" Local time: %s\n", a);
+ if (have_time) {
+ zero(tm);
+ assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S %Z", localtime_r(&sec, &tm)) > 0);
+ char_array_0(a);
+ printf(" Local time: %s\n", a);
- zero(tm);
- assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S UTC", gmtime_r(&sec, &tm)) > 0);
- char_array_0(a);
- printf(" Universal time: %s\n", a);
+ zero(tm);
+ assert_se(strftime(a, sizeof(a), "%a %Y-%m-%d %H:%M:%S UTC", gmtime_r(&sec, &tm)) > 0);
+ char_array_0(a);
+ printf(" Universal time: %s\n", a);
+ } else {
+ printf(" Local time: %s\n", "n/a");
+ printf(" Universal time: %s\n", "n/a");
+ }
if (i->rtc_time > 0) {
time_t rtc_sec;
@@ -133,7 +146,7 @@ static void print_status_info(const StatusInfo *i) {
char_array_0(a);
printf(" RTC time: %s\n", a);
} else
- printf(" RTC time: n/a\n");
+ printf(" RTC time: %s\n", "n/a");
zero(tm);
assert_se(strftime(a, sizeof(a), "%Z, %z", localtime_r(&sec, &tm)) > 0);
@@ -151,8 +164,8 @@ static void print_status_info(const StatusInfo *i) {
&tc, &zc, &is_dstc,
&tn, &dn, &zn, &is_dstn);
if (r < 0)
- printf(" DST active: n/a\n");
- else {
+ printf(" DST active: %s\n", "n/a");
+ else if (have_time) {
printf(" DST active: %s\n", yes_no(is_dstc));
t = tc - 1;
@@ -183,7 +196,8 @@ static void print_status_info(const StatusInfo *i) {
free(zc);
free(zn);
- }
+ } else
+ printf(" DST active: %s\n", yes_no(is_dstc));
if (i->rtc_local)
fputs("\n" ANSI_HIGHLIGHT_ON