]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: correlate hclocktime instead of set_time.
authorJ William Piggott <elseifthen@gmx.com>
Sun, 30 Jul 2017 20:22:49 +0000 (16:22 -0400)
committerJ William Piggott <elseifthen@gmx.com>
Fri, 4 Aug 2017 12:53:44 +0000 (08:53 -0400)
Correlate hclocktime with set_time instead of the other way around,
because set_time is used for timestamps in the adjtime file so it needs
to be unadulterated.

Also create var startup_hclocktime for correlated time.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
sys-utils/hwclock.c

index e172fb1bf42002f9d4d77668a6efa64ba2d8f822..df6b59e863b860b93baf735403eb6ac354e49a90 100644 (file)
@@ -1029,9 +1029,14 @@ manipulate_clock(const struct hwclock_control *ctl, const time_t set_time,
        bool hclock_valid = FALSE;
        /*
         * Tick synchronized time read from the Hardware Clock and
-        * then drift correct for all operations except --show.
+        * then drift corrected for all operations except --show.
         */
-       struct timeval hclocktime = { 0, 0 };
+       struct timeval hclocktime = { 0 };
+       /*
+        * hclocktime correlated to startup_time. That is, what drift
+        * corrected Hardware Clock time would have been at start up.
+        */
+       struct timeval startup_hclocktime = { 0 };
        /* Total Hardware Clock drift correction needed. */
        struct timeval tdrift;
 
@@ -1096,18 +1101,17 @@ manipulate_clock(const struct hwclock_control *ctl, const time_t set_time,
                                     hclocktime.tv_sec, &tdrift);
                if (!ctl->show)
                        hclocktime = time_inc(tdrift, hclocktime.tv_sec);
+
+               startup_hclocktime =
+                time_inc(hclocktime, time_diff(startup_time, read_time));
        }
        if (ctl->show || ctl->get) {
-               display_time(hclock_valid,
-                            time_inc(hclocktime, -time_diff
-                                     (read_time, startup_time)));
+               display_time(hclock_valid, startup_hclocktime);
        } else if (ctl->set) {
                set_hardware_clock_exact(ctl, set_time, startup_time);
                if (!ctl->noadjfile)
-                       adjust_drift_factor(ctl, adjtime,
-                                           time_inc(t2tv(set_time), time_diff
-                                                    (read_time, startup_time)),
-                                           hclock_valid, hclocktime);
+                       adjust_drift_factor(ctl, adjtime, t2tv(set_time),
+                                           hclock_valid, startup_hclocktime);
        } else if (ctl->adjust) {
                if (tdrift.tv_sec > 0 || tdrift.tv_sec < -1)
                        do_adjustment(ctl, adjtime, hclock_valid,