[Git][NTPsec/ntpsec][master] Armor ntpwait's report of time to sync against NTP clock stepping, if we can.

Eric S. Raymond gitlab at mg.gitlab.com
Tue Aug 15 17:45:03 UTC 2017


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


Commits:
bc2ef7e0 by Eric S. Raymond at 2017-08-15T13:43:31-04:00
Armor ntpwait's report of time to sync against NTP clock stepping, if we can.

- - - - -


2 changed files:

- docs/includes/ntpwait-body.txt
- ntpclients/ntpwait


Changes:

=====================================
docs/includes/ntpwait-body.txt
=====================================
--- a/docs/includes/ntpwait-body.txt
+++ b/docs/includes/ntpwait-body.txt
@@ -35,10 +35,11 @@ returns "the time is not yet stable".
   Be verbose.
 +
 By default, +ntpwait+ is silent. With this option, +ntpwait+ will
-provide status information.
+provide status information, including time to synchronization in seconds.
 
-== AUTHOR ==
+== BUGS ==
 
-Harlan Stenn.
+If you are running Python at a version older than 3.3, the report on time
+to synchronization may be thrown off by NTP clock stepping.
 
 //end 


=====================================
ntpclients/ntpwait
=====================================
--- a/ntpclients/ntpwait
+++ b/ntpclients/ntpwait
@@ -128,6 +128,14 @@ class Unbuffered(object):
     def __getattr__(self, attr):
         return getattr(self.stream, attr)
 
+def monoclock():
+    "Try to get a monotonic clock value unaffected by NTP stepping."
+    try:
+        # Available in Python 3.3 and up.
+        return time.monotonic()
+    except AttributeError:
+        return time.time()
+
 if __name__ == "__main__":
     try:
         (options, arguments) = getopt.getopt(sys.argv[1:], "hn:s:v", [
@@ -155,7 +163,7 @@ if __name__ == "__main__":
     # Autoflush stdout
     sys.stdout = Unbuffered(sys.stdout)
 
-    basetime = time.time()
+    basetime = monoclock()
     if verbose:
         sys.stdout.write("Waiting for ntpd to synchronize...  ")
 
@@ -205,7 +213,7 @@ if __name__ == "__main__":
                     ntp.magic.LEAP_DELSECOND):
             # We could check "sync" here to make sure we like the source...
             if verbose:
-                sys.stdout.write("\bOK! (%d seconds)\n" % (time.time() - basetime))
+                sys.stdout.write("\bOK! (%d seconds)\n" % (monoclock() - basetime))
             sys.exit(0)
 
         sys.stdout.write("\bUnexpected 'leap' status <%s>\n" % leap)



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

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/bc2ef7e0c905eaa5a15295c8ab456245fd34a377
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/20170815/6f255ba7/attachment.html>


More information about the vc mailing list