Minimize clock drift between getting and setting time

Submitted by: bde
This commit is contained in:
Andrey A. Chernov 1998-02-25 09:40:21 +00:00
parent e978f41536
commit 57394688f8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=33831

View file

@ -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 @@ int main(argc, argv)
#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 @@ int main(argc, argv)
}
}
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 */