From: Brian Utterback Date: Fri, 15 Aug 2003 18:18:53 +0000 (-0400) Subject: ntp_timer.c, ntp_loopfilter.c, ntpd.h: X-Git-Tag: NTP_4_2_0~12 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=155f36e87f08a2561e23ab3520ca2b782e8e00f3;p=thirdparty%2Fntp.git ntp_timer.c, ntp_loopfilter.c, ntpd.h: Reinitialize the interval timer after stepping the clock. The behavior of the timer after a clock step is not addressed by POSIX and is undefined, so the safest course is to reintitialize it when we step the clock. Solaris, for one, is known to stop triggering the timer after a step backward until the system clock "catches up". bk: 3f3d240d8rI8i0AI39m1iUiTK6Jo7w --- diff --git a/include/ntpd.h b/include/ntpd.h index a09ac1b9cb..34bedce25d 100644 --- a/include/ntpd.h +++ b/include/ntpd.h @@ -192,6 +192,7 @@ extern void hack_restrict P((int, struct sockaddr_storage *, struct sockaddr_sto /* ntp_timer.c */ extern void init_timer P((void)); +extern void reinit_timer P((void)); extern void timer P((void)); extern void timer_clr_stats P((void)); #ifdef OPENSSL diff --git a/ntpd/ntp_loopfilter.c b/ntpd/ntp_loopfilter.c index f59f77091d..99d1cc4824 100644 --- a/ntpd/ntp_loopfilter.c +++ b/ntpd/ntp_loopfilter.c @@ -285,6 +285,7 @@ local_clock( step_systime(fp_offset); msyslog(LOG_NOTICE, "time reset %+.6f s", fp_offset); + reinit_timer(); } rstclock(S_FREQ, peer->epoch, 0); return (1); @@ -393,6 +394,7 @@ local_clock( step_systime(fp_offset); msyslog(LOG_NOTICE, "time reset %+.6f s", fp_offset); + reinit_timer(); rstclock(S_TSET, peer->epoch, 0); retval = 1; break; diff --git a/ntpd/ntp_timer.c b/ntpd/ntp_timer.c index ad8c15e207..e33b48bab3 100644 --- a/ntpd/ntp_timer.c +++ b/ntpd/ntp_timer.c @@ -79,6 +79,43 @@ static HANDLE WaitableTimerHandle = NULL; static RETSIGTYPE alarming P((int)); #endif /* SYS_WINNT */ +#if !defined(VMS) +# if !defined SYS_WINNT || defined(SYS_CYGWIN32) +# ifndef HAVE_TIMER_SETTIME + struct itimerval itimer; +# else + static timer_t ntpd_timerid; + struct itimerspec itimer; +# endif /* HAVE_TIMER_SETTIME */ +# endif /* SYS_WINNT */ +#endif /* VMS */ + +/* + * reinit_timer - reinitialize interval timer. + */ +void +reinit_timer(void) +{ +#if !defined(SYS_WINNT) && !defined(VMS) +# if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME) + timer_gettime(ntpd_timerid, &itimer); + if (itimer.it_value.tv_sec < 0 || itimer.it_value.tv_sec > (1< (1<