]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1993] ntpd Windows port adj_systime() broken in 4.2.7p203.
authorDave Hart <hart@ntp.org>
Fri, 19 Aug 2011 16:06:28 +0000 (16:06 +0000)
committerDave Hart <hart@ntp.org>
Fri, 19 Aug 2011 16:06:28 +0000 (16:06 +0000)
bk: 4e4e8a04UmYK5v6AiBTVXyXWsNZSog

ChangeLog
include/ntp_fp.h
include/ntp_types.h
ports/winnt/ntpd/nt_clockstuff.c

index 086870ee0a015b7b6b091734886610e4c743a247..fa090c5b6a018f6032338f28b1c1fe0df91d7ba1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,4 @@
+* [Bug 1993] ntpd Windows port adj_systime() broken in 4.2.7p203.
 (4.2.7p205) 2011/08/19 Released by Harlan Stenn <stenn@ntp.org>
 * [Bug 1992] util/tg2 doesn't compile, needs libntp.
 (4.2.7p204) 2011/08/16 Released by Harlan Stenn <stenn@ntp.org>
index bd6471041344420682ee265ccfca0eef45014335..c726748e589ac6eb7180d52288dd14a1738ee9f1 100644 (file)
@@ -265,7 +265,7 @@ typedef u_int32 u_fp;
                        q_tmp = ~(u_int64)ldexp(-d_tmp, 32) + 1; \
                else \
                        q_tmp = (u_int64)ldexp(d_tmp, 32); \
-               (r_uf) = (u_int32)q_tmp; \
+               (r_uf) = (u_int32)(q_tmp & UINT32_MAX); \
                (r_ui) = (u_int32)(q_tmp >> 32); \
        } while(0)
 
index 504596b61d16099a38e3f41c7def8be8713c43fa..919cff9136784e2c90b643393f57553e6ab4e152 100644 (file)
@@ -84,6 +84,11 @@ typedef unsigned int u_int;
 # endif
 #endif /* !HAVE_UINT32_T && SIZEOF_INT != 4 */
 
+#ifndef UINT32_MAX
+#define UINT32_MAX     0xffffffff
+#endif
+
+
 /*
  * Ugly dance to find out if we have 64bit integer type.
  */
index a58e4bee19829c65f624770c8448f4a01899a72e..3036e835e1ffd92b3ea2bb1cf0a1fa6f35c58d2a 100644 (file)
@@ -415,7 +415,7 @@ adj_systime(
        )
 {
        double dtemp;
-       u_char isneg = 0;
+       u_char isneg;
        BOOL rc;
        long TimeAdjustment;
        SYSTEMTIME st;
@@ -429,8 +429,10 @@ adj_systime(
        dtemp = sys_residual + now;
        sys_residual = 0;
        if (dtemp < 0) {
-               isneg = 1;
+               isneg = TRUE;
                dtemp = -dtemp;
+       } else {
+               isneg = FALSE;
        }
 
        if (dtemp > NTP_MAXFREQ)
@@ -450,10 +452,10 @@ adj_systime(
         * and leave the remainder in dtemp
         */
        TimeAdjustment = (long)(dtemp / ppm_per_adjust_unit +
-                               (isneg)
-                                   ? -0.5
-                                   : 0.5);
-       dtemp -= (double)TimeAdjustment * ppm_per_adjust_unit;  
+                               ((isneg)
+                                    ? -0.5
+                                    : 0.5));
+       dtemp -= TimeAdjustment * ppm_per_adjust_unit;  
 
 
        /*
@@ -500,7 +502,7 @@ adj_systime(
                         */
                        if (0 == ls_time_adjustment) {
                                ls_ft.ull = 0;
-                               msyslog( LOG_NOTICE, "Leap second announcement disarmed" );
+                               msyslog(LOG_NOTICE, "Leap second announcement disarmed");
                        }
                }
        }
@@ -515,17 +517,16 @@ adj_systime(
 
                if (0 == ls_time_adjustment) { /* has not yet been scheduled */
 
-                       GetSystemTimeAsFileTime(&curr_ft.ft);   
-                       if ( curr_ft.ull >= ls_ft.ull )
-                       {
+                       GetSystemTimeAsFileTime(&curr_ft.ft);
+                       if (curr_ft.ull >= ls_ft.ull) {
                                ls_time_adjustment = clockperiod / LS_CORR_INTV_SECS;
                                ls_ref_perf_cnt = this_perf_count;
                                ls_elapsed = 0;
                                msyslog(LOG_NOTICE, "Inserting positive leap second.");
                        }
                } else {  /* leap sec adjustment has been scheduled previously */
-                       ls_elapsed = ( this_perf_count - ls_ref_perf_cnt 
-                                      * HECTONANOSECONDS / PerfCtrFreq;
+                       ls_elapsed = (this_perf_count - ls_ref_perf_cnt
+                                    * HECTONANOSECONDS / PerfCtrFreq;
                }
 
                if (ls_time_adjustment != 0) {  /* leap second adjustment is currently active */
@@ -538,7 +539,7 @@ adj_systime(
                         * NOTE: While the system time is slewed during the leap second 
                         * the interpolation function which is based on the performance 
                         * counter does not account for the slew.
-                       */
+                        */
                        TimeAdjustment -= ls_time_adjustment;
                }
        }
@@ -555,16 +556,14 @@ adj_systime(
        }
        if (rc) {
                msyslog(LOG_ERR, "Can't adjust time: %m");
-               return 0;
-       }
-       else {
-               sys_residual = dtemp / 1e6;
+               return FALSE;
        }
 
-       DPRINTF(6, ("adj_systime: adj %.9f -> remaining residual %.9f\n", 
+       sys_residual = dtemp / 1e6;
+       DPRINTF(4, ("adj_systime: adj %.9f -> remaining residual %.9f\n", 
                    now, sys_residual));
 
-       return 1;
+       return TRUE;
 }
 
 
@@ -1189,6 +1188,12 @@ ntp_timestamp_from_counter(
        ULONGLONG       InterpTimestamp;
 
        if (winnt_use_interpolation) {
+               if (0 == Counterstamp) {
+                       DPRINTF(1, ("ntp_timestamp_from_counter rejecting 0 counter.\n"));
+                       ZERO(*result);
+                       return;
+               }
+
                InterpTimestamp = interp_time(Counterstamp + QPC_offset, FALSE);
 
 #ifdef DEBUG
@@ -1200,9 +1205,9 @@ ntp_timestamp_from_counter(
                    Now.ll < -60 * HECTONANOSECONDS) {
                        DPRINTF(1, ("ntp_timestamp_from_counter interpolated time %.6fs from current\n",
                                        Now.ll / (double)HECTONANOSECONDS));
-                       DPRINTF(1, ("interpol time %llx from  %llx\n",
-                                       InterpTimestamp,
-                                       Counterstamp));
+                       DPRINTF(1, ("interpol time %llx from  %llx + %llx\n",
+                                       InterpTimestamp, Counterstamp,
+                                       QPC_offset));
                        msyslog(LOG_ERR,
                                "ntp_timestamp_from_counter interpolated time %.6fs from current\n",
                                Now.ll / (double)HECTONANOSECONDS);
@@ -1216,7 +1221,8 @@ ntp_timestamp_from_counter(
                /* sanity check timestamp is within 1 minute of now */
                GetSystemTimeAsFileTime(&Now.ft);
                Now.ll -= InterpTimestamp;
-               if (Now.ll > 60 * HECTONANOSECONDS || 
+               if (debug &&
+                   Now.ll > 60 * HECTONANOSECONDS || 
                    Now.ll < -60 * HECTONANOSECONDS) {
                        DPRINTF(1, ("ntp_timestamp_from_counter serial driver system time %.6fs from current\n",
                                    Now.ll / (double)HECTONANOSECONDS));