[Git][NTPsec/ntpsec][master] Changed ntpdig -p option to poll servers instead of limit server count

Ian Bruene gitlab at mg.gitlab.com
Fri Jul 14 22:31:33 UTC 2017


Ian Bruene pushed to branch master at NTPsec / ntpsec


Commits:
f5df6d7e by Ian Bruene at 2017-07-14T17:14:15-05:00
Changed ntpdig -p option to poll servers instead of limit server count

Previously the docs indicated that -p/--samples would poll all servers
N times, then choose the best one.

The code on the other hand simply didn't poll more than N servers,
regardless of how many were given.

- - - - -


1 changed file:

- ntpclients/ntpdig


Changes:

=====================================
ntpclients/ntpdig
=====================================
--- a/ntpclients/ntpdig
+++ b/ntpclients/ntpdig
@@ -325,6 +325,8 @@ if __name__ == '__main__':
                 elif switch in ("-p", "--samples"):
                     errmsg = "Error: -p parameter '%s' not a number\n"
                     samples = ntp.util.safeargcast(val, int, errmsg, usage)
+                    if samples < 1:  # If <1 it won't run at all
+                        samples = 1
                 elif switch in ('-r', "--replay"):
                     replay = val
                 elif switch in ("-S", "--step"):
@@ -379,24 +381,23 @@ if __name__ == '__main__':
             returned = [packet]
         else:
             returned = []
-            for server in concurrent_hosts:
-                try:
-                    returned += queryhost(server=server, concurrent=True,
-                                          timeout=timeout)
-                except ntp.packet.SyncException as e:
-                    log(str(e))
-                    continue
-                if len(returned) >= samples:
-                    break
-            for server in arguments:
-                try:
-                    returned += queryhost(server=server,
-                                          concurrent=False, timeout=timeout)
-                except ntp.packet.SyncException as e:
-                    log(str(e))
-                    continue
-                if len(returned) >= samples:
-                    break
+            for s in range(samples):
+                for server in concurrent_hosts:
+                    try:
+                        returned += queryhost(server=server,
+                                              concurrent=True,
+                                              timeout=timeout)
+                    except ntp.packet.SyncException as e:
+                        log(str(e))
+                        continue
+                for server in arguments:
+                    try:
+                        returned += queryhost(server=server,
+                                              concurrent=False,
+                                              timeout=timeout)
+                    except ntp.packet.SyncException as e:
+                        log(str(e))
+                        continue
             returned = clock_select(returned)
 
         if returned:



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/f5df6d7e84ba3aa9b3ecb9d9254eb239d685bf7d

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/f5df6d7e84ba3aa9b3ecb9d9254eb239d685bf7d
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170714/95c9e89d/attachment.html>


More information about the vc mailing list