From: Harlan Stenn Date: Fri, 23 Jul 1999 07:16:36 +0000 (-0000) Subject: Many files: X-Git-Tag: NTP_4_0_94b~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab2e5abce08da846302795913a4e8e191a7d4034;p=thirdparty%2Fntp.git Many files: * include/ntpd.h: * libntp/machines.c: * libntp/systime.c: * ntpd/ntp_config.c: * ntpd/ntp_filegen.c: * ntpd/ntp_io.c: * ntpd/ntp_proto.c: * ntpd/ntp_timer.c: * ntpdate/ntpdate.c: Windows NT port cleanup From: Sven Dietrich bk: 379816d4esxguXafr-PFroOUCCmWHQ --- diff --git a/ChangeLog b/ChangeLog index 595637402..0f0008d19 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +1999-07-23 Harlan Stenn + + * include/ntpd.h: + * libntp/machines.c: + * libntp/systime.c: + * ntpd/ntp_config.c: + * ntpd/ntp_filegen.c: + * ntpd/ntp_io.c: + * ntpd/ntp_proto.c: + * ntpd/ntp_timer.c: + * ntpdate/ntpdate.c: Windows NT port cleanup + From: Sven Dietrich + 1999-07-22 Harlan Stenn * libntp/authkeys.c: diff --git a/include/ntpd.h b/include/ntpd.h index d5fd71731..9a3b929b7 100644 --- a/include/ntpd.h +++ b/include/ntpd.h @@ -19,13 +19,6 @@ void service_main (DWORD, LPTSTR *); void service_ctrl (DWORD); void worker_thread (void *); #define sleep(x) Sleep((DWORD) x * 1000 /* milliseconds */ ); -#define TARGET_RESOLUTION 1 /* Try for 1-millisecond accuracy. - * used in ntp_timer.c - */ -extern DWORD units_per_tick; -extern long adj_precision; -extern HANDLE ResolverThreadHandle; -extern HANDLE hMutex; #else #define closesocket close #endif /* SYS_WINNT */ @@ -233,14 +226,6 @@ extern u_long numasyncmsgs; /* number of async messages we've sent */ extern u_long req_keyid; /* request keyid */ extern char * req_file; /* name of the file with configuration info */ -/* ntp_io.c */ -/* - * Memory allocation - */ -extern volatile u_long full_recvbufs; /* number of recvbufs on fulllist */ -extern volatile u_long free_recvbufs; /* number of recvbufs on freelist */ -extern u_long total_recvbufs; /* total recvbufs currently in use */ - /* * Other statistics of possible interest */ diff --git a/libntp/machines.c b/libntp/machines.c index 662ed4701..9f64d8feb 100644 --- a/libntp/machines.c +++ b/libntp/machines.c @@ -86,7 +86,7 @@ struct servent *getservbyname (char *name, char *type) /* & it prescales by 32, thus 4 usec */ /* on mv167, granularity is 1usec anyway*/ /* To defeat rounding, set to 1 */ -#define USECS_PER_SEC 1000000L /* Microseconds per second */ +#define USECS_PER_SEC MILLION /* Microseconds per second */ #define TICK (((USECS_PER_SEC / CLKRATE) / CLK_GRANULARITY) * CLK_GRANULARITY) /* emulate unix sleep @@ -205,233 +205,9 @@ settimeofday_NT( } return 0; } -#endif - -#else /* SYS_WINNT */ - - -#include -#include -#include "ntp_syslog.h" - -char * set_tod_using = "SetSystemTime"; - -/* Windows NT versions of gettimeofday and settimeofday - * - * ftime() has internal DayLightSavings related BUGS - * therefore switched to GetSystemTimeAsFileTime() - */ - -/* 100ns intervals between 1/1/1601 and 1/1/1970 as reported by - * SystemTimeToFileTime() - */ - -#define FILETIME_1970 0x019db1ded53e8000 -#define HECTONANOSECONDS 10000000ui64 - -static LONGLONG PerfFrequency = 0; -static LONGLONG LastTimerCount = 0; -static ULONGLONG LastTimerTime = 0; -static CRITICAL_SECTION TimerCritialSection; /* lock for LastTimerCount & LastTimerTime */ - - -int -gettimeofday( - struct timeval *tv - ) -{ - /* Use the system time (roughly synchronised to the tick, and - * extrapolated using the system performance counter. - */ - - ULONGLONG Count; - ULONGLONG Time; - LARGE_INTEGER LargeIntNowCount; - ULONGLONG NowCount; - ULONGLONG TicksElapsed; - - /* Mark a mark ASAP. The latency to here should - * be reasonably deterministic - */ - if (!QueryPerformanceCounter(&LargeIntNowCount)) { - msyslog(LOG_ERR, "QueryPeformanceCounter failed: %m"); - exit(1); - } - NowCount = LargeIntNowCount.QuadPart; - - /* Get base time we are going to extrapolate from - */ - EnterCriticalSection(&TimerCritialSection); - { - Count = LastTimerCount; - Time = LastTimerTime; - } - LeaveCriticalSection(&TimerCritialSection); - - printf ("Count %I64d\n", Count); - - /* Caclulate when now is. - * - * Result = LastTimerTime + (NowCount - LastTimerCount) / PerfFrequency - */ - if (NowCount >= Count) { - TicksElapsed = NowCount - Count; /* linear progression of ticks */ - } - else { - TicksElapsed = NowCount + 1 + ~Count; /* tick counter has wrapped around - I don't think this will ever happen*/ - } - - /* Calculate the new time (in 100's of nano-seconds) - */ - Time += ((TicksElapsed * HECTONANOSECONDS) / PerfFrequency); - - - /* Convert the hecto-nano second time to tv format - */ - Time -= FILETIME_1970; - tv->tv_sec = (LONG) ( Time / 10000000ui64); - tv->tv_usec = (LONG) (( Time % 10000000ui64) / 10); - return 0; -} - - -static void CALLBACK -TimerApcFunction( - LPVOID lpArgToCompletionRoutine, - DWORD dwTimerLowValue, - DWORD dwTimerHighValue - ) -{ - LARGE_INTEGER LargeIntNowCount; - ULARGE_INTEGER Time; - (void) lpArgToCompletionRoutine; /* not used */ - - if (QueryPerformanceCounter(&LargeIntNowCount)) { - - /* Fill in the data - */ - Time.u.LowPart = dwTimerLowValue; - Time.u.HighPart = dwTimerHighValue; - - EnterCriticalSection(&TimerCritialSection); - { - LastTimerCount = LargeIntNowCount.QuadPart; - LastTimerTime = Time.QuadPart; - } - LeaveCriticalSection(&TimerCritialSection); - } -} - - - +#endif /* SYS_CYGWIN32 */ -static HANDLE ClockThreadHandle = NULL; -static HANDLE TimerThreadExitRequest = NULL; - -DWORD WINAPI ClockThread(void *arg) -{ - LARGE_INTEGER DueTime; - HANDLE WaitableTimerHandle = CreateWaitableTimer(NULL, FALSE, NULL); - - (void) arg; /* not used */ - - if (WaitableTimerHandle != NULL) { - DueTime.QuadPart = 0i64; - if (SetWaitableTimer(WaitableTimerHandle, &DueTime, 10L /* ms */, TimerApcFunction, &WaitableTimerHandle, FALSE) != NO_ERROR) { - for(;;) { - if (WaitForSingleObjectEx(TimerThreadExitRequest, INFINITE, TRUE) == WAIT_OBJECT_0) { - break; /* we've been asked to exit */ - } - } - } - CloseHandle(WaitableTimerHandle); - WaitableTimerHandle = NULL; - } - return 0; -} - -static void StartClockThread(void) -{ - DWORD tid; - FILETIME StartTime; - LARGE_INTEGER Freq = { 0, 0 }; - - /* get the performance counter freq*/ - if (QueryPerformanceFrequency(&Freq)) { - PerfFrequency = Freq.QuadPart; - } - - /* init variables with the time now */ - GetSystemTimeAsFileTime(&StartTime); - LastTimerTime = (((ULONGLONG) StartTime.dwHighDateTime) << 32) + (ULONGLONG) StartTime.dwLowDateTime; - - /* init sync objects */ - InitializeCriticalSection(&TimerCritialSection); - TimerThreadExitRequest = CreateEvent(NULL, FALSE, FALSE, NULL); - ClockThreadHandle = CreateThread(NULL, 0, ClockThread, NULL, 0, &tid); - if (ClockThreadHandle != NULL) { - /* remober the thread priority is only within the process class */ - if (!SetThreadPriority(ClockThreadHandle, THREAD_PRIORITY_TIME_CRITICAL)) { - printf("Error setting thread priority\n"); - } - } -} - -static void StopClockThread(void) -{ - if (SetEvent(TimerThreadExitRequest) && - WaitForSingleObject(ClockThreadHandle, 10000L) == 0) { - CloseHandle(TimerThreadExitRequest); - TimerThreadExitRequest = NULL; - - CloseHandle(ClockThreadHandle); - ClockThreadHandle = NULL; - - DeleteCriticalSection(&TimerCritialSection); - } -} - -typedef void (__cdecl *CRuntimeFunction)(void); - -#pragma data_seg(".CRT$XIY") - CRuntimeFunction _StartClockThread = StartClockThread; -#pragma data_seg(".CRT$XTY") - CRuntimeFunction _StopClockThread = StopClockThread; -#pragma data_seg() /* reset */ - - -int -ntp_set_tod( - struct timeval *tv, - void *tzp - ) -{ - SYSTEMTIME st; - struct tm *gmtm; - long x = tv->tv_sec; - long y = tv->tv_usec; - (void) tzp; - - gmtm = gmtime((const time_t *) &x); - st.wSecond = (WORD) gmtm->tm_sec; - st.wMinute = (WORD) gmtm->tm_min; - st.wHour = (WORD) gmtm->tm_hour; - st.wDay = (WORD) gmtm->tm_mday; - st.wMonth = (WORD) (gmtm->tm_mon + 1); - st.wYear = (WORD) (gmtm->tm_year + 1900); - st.wDayOfWeek = (WORD) gmtm->tm_wday; - st.wMilliseconds = (WORD) (y / 1000); - - if (!SetSystemTime(&st)) { - msyslog(LOG_ERR, "SetSystemTime failed: %m\n"); - return -1; - } - return 0; -} - - - -#endif /* SYS_WINNT */ +#endif /* not SYS_WINNT */ #if defined (SYS_WINNT) || defined (SYS_VXWORKS) /* getpass is used in ntpq.c and ntpdc.c */ @@ -441,9 +217,10 @@ getpass(const char * prompt) { int c, i; static char password[32]; - +#ifdef DEBUG fprintf(stderr, "%s", prompt); fflush(stderr); +#endif for (i=0; i 1) + printf("SetSystemTimeAdjustment( %ld)\n", dwTimeAdjustment); +# endif + rc = !SetSystemTimeAdjustment(dwTimeAdjustment, FALSE); + } + else rc = 0; + if (rc) +#else /* * Here we do the actual adjustment. If for some reason the adjtime() * call fails, like it is not implemented or something like that, * we honk to the log. If the previous adjustment did not complete, * we correct the residual offset. */ -#if !defined (SYS_WINNT) && !defined (SYS_CYGWIN32) /* casey - we need a posix type thang here */ if (adjtime(&adjtv, &oadjtv) < 0) -#else - if (debug) { - printf("SetSystemTimeAdjustment( %ld)\n", dwTimeAdjustment); - } - if (!SetSystemTimeAdjustment(dwTimeAdjustment, FALSE)) #endif /* SYS_WINNT */ { msyslog(LOG_ERR, "Can't adjust time: %m"); @@ -203,11 +213,13 @@ adj_systime( else { #if !defined (SYS_WINNT) && !defined (SYS_CYGWIN32) sys_residual += oadjtv.tv_usec / 1e6; +#else + sys_residual = dtemp / 1000000.0; #endif /* SYS_WINNT */ } #ifdef DEBUG if (debug > 6) - printf("adj_systime: adj %.6f -> remaining residual %.6f\n", now, sys_residual); + printf("adj_systime: adj %.9lf -> remaining residual %.9lf\n", now, sys_residual); #endif return 1; } diff --git a/ntpd/ntp_config.c b/ntpd/ntp_config.c index 7b5155be0..cec82b66d 100644 --- a/ntpd/ntp_config.c +++ b/ntpd/ntp_config.c @@ -25,6 +25,7 @@ #ifdef SYS_WINNT #include +extern HANDLE ResolverThreadHandle; #endif /* SYS_WINNT */ /* diff --git a/ntpd/ntp_filegen.c b/ntpd/ntp_filegen.c index 80b9000b9..445c3d049 100644 --- a/ntpd/ntp_filegen.c +++ b/ntpd/ntp_filegen.c @@ -242,18 +242,16 @@ filegen_open( */ /* Windows NT does not support file links -Greg Schueman 1/18/97 */ - -#if defined(VMS) || defined(SYS_WINNT) || defined(SYS_VXWORKS) -# ifdef VMS - errno = 0; /* On VMS, don't support FGEN_FLAG_LINK */ -# else /* SYS_WINNT */ + +#if defined SYS_WINNT || defined SYS_VXWORKS SetLastError(0); /* On WinNT, don't support FGEN_FLAG_LINK */ -# endif /* SYS_WINNT */ -#else /* not (VMS || SYS_WINNT) */ +#elif defined(VMS) + errno = 0; /* On VMS, don't support FGEN_FLAG_LINK */ +#else /* not (VMS) / VXWORKS / WINNT ; DO THE LINK) */ if (link(filename, basename) != 0) if (errno != EEXIST) -#endif /* not (VMS || SYS_WINNT) */ msyslog(LOG_ERR, "can't link(%s, %s): %m", filename, basename); +#endif /* SYS_WINNT || VXWORKS */ } /* flags & FGEN_FLAG_LINK */ } /* else fp == NULL */ diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index e94378e45..1c2d37dcf 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -7,8 +7,6 @@ # include #endif -/* Modified by Sven 7/14/99 322pm */ - #include #include #include diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index 61f465441..6fec8e30c 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -1916,29 +1916,7 @@ default_get_precision(void) #if defined(__FreeBSD__) && __FreeBSD__ >= 3 u_long freq; int j; -#endif - -#if defined SYS_WINNT || defined SYS_CYGWIN32 - DWORD every; - BOOL noslew; - LARGE_INTEGER freq; - - if (GetSystemTimeAdjustment(&units_per_tick, &every, &noslew)) { - adj_precision = 1000000L / (long)every; - } - - if (QueryPerformanceFrequency(&freq)) { - int i; - for (i = 1; freq.QuadPart ; i--) { - freq.QuadPart >>= 1; - } - return (i); - } - -#endif - -#if defined(__FreeBSD__) && __FreeBSD__ >= 3 /* Try to see if we can find the frequency of of the counter * which drives our timekeeping */ diff --git a/ntpd/ntp_timer.c b/ntpd/ntp_timer.c index 8f1c3e236..57ea5c47f 100644 --- a/ntpd/ntp_timer.c +++ b/ntpd/ntp_timer.c @@ -83,7 +83,7 @@ void init_timer(void) { #if !defined(VMS) -# ifndef SYS_WINNT +# if !defined SYS_WINNT || defined(SYS_CYGWIN32) # ifndef HAVE_TIMER_SETTIME struct itimerval itimer; # else @@ -91,15 +91,10 @@ init_timer(void) /* to kill timer without rebooting ... */ struct itimerspec itimer; # endif /* HAVE_TIMER_SETTIME */ -# endif /* !SYS_WINNT */ -# if defined(SYS_CYGWIN32) || defined(SYS_WINNT) - TIMECAPS tc; - UINT wTimerRes, wTimerID; -# endif /* SYS_WINNT */ -# if defined(SYS_CYGWIN32) || defined(SYS_WINNT) +# else /* SYS_WINNT */ HANDLE hToken; TOKEN_PRIVILEGES tkp; -# endif +# endif /* SYS_WINNT */ #endif /* !VMS */ /* diff --git a/ntpdate/ntpdate.c b/ntpdate/ntpdate.c index 4ee283f66..f1bc0c6dd 100644 --- a/ntpdate/ntpdate.c +++ b/ntpdate/ntpdate.c @@ -1614,15 +1614,13 @@ sendpkt( #ifndef SYS_WINNT if (cc == -1) { if (errno != EWOULDBLOCK && errno != ENOBUFS) - msyslog(LOG_ERR, "sendto(%s): %m", ntoa(dest)); - } #else if (cc == SOCKET_ERROR) { err = WSAGetLastError(); if (err != WSAEWOULDBLOCK && err != WSAENOBUFS) +#endif /* SYS_WINNT */ msyslog(LOG_ERR, "sendto(%s): %m", ntoa(dest)); } -#endif /* SYS_WINNT */ }