[Git][NTPsec/ntpsec][master] Fix a serious bug in ntpmon's poll-interval calculation.

Eric S. Raymond gitlab at mg.gitlab.com
Sat Dec 17 13:25:42 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
74183016 by Eric S. Raymond at 2016-12-17T08:24:57-05:00
Fix a serious bug in ntpmon's poll-interval calculation.

- - - - -


2 changed files:

- ntpclients/ntpmon
- pylib/util.py


Changes:

=====================================
ntpclients/ntpmon
=====================================
--- a/ntpclients/ntpmon
+++ b/ntpclients/ntpmon
@@ -53,12 +53,13 @@ def iso8601(t):
     "ISO8601 string from Unix time, including fractional second."
     return time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(time.time()))
 
-def statline(_peerlist, _mrulist):
+def statline(_peerlist, _mrulist, nyquist):
     "Generate a status line"
     # We don't use stdversion here because the presence of a date is confusing
     leader = sysvars['version']
     if span.entries:
-        trailer = "Last update: %s" % iso8601(span.entries[0].last)
+        trailer = "Last update: %s (%s)" \
+                  % (iso8601(span.entries[0].last), ntp.util.PeerSummary.prettyinterval(nyquist))
     else:
         trailer = ""
     spacer = (peer_report.termwidth - len(leader) - len(trailer)) * " "
@@ -171,8 +172,13 @@ if __name__ == '__main__':
                         span = session.mrulist(recent=limit)
                         mru_report.now = time.time()
 
+                        # Nyquist-interval sampling - half the
+                        # smallest poll interval seen in the last
+                        # cycle, rounded up to 1 second.                        
+                        nyquist = int(min(peer_report.intervals()) / 2)
+                        nyquist = 1 if nyquist == 0 else nyquist
                         # The status line
-                        sl = statline(peer_report, mru_report)
+                        sl = statline(peer_report, mru_report, nyquist)
                         stdscr.addstr(sl + "\n", curses.A_REVERSE|curses.A_DIM)
                         if span.entries:
                             stdscr.addstr(ntp.util.MRUSummary.header + "\n",
@@ -184,9 +190,7 @@ if __name__ == '__main__':
                         pass
                     # Display all
                     stdscr.refresh()
-                    # Nyquist-interval sampling - half the smallest poll interval
-                    # seen in the last cycle, rounded up to 1 second.
-                    stdscr.timeout(max(int(min(hpolls) / 2), 1))
+                    stdscr.timeout(nyquist)
                 try:
                     helpmode = False
                     key = stdscr.getkey()


=====================================
pylib/util.py
=====================================
--- a/pylib/util.py
+++ b/pylib/util.py
@@ -122,6 +122,7 @@ class PeerSummary:
         self.__remote = "     remote    ".ljust(self.namewidth)
         self.__common = "st t when poll reach   delay   offset  "
         self.__header = None
+        self.polls = []
 
     @staticmethod
     def prettyinterval(diff):
@@ -257,6 +258,7 @@ class PeerSummary:
         #
         line = ""
         poll_sec = 1 << min(ppoll, hpoll)
+        self.polls.append(poll_sec)
         if self.pktversion > ntp.magic.NTP_OLDVERSION:
             c = " x.-+#*o"[ntp.control.CTL_PEER_STATVAL(rstatus) & 0x7]
         else:
@@ -313,6 +315,12 @@ class PeerSummary:
             # This can happen when ntpd ships a corrupt varlist
             return ''
 
+    def intervals(self):
+        "Return and flush the list of actual poll intervals."
+        res = self.polls[:]
+        self.polls = []
+        return res
+
 class MRUSummary:
     "Reusable class for MRU entry summary generation."
     def __init__(self, showhostnames):



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/74183016446f2ef523ef957e0fee3d1cfdc43b9e
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20161217/e6de12a0/attachment.html>


More information about the vc mailing list