From: Harlan Stenn Date: Thu, 19 Aug 1999 03:08:18 +0000 (-0000) Subject: Many files: X-Git-Tag: NTP_4_0_97~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=195ccbe4642a0c2f342ca35720088a0ebebd1baa;p=thirdparty%2Fntp.git Many files: Convert NT files to Unix EOLs; a CVS checkout on an NT box will DTRT. * libntp/systime.c: * ntpd/ntp_loopfilter.c: * ntpd/ntpd.c: * ports/winnt/libntp/nt_clockstuff.c: From: Sven Dietrich bk: 37bb7522c3tVaTpFpJHoo-44nFYucw --- diff --git a/ChangeLog b/ChangeLog index bcdacbf00..bcf05c37e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 1999-08-18 Harlan Stenn + * libntp/systime.c: + * ntpd/ntp_loopfilter.c: + * ntpd/ntpd.c: + * ports/winnt/libntp/nt_clockstuff.c: + From: Sven Dietrich + * README.cvs: Updated. * configure.in: diff --git a/NEWS b/NEWS index 99d7406e1..99aec7b15 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +* NT patches +* AIX,SunOS,IRIX portability * NeXT portability * ntptimeset utility added * cygwin portability patches diff --git a/libntp/systime.c b/libntp/systime.c index 258e3b010..5e9d39fed 100644 --- a/libntp/systime.c +++ b/libntp/systime.c @@ -45,6 +45,7 @@ double sys_maxfreq = MAXFREQ; /* max frequency correction */ #if defined SYS_WINNT || defined SYS_CYGWIN32 static long last_Adj = 0; +extern DWORD units_per_tick; /*long adj_precision = (long)(HZ * 0.1); */ /* adj precision in usec (tickadj) */ #endif /* SYS_WINNT */ @@ -183,7 +184,7 @@ adj_systime( * and leave the remainder in dtemp */ dwTimeAdjustment = dtemp / 10; dtemp += (double) -dwTimeAdjustment * 10.0; - dwTimeAdjustment += PRESET_TICK; + dwTimeAdjustment += units_per_tick; /* only adjust the clock if adjustment changes */ if (last_Adj != dwTimeAdjustment) { diff --git a/ntpd/ntp_loopfilter.c b/ntpd/ntp_loopfilter.c index c2632a9b5..a501931e6 100644 --- a/ntpd/ntp_loopfilter.c +++ b/ntpd/ntp_loopfilter.c @@ -194,13 +194,14 @@ local_clock( /* * If the clock is way off, don't tempt fate by correcting it. */ +#ifndef SYS_WINNT if (fabs(fp_offset) >= clock_panic && !correct_any) { - msyslog(LOG_ERR, + msyslog(LOG_ERR, "time error %.0f over %d seconds; set clock manually)", fp_offset, (int)clock_panic); return (-1); } - +#endif /* * If the clock has never been set, set it and initialize the * discipline parameters. We then switch to frequency mode to diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index 7cfa01d9a..dc7db8214 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -1061,11 +1061,6 @@ service_exit( int status ) { - /* restore the clock frequency back to its original value */ - if (!SetSystemTimeAdjustment((DWORD)0, TRUE)) { - msyslog(LOG_ERR, "Failed to reset clock frequency, SetSystemTimeAdjustment(): %m"); - } - if (!debug) { /* did not become a service, simply exit */ /* service mode, need to have the service_main routine * register with the service control manager that the diff --git a/ports/winnt/libntp/nt_clockstuff.c b/ports/winnt/libntp/nt_clockstuff.c index 557b19295..5d0567383 100644 --- a/ports/winnt/libntp/nt_clockstuff.c +++ b/ports/winnt/libntp/nt_clockstuff.c @@ -1,5 +1,3 @@ - - #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -13,6 +11,8 @@ char * set_tod_using = "SetSystemTime"; extern double drift_comp; +DWORD units_per_tick; +static DWORD initial_units_per_tick; /* Windows NT versions of gettimeofday and settimeofday * @@ -77,7 +77,7 @@ gettimeofday( } else { TicksElapsed = NowCount + 1 + ~Count; /* tick counter has wrapped around - I don't think this will ever happen*/ - msyslog(LOG_INFO, "Wraparound %m"); + msyslog(LOG_INFO, "Wraparound %d -> %d%m", Count, NowCount); } @@ -120,12 +120,11 @@ TimerApcFunction( DWORD WINAPI ClockThread(void *arg) { + LARGE_INTEGER DueTime; HANDLE WaitableTimerHandle = CreateWaitableTimer(NULL, FALSE, NULL); (void) arg; /* not used */ - /* Reset the Clock to a reasonable increment */ - SetSystemTimeAdjustment(PRESET_TICK, FALSE); if (WaitableTimerHandle != NULL) { DueTime.QuadPart = 0i64; @@ -147,12 +146,27 @@ static void StartClockThread(void) DWORD tid; FILETIME StartTime; LARGE_INTEGER Freq = { 0, 0 }; + DWORD every; + BOOL noslew; + /* Reset the Clock to a reasonable increment */ + if (!GetSystemTimeAdjustment(&initial_units_per_tick, &every, &noslew)) { + msyslog(LOG_ERR, "GetSystemTimeAdjustment failed: %m\n"); + exit (-1); + } + + units_per_tick = initial_units_per_tick; + + msyslog(LOG_INFO, "Initial Clock increment %d\n", + units_per_tick); /* get the performance counter freq*/ - if (QueryPerformanceFrequency(&Freq)) { - PerfFrequency = Freq.QuadPart; + if (!QueryPerformanceFrequency(&Freq)) { + msyslog(LOG_ERR, "QueryPerformanceFrequency failed: %m\n"); + exit (-1); } + PerfFrequency = Freq.QuadPart; + /* init variables with the time now */ GetSystemTimeAsFileTime(&StartTime); LastTimerTime = (((ULONGLONG) StartTime.dwHighDateTime) << 32) + (ULONGLONG) StartTime.dwLowDateTime; @@ -181,6 +195,11 @@ static void StopClockThread(void) DeleteCriticalSection(&TimerCritialSection); } + + /* restore the clock frequency back to its original value */ + if (!SetSystemTimeAdjustment(initial_units_per_tick, TRUE)) { + msyslog(LOG_ERR, "Failed to reset clock frequency, SetSystemTimeAdjustment(): %m"); + } } typedef void (__cdecl *CRuntimeFunction)(void);