[systemd-devel] [PATCH] timedatectl: work with old timedated

Shawn Landden shawn at churchofgit.com
Wed Dec 11 14:04:10 PST 2013


Which does have TimeUSec. Should we specifically check for this method
instead of assuming time=0 means it doesn't exist?

Before:
shawn at 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 at 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
---
 src/timedate/timedatectl.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index 9b81513..7dba8e9 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -106,14 +106,19 @@ static void print_status_info(const StatusInfo *i) {
 
         assert(i);
 
+        if (i->time)
+                sec = (time_t) (i->time / USEC_PER_SEC);
+        else if (arg_transport == BUS_TRANSPORT_LOCAL)
+                sec = time(NULL);
+        else
+                return (void)fprintf(stderr, "Could not get time from timedated and not operating locally.\n\n");
+
         /* Enforce the values of /etc/localtime */
         if (getenv("TZ")) {
                 fprintf(stderr, "Warning: ignoring the TZ variable, reading the system's timezone setting only.\n\n");
                 unsetenv("TZ");
         }
 
-        sec = (time_t) (i->time / USEC_PER_SEC);
-
         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);
-- 
1.8.5.1



More information about the systemd-devel mailing list