]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3814] First poll delay of new or cleared associations miscalculated.
authorDave Hart <hart@ntp.org>
Wed, 3 May 2023 21:16:16 +0000 (21:16 +0000)
committerDave Hart <hart@ntp.org>
Wed, 3 May 2023 21:16:16 +0000 (21:16 +0000)
Switch NONEMPTY_TRANSLATION_UNIT extern reference from exit() to abs() to avoid
  warning on VS 2022 due to mismatching declaration as exit() is now noreturn.
Minimum supported Visual Studio has been 2005, remove code for earlier.

bk: 6452cf209PBAzQTFiZwD6XKLzpAdbQ

ChangeLog
include/ntp_types.h
libntp/mktime.c
libntp/systime.c
ntpd/ntp_proto.c
ports/winnt/include/config.h
ports/winnt/ntptrace/ntptrace.dsp [deleted file]

index 23c6a6c957a769b928645624beb5360f8dd22e70..5ce1c0ad7d19cf05f4c92fd7411dd2a6bfef19de 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,6 @@
 ---
+* [Bug 3814] First poll delay of new or cleared associations miscalculated.
+             <hart@ntp.org>
 * [Bug 3802] ntp-keygen -I default identity modulus bits too small for
              OpenSSL 3.  Reported by rmsh1216@163.com <hart@ntp.org>
 * [Bug 3801] gpsdjson refclock gps_open() device name mishandled. <hart@ntp.org>
index 969b325b5db70ddd11c204fb2e4f0c47c2df9f1d..abf5226b8e2f80e00c6410204876cd88d3d531f1 100644 (file)
@@ -258,10 +258,11 @@ aligned_ptr(
  * Macro to use in otherwise-empty source files to comply with ANSI C
  * requirement that each translation unit (source file) contain some
  * declaration.  This has commonly been done by declaring an unused
- * global variable of type int or char.  An extern reference to exit()
- * serves the same purpose without bloat.
+ * global variable of type int or char.  An extern reference to abs()
+ * serves the same purpose without bloat.  We once used exit() but
+ * that can produce warnings on systems that declare exit() noreturn.
  */
-#define        NONEMPTY_TRANSLATION_UNIT       extern void exit(int);
+#define        NONEMPTY_TRANSLATION_UNIT       extern int abs(int);
 
 /*
  * On Unix struct sock_timeval is equivalent to struct timeval.
index 50d2a081040832cd456b69db1d09546085f79cde..74ae85431d2f706664b5e744616088a4d40a7902 100644 (file)
@@ -60,7 +60,7 @@
  */
 
 #include <config.h>
-#include "ntp_machine.h"
+#include "ntp_types.h"
 
 #if !defined(HAVE_MKTIME) || ( !defined(HAVE_TIMEGM) && defined(WANT_TIMEGM) )
 
@@ -259,7 +259,7 @@ time2(
        return t;
 }
 #else
-int mktime_bs;
+NONEMPTY_TRANSLATION_UNIT
 #endif /* !HAVE_MKTIME || !HAVE_TIMEGM */
 
 #ifndef HAVE_MKTIME
index e2f07f71aa924d2f0e86e77332bffe8d4bf09218..76fba7fe1608f436a71048de6999fc24a05a8ce1 100644 (file)
@@ -591,6 +591,8 @@ step_systime(
        return TRUE;
 }
 
+
+#if SIZEOF_TIME_T > 4
 static const char *
 tv_fmt_libbuf(
        const struct timeval * ptv
@@ -612,6 +614,7 @@ tv_fmt_libbuf(
                 (u_int)ptv->tv_usec);
        return retv;
 }
+#endif /* SIZEOF_TIME_T > 4 */
 
 
 int /*BOOL*/
index 7de94c421cf833a4adb446a44d9f83d7a0fbe6de..18638605a210d27972732eaba8e4b8dcb2ac98ac 100644 (file)
@@ -3228,19 +3228,19 @@ peer_clear(
 
        /*
         * During initialization use the association count to spread out
-        * the polls at one-second intervals. Passive associations'
-        * first poll is delayed by the "discard minimum" to avoid rate
-        * limiting. Other post-startup new or cleared associations
+        * the polls at one-second intervals. Unconfigured associations'
+        * first poll is delayed by the "discard minimum" plus 1 to avoid
+        * rate limiting. Other post-startup new or cleared associations
         * randomize the first poll over the minimum poll interval to
         * avoid implosion.
         */
        peer->nextdate = peer->update = peer->outdate = current_time;
        if (initializing) {
                peer->nextdate += peer_associations;
-       } else if (MODE_PASSIVE == peer->hmode) {
-               peer->nextdate += ntp_minpkt;
+       } else if (!(FLAG_CONFIG & peer->flags)) {
+               peer->nextdate += ntp_minpkt + 1;
        } else {
-               peer->nextdate += ntp_random() % peer->minpoll;
+               peer->nextdate += ntp_random() % (1 << peer->minpoll);
        }
 #ifdef AUTOKEY
        peer->refresh = current_time + (1 << NTP_REFRESH);
index 4439b1cdd4f623b5ec481e495f7c36bb1c16771e..6e119da8051522900cd5c963cb7efd6d2f87f1e7 100644 (file)
@@ -75,7 +75,7 @@
 
 /* Prevent inclusion of winsock.h in windows.h */
 #ifndef _WINSOCKAPI_
-#define _WINSOCKAPI_  
+#define _WINSOCKAPI_
 #endif
 
 #ifndef __RPCASYNC_H__
@@ -213,15 +213,7 @@ typedef int socklen_t;
 #define SO_EXCLUSIVEADDRUSE ((int)(~SO_REUSEADDR))
 #endif
 
-#if defined _MSC_VER && _MSC_VER < 1400
-/*
- * Use 32-bit time definitions for versions prior to VS 2005
- * VS 2005 defaults to 64-bit time
- */
-# define SIZEOF_TIME_T 4
-#else
-# define SIZEOF_TIME_T 8
-#endif
+#define SIZEOF_TIME_T 8
 
 
 /*
diff --git a/ports/winnt/ntptrace/ntptrace.dsp b/ports/winnt/ntptrace/ntptrace.dsp
deleted file mode 100644 (file)
index ed8616a..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-# Microsoft Developer Studio Project File - Name="ntptrace" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Console Application" 0x0103
-
-CFG=ntptrace - Win32 Debug
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE 
-!MESSAGE NMAKE /f "ntptrace.mak".
-!MESSAGE 
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE 
-!MESSAGE NMAKE /f "ntptrace.mak" CFG="ntptrace - Win32 Debug"
-!MESSAGE 
-!MESSAGE Possible choices for configuration are:
-!MESSAGE 
-!MESSAGE "ntptrace - Win32 Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "ntptrace - Win32 Debug" (based on "Win32 (x86) Console Application")
-!MESSAGE 
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""$/ntp/dev/ports/winnt/ntptrace", AXBAAAAA"
-# PROP Scc_LocalPath "."
-CPP=cl.exe
-RSC=rc.exe
-
-!IF  "$(CFG)" == "ntptrace - Win32 Release"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release"
-# PROP BASE Intermediate_Dir "Release"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release"
-# PROP Intermediate_Dir "Release"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MT /W4 /GX /O2 /I "\\" /I "$(OPENSSL)\inc32" /I "." /I "..\include" /I "..\..\..\include" /D "NDEBUG" /D "_CONSOLE" /D "WIN32" /D "_MBCS" /D "__STDC__" /D "SYS_WINNT" /D "HAVE_CONFIG_H" /D _WIN32_WINNT=0x400 /YX"windows.h" /FD /c
-# ADD BASE RSC /l 0x409 /d "NDEBUG"
-# ADD RSC /l 0x409 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
-# ADD LINK32 kernel32.lib user32.lib advapi32.lib ws2_32.lib /nologo /subsystem:console /machine:I386
-
-!ELSEIF  "$(CFG)" == "ntptrace - Win32 Debug"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug"
-# PROP BASE Intermediate_Dir "Debug"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug"
-# PROP Intermediate_Dir "Debug"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /MTd /W4 /Gm /GX /ZI /Od /I "." /I "..\include" /I "..\..\..\include" /I "$(OPENSSL)\inc32" /D "_DEBUG" /D "_CONSOLE" /D "WIN32" /D "_MBCS" /D "__STDC__" /D "SYS_WINNT" /D "HAVE_CONFIG_H" /D _WIN32_WINNT=0x400 /FR /YX"windows.h" /FD /GZ /c
-# ADD BASE RSC /l 0x409 /d "_DEBUG"
-# ADD RSC /l 0x409 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib advapi32.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /out:"../bin/Debug/ntptrace.exe" /pdbtype:sept
-
-!ENDIF 
-
-# Begin Target
-
-# Name "ntptrace - Win32 Release"
-# Name "ntptrace - Win32 Debug"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=..\..\..\ntptrace\ntptrace.c
-# End Source File
-# Begin Source File
-
-SOURCE=..\libntp\util_clockstuff.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\version.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=..\include\sys\ioctl.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\..\..\ntptrace\ntptrace.h
-# End Source File
-# Begin Source File
-
-SOURCE=..\include\sys\resource.h
-# End Source File
-# End Group
-# Begin Group "Resource Files"
-
-# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
-# End Group
-# Begin Source File
-
-SOURCE=..\..\..\configure
-
-!IF  "$(CFG)" == "ntptrace - Win32 Release"
-
-# Begin Custom Build
-ProjDir=.
-InputPath=..\..\..\configure
-
-"$(ProjDir)\version.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
-       echo Using NT Shell Script to generate version.c 
-       ..\scripts\mkver.bat -P ntptrace 
-       
-# End Custom Build
-
-!ELSEIF  "$(CFG)" == "ntptrace - Win32 Debug"
-
-# Begin Custom Build
-ProjDir=.
-InputPath=..\..\..\configure
-
-"$(ProjDir)\version.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
-       echo Using NT Shell Script to generate version.c 
-       ..\scripts\mkver.bat -P ntptrace 
-       
-# End Custom Build
-
-!ENDIF 
-
-# End Source File
-# End Target
-# End Project