mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-06 17:18:32 +00:00
Minimize clock drift between getting and setting time
Submitted by: bde
This commit is contained in:
parent
e978f41536
commit
57394688f8
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=33831
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue