[Git][NTPsec/ntpsec][master] Additions for debugging
Hal Murray
gitlab at mg.gitlab.com
Mon Dec 19 05:53:40 UTC 2016
Hal Murray pushed to branch master at NTPsec / ntpsec
Commits:
d4e35d39 by Hal Murray at 2016-12-18T21:51:29-08:00
Additions for debugging
In ntpmon, + and - on keyboard now bump debugging level.
- - - - -
4 changed files:
- docs/includes/ntpmon-body.txt
- ntpclients/ntpmon
- ntpclients/ntpq
- pylib/packet.py
Changes:
=====================================
docs/includes/ntpmon-body.txt
=====================================
--- a/docs/includes/ntpmon-body.txt
+++ b/docs/includes/ntpmon-body.txt
@@ -61,6 +61,10 @@ x:: Cleanly terminate the program.
<space>:: Rotate through a/n/o/p display modes.
++:: Increase debugging level. Output goes to ntpmon.log
+
+-:: Decrease debugging level.
+
?:: List these commands.
== Options ==
=====================================
ntpclients/ntpmon
=====================================
--- a/ntpclients/ntpmon
+++ b/ntpclients/ntpmon
@@ -15,6 +15,8 @@ Any keystroke causes a poll and update. Keystroke commands:
'w': Toggle wide mode.
'x': Cleanly terminate the program.
' ': Rotate through a/n/o/p display modes.
+'+': Increase debugging level. Output goes to ntpmon.log
+'-': Decrease debugging level.
'?': Display helpscreen.
'''
@@ -143,13 +145,6 @@ if __name__ == '__main__':
mru_report = ntp.util.MRUSummary(showhostnames)
try:
session = ntp.packet.ControlSession()
- if 0: # debugging hacks, UI is $EDITOR
- session.logfp = open("ntpmon.log", "a", 1) # 1 => line buffered
- session.debug = 4
- peer_report.logfp = session.logfp
- peer_report.debug = session.debug
- mru_report.logfp = session.logfp
- mru_report.debug = session.debug
session.openhost(arguments[0] if arguments else "localhost")
sysvars = session.readvar()
nyquist = 12 ##### FIXME (undefined below)
@@ -207,6 +202,8 @@ if __name__ == '__main__':
# cycle, rounded up to 1 second.
nyquist = int(min(peer_report.intervals()) / 2)
nyquist = 1 if nyquist == 0 else nyquist
+ if session.debug:
+ session.logfp.write("nyquist is %d\n" % nyquist)
# The status line
sl = statline(peer_report, mru_report, nyquist)
stdscr.addstr(sl + "\n", curses.A_REVERSE|curses.A_DIM)
@@ -248,8 +245,6 @@ if __name__ == '__main__':
selected = 0
selectmode = not selectmode
detailmode = not detailmode
- elif key == '?':
- helpmode = True
elif key == 'n':
peer_report.showhostnames = not peer_report.showhostnames
mru_report.showhostnames = not mru_report.showhostnames
@@ -274,6 +269,18 @@ if __name__ == '__main__':
elif key == 'k' or key == "KEY_UP":
selected += len(peers) - 1
selected %= len(peers)
+ elif key == '+':
+ if session.debug == 0:
+ session.logfp = open("ntpmon.log", "a", 1)
+ peer_report.logfp = session.logfp
+ mru_report.logfo = session.logfp
+ session.debug += 1
+ peer_report.debug = session.debug
+ mru_report.debug = session.debug
+ elif key == '-':
+ session.debug -= 1
+ peer_report.debug = session.debug
+ mru_report.debug = session.debug
elif key == '?':
helpmode = True
except curses.error:
=====================================
ntpclients/ntpq
=====================================
--- a/ntpclients/ntpq
+++ b/ntpclients/ntpq
@@ -597,9 +597,9 @@ usage: hostnames [yes|no]
if not line:
pass
elif line == "more":
- self.debug +=1
+ self.debug += 1
elif line == "less":
- self.debug -= 1
+ if self.debug > 0: self.debug -= 1
elif line == "no":
self.debug = 0
else:
@@ -608,6 +608,8 @@ usage: hostnames [yes|no]
except ValueError:
print("What?")
self.session.debug = self.debug
+ if self.debug > 0:
+ self.session.logfp = open("ntpq.log", "a", 1) # 1 => line buffered
print("debug level is %d" % self.debug)
def help_debug(self):
@@ -1195,6 +1197,9 @@ usage: config_from_file <configuration filename>
"Displaying partial client list.\n")
try:
formatter = ntp.util.MRUSummary(interpreter.showhostnames)
+ if session.debug:
+ formatter.logfp = session.logfp
+ formatter.debug = session.debug
self.say(ntp.util.MRUSummary.header + "\n")
self.say(("=" * ntp.util.MRUSummary.width) + "\n")
# reversed to put most recent entries at the top.
@@ -1481,6 +1486,7 @@ if __name__ == '__main__':
elif switch in ("-d", "--debug"):
interpreter.debug += 1
session.debug += 1
+ session.logfp = open("ntpq.log", "a", 1) # 1 => line buffered
elif switch in ("-D", "--set-debug-level"):
try:
session.debug = interpreter.debug = int(val)
=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -844,14 +844,14 @@ class ControlSession:
while len(xdata) % 4:
xdata += b"\x00"
if self.debug >= 3:
- self.logfp.write("Sending %d octets" % len(xdata))
+ self.logfp.write("Sending %d octets.\n" % len(xdata))
try:
self.sock.sendall(polybytes(xdata))
except socket.error:
# On failure, we don't know how much data was actually received
self.logfp.write("Write to %s failed\n" % self.hostname)
return -1
- if self.debug >= 4:
+ if self.debug >= 5:
self.logfp.write("Request packet:\n")
dump_hex_printable(xdata, self.logfp)
return 0
@@ -859,7 +859,10 @@ class ControlSession:
def sendrequest(self, opcode, associd, qdata, auth=False):
"Ship an ntpq request packet to a server."
if self.debug:
- self.logfp.write("sendrequest(opcode=%d)\n" % opcode)
+ if self.debug >= 3:
+ self.logfp.write("\n") # extra space to help find clumps
+ self.logfp.write("sendrequest: opcode=%d, associd=%d, qdata=%s\n" \
+ % (opcode, associd, qdata) )
# Check to make sure the data will fit in one packet
if len(qdata) > ntp.control.CTL_MAX_DATA_LEN:
@@ -956,10 +959,10 @@ class ControlSession:
% ("not ", "")[seenlastfrag])
raise ControlException(SERR_INCOMPLETE)
- if self.debug > 4:
+ if self.debug > 3:
warn("At %s, socket read begins\n" % time.asctime())
rawdata = polybytes(self.sock.recv(4096))
- if self.debug >= 4:
+ if self.debug >= 3:
warn("Received %d octets\n" % len(rawdata))
rpkt = ControlPacket(self)
try:
@@ -1081,9 +1084,12 @@ class ControlSession:
if self.debug:
warn("Fragment collection ends\n")
self.response = polybytes("".join([polystr(frag.data) for frag in fragments]))
- if self.debug >= 4:
+ if self.debug >= 5:
warn("Response packet:\n")
dump_hex_printable(self.response, self.logfp)
+ elif self.debug >= 3:
+ # FIXME: Garbage when retrieving assoc list (binary)
+ warn("Response packet:\n%s\n" % self.response)
return None
break
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/d4e35d3951f085967fb18bdac430efcdbb29dfa8
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20161219/e55524cf/attachment.html>
More information about the vc
mailing list