summaryrefslogtreecommitdiffstats
path: root/sbin/adjkerntz
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1998-02-25 09:40:21 +0000
committerache <ache@FreeBSD.org>1998-02-25 09:40:21 +0000
commit0398ae2bf7418f729f8b0d22fb08c26557242cb4 (patch)
tree8f218e487c4563557e1c9a7335e0a42170413a4a /sbin/adjkerntz
parentdd04474345429a111f490c7982f1a882e64af161 (diff)
downloadFreeBSD-src-0398ae2bf7418f729f8b0d22fb08c26557242cb4.zip
FreeBSD-src-0398ae2bf7418f729f8b0d22fb08c26557242cb4.tar.gz
Minimize clock drift between getting and setting time
Submitted by: bde
Diffstat (limited to 'sbin/adjkerntz')
-rw-r--r--sbin/adjkerntz/adjkerntz.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/sbin/adjkerntz/adjkerntz.c b/sbin/adjkerntz/adjkerntz.c
index f92ea56..e7ad4a7 100644
--- a/sbin/adjkerntz/adjkerntz.c
+++ b/sbin/adjkerntz/adjkerntz.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id$
+ * $Id: adjkerntz.c,v 1.20 1997/06/10 11:01:13 charnier Exp $
*/
#ifndef lint
@@ -257,8 +257,10 @@ recalculate:
#ifdef DEBUG
fprintf(stderr, "Final diff: %ld secs\n", diff);
#endif
- tv.tv_sec += diff;
- tv.tv_usec = 0; /* we are restarting here... */
+ /*
+ * stv is abused as a flag. The important value
+ * is in `diff'.
+ */
stv = &tv;
}
}
@@ -293,13 +295,28 @@ recalculate:
}
}
- if ( ( (init && (stv != NULL || stz != NULL))
- || (stz != NULL && stv == NULL)
- )
- && settimeofday(stv, stz)
+ if ( (init && (stv != NULL || stz != NULL))
+ || (stz != NULL && stv == NULL)
) {
- syslog(LOG_ERR, "settimeofday: %m");
- return 1;
+ if (stv != NULL) {
+ /*
+ * Get the time again, as close as possible to
+ * adjusting it, to minimise drift.
+ * XXX we'd better not fail between here and
+ * restoring disrtcset, since we don't clean up
+ * anything.
+ */
+ if (gettimeofday(&tv, (struct timezone *)NULL)) {
+ syslog(LOG_ERR, "gettimeofday: %m");
+ return 1;
+ }
+ tv.tv_sec += diff;
+ stv = &tv;
+ }
+ if (settimeofday(stv, stz)) {
+ syslog(LOG_ERR, "settimeofday: %m");
+ return 1;
+ }
}
/* setting CPU_ADJKERNTZ have a side effect: resettodr(), which */
OpenPOWER on IntegriCloud