From 1ef6feb533ec7f45e6264189ad7ed93f616564ea Mon Sep 17 00:00:00 2001 From: J William Piggott Date: Sun, 30 Jul 2017 16:22:49 -0400 Subject: hwclock: correlate hclocktime instead of set_time. 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 --- sys-utils/hwclock.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'sys-utils/hwclock.c') diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c index e172fb1bf..df6b59e86 100644 --- a/sys-utils/hwclock.c +++ b/sys-utils/hwclock.c @@ -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, -- cgit v1.2.3-55-g7522