]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Many files:
authorHarlan Stenn <stenn@ntp.org>
Fri, 23 Jul 1999 07:16:36 +0000 (07:16 -0000)
committerHarlan Stenn <stenn@ntp.org>
Fri, 23 Jul 1999 07:16:36 +0000 (07:16 -0000)
  * 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 <Sven_Dietrich@trimble.com>

bk: 379816d4esxguXafr-PFroOUCCmWHQ

ChangeLog
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

index 595637402235bfc0ac5f0326c86940df69d8df07..0f0008d19f3b200c8841e2472ecb3e4593fa7dfd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+1999-07-23  Harlan Stenn  <stenn@whimsy.udel.edu>
+
+       * 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 <Sven_Dietrich@trimble.com>
+
 1999-07-22  Harlan Stenn  <stenn@whimsy.udel.edu>
 
        * libntp/authkeys.c:
index d5fd71731f0c1bc27e5189f129df85397382a3e4..9a3b929b7b376b8de1343661f3a7febdabee2dab 100644 (file)
@@ -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
  */
index 662ed4701696ac55e243fedb845f4f854ae9a9b1..9f64d8feba25d70a1646256c5cd9b2ef4a6eb447 100644 (file)
@@ -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 <time.h>
-#include <sys\timeb.h>
-#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<sizeof(password)-1 && ((c=_getch())!='\n'); i++) {
                password[i] = c;
        }
index dcb62982036c220adee0be40060402fa0b66d431..258e3b01069accf4d2284ab0c0e4c7f508fbfa32 100644 (file)
@@ -44,16 +44,7 @@ double sys_residual = 0;     /* residual from previous adjustment */
 double sys_maxfreq = MAXFREQ;  /* max frequency correction */
 
 #if defined SYS_WINNT || defined SYS_CYGWIN32
-long tvu_maxslew;                        /* maximum adjust doable in 1 second */
-u_long tsf_maxslew;              /* same as above, as long format */
-l_fp sys_clock_offset;                           /* correction for current system time */
-/*
- * units_per_tick = number of 100 nanosecond units added to the clock at each tick
- * adj_precision  = converts microsecond/second to .1us/N*.1us
- * determined by GetSystemTimeAdjustment() in default_get_precision()
- */
-DWORD units_per_tick;
-long   adj_precision;
+static long last_Adj = 0;
 /*long adj_precision = (long)(HZ * 0.1); */ /* adj precision in usec (tickadj) */
 #endif /* SYS_WINNT */
 
@@ -120,6 +111,7 @@ get_systime(
 
 }
 
+
 /*
  * adj_systime - called once every second to make system time adjustments.
  * Returns 1 if okay, 0 if trouble.
@@ -135,7 +127,8 @@ adj_systime(
 #if !defined SYS_WINNT && !defined SYS_CYGWIN32
        struct timeval oadjtv;
 #else
-   DWORD dwTimeAdjustment;
+       int rc;
+   long dwTimeAdjustment;
 #endif
 
        /*
@@ -172,29 +165,46 @@ adj_systime(
                dtemp = sys_maxfreq;
 #endif /* SCO5_CLOCK */
 
+#ifdef SYS_WINNT
+       dtemp = dtemp * 1000000.0;
+#else
        dtemp = dtemp * 1e6 + .5;
+#endif
        if (isneg)
                dtemp = -dtemp;
        adjtv.tv_sec = 0;
        adjtv.tv_usec = (int32)dtemp;
-#if defined SYS_WINNT || defined SYS_CYGWIN32
-       dwTimeAdjustment = units_per_tick + adjtv.tv_usec / adj_precision;
-#endif /* SYS_WINNT */
 
+#if defined SYS_WINNT || defined SYS_CYGWIN32  
+       /* dtemp is in micro seconds. NT uses 100 ns units,
+        * so a unit change in dwTimeAdjustment corresponds
+        * to slewing 10 ppm. 
+        * Calculate the number of 100ns units to add, 
+        * and leave the remainder in dtemp */
+       dwTimeAdjustment = dtemp / 10;
+       dtemp +=  (double) -dwTimeAdjustment * 10.0;    
+       dwTimeAdjustment += PRESET_TICK;
+
+       /* only adjust the clock if adjustment changes */
+       if (last_Adj != dwTimeAdjustment) {     
+                       last_Adj = dwTimeAdjustment;  
+# ifdef DEBUG
+               if (debug > 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;
 }
index 7b5155be0fcb1236f9676ffe9a167b18405d029d..cec82b66d90e142415aa90fbca6064b442f466c3 100644 (file)
@@ -25,6 +25,7 @@
 
 #ifdef SYS_WINNT
 #include <io.h>
+extern HANDLE ResolverThreadHandle;
 #endif /* SYS_WINNT */
 
 /*
index 80b9000b90b6802fc536a11389607af252cc9c16..445c3d049563906ee1a5d4591b2f6095cbccac3d 100644 (file)
@@ -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 */
        
index e94378e45bda479f52c551e85551df02ba7ff631..1c2d37dcfd0fb6e4070bf233e6bbc8c827d6c403 100644 (file)
@@ -7,8 +7,6 @@
 # include <config.h>
 #endif
 
-/* Modified by Sven 7/14/99 322pm */
-
 #include <stdio.h>
 #include <signal.h>
 #include <errno.h>
index 61f465441000fff35eaf0b999515b4db917597ea..6fec8e30c85a4b6d8ad04343efd910dce1593ba7 100644 (file)
@@ -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
         */
index 8f1c3e236cde19ce721718775fa7551611909595..57ea5c47f771c6d402fb184c1aa32f8e245e9e95 100644 (file)
@@ -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 */
 
        /*
index 4ee283f663a1ac6b519c68b91e39d03caa8c5db1..f1bc0c6dd822e32d000e5e5978457ce25e016115 100644 (file)
@@ -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 */
 }