[Git][NTPsec/ntpsec][master] Address Issue #303: ntpq shell command unknown.

Eric S. Raymond gitlab at mg.gitlab.com
Sat May 13 16:55:48 UTC 2017


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


Commits:
8f0696e6 by Eric S. Raymond at 2017-05-13T12:55:11-04:00
Address Issue #303: ntpq shell command unknown.

Repair it to work correctly, and document it.

- - - - -


2 changed files:

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


Changes:

=====================================
docs/includes/ntpq-body.txt
=====================================
--- a/docs/includes/ntpq-body.txt
+++ b/docs/includes/ntpq-body.txt
@@ -186,6 +186,10 @@ following.
   to transform nonascii data into a printable (but barely
   understandable) form.
 
++shell+::
+  Execute the remainder of the line as a shell command. '!' is a
+  synonym for this.
+
 +timeout+ 'milliseconds'::
   Specify a timeout period for responses to server queries. The default
   is about 5000 milliseconds. Note that since +ntpq+ retries each query


=====================================
ntpclients/ntpq
=====================================
--- a/ntpclients/ntpq
+++ b/ntpclients/ntpq
@@ -179,34 +179,37 @@ class Ntpq(cmd.Cmd):
             line = line.replace("config-from-file ", "config_from_file")
 
         cmd, arg, line = self.parseline(line)
-        dotext = 'do_'+cmd
-        cmdprefixlist = [a[3:] for a in self.get_names()
-                         if a.startswith(dotext)]
-        if len(cmdprefixlist) == 1:
-            line = line.replace(cmd, cmdprefixlist[0])
-            cmd = cmdprefixlist[0]
-        elif len(cmdprefixlist) > 1:
-            self.warn("***Command `%s' ambiguous\n" % cmd)
-            return
-        elif len(cmdprefixlist) == 0:
-            self.warn("***Command `%s' unknown\n" % cmd)
-            return
-
-        if cmd == "help" and arg:
-            helptext = 'help_'+arg
-            if helptext not in self.get_names():
-                argprefixlist = [a[5:] for a in self.get_names()
-                                 if a.startswith(helptext)]
-                if len(argprefixlist) == 1:
-                    line = line.replace(arg, argprefixlist.pop())
-                elif len(argprefixlist) > 1:
-                    self.warn("Command `%s' is ambiguous\n" % arg)
-                    return
-                elif len(argprefixlist) == 0:
-                    self.warn("Command `%s' is unknown\n" % arg)
-                    return
+        try:
+            dotext = 'do_'+cmd
+            cmdprefixlist = [a[3:] for a in self.get_names()
+                             if a.startswith(dotext)]
+            if len(cmdprefixlist) == 1:
+                line = line.replace(cmd, cmdprefixlist[0])
+                cmd = cmdprefixlist[0]
+            elif len(cmdprefixlist) > 1:
+                self.warn("***Command `%s' ambiguous\n" % cmd)
+                return
+            elif len(cmdprefixlist) == 0:
+                self.warn("***Command `%s' unknown\n" % cmd)
+                return
 
-        self.onecmd(line)
+            if cmd == "help" and arg:
+                helptext = 'help_'+arg
+                if helptext not in self.get_names():
+                    argprefixlist = [a[5:] for a in self.get_names()
+                                     if a.startswith(helptext)]
+                    if len(argprefixlist) == 1:
+                        line = line.replace(arg, argprefixlist.pop())
+                    elif len(argprefixlist) > 1:
+                        self.warn("Command `%s' is ambiguous\n" % arg)
+                        return
+                    elif len(argprefixlist) == 0:
+                        self.warn("Command `%s' is unknown\n" % arg)
+                        return
+
+            self.onecmd(line)
+        except TypeError:
+            self.warn("Command `%s' is unknown\n" % line)
 
     def do_help(self, arg):
         if arg:
@@ -217,16 +220,19 @@ class Ntpq(cmd.Cmd):
                 if len(argprefixlist) == 1:
                     arg = argprefixlist.pop()
                 elif len(argprefixlist) > 1:
-                    self.warn("Command `%s' is ambiguous\n" % arg)
+                    self.warn("Command `%s' is ambiguous.\n" % arg)
                     return
         cmd.Cmd.do_help(self, arg)
 
     def do_shell(self, line):
-        """
-Called when a line that starts with ! is entered in response to the prompt.
-"""
-        self.warn("***Command `!%s' unknown\n" % line)
-        return
+        "Execute a shell command."
+        sys.stdout.flush()
+        sys.stderr.flush()
+        if os.system(line):
+            self.warn("'shell %s' returned error.\n" % line)
+
+    def help_shell(self):
+        self.say("function: execute the line as a shell command.\n")
 
     def say(self, msg):
         try:



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

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/8f0696e642fc3093d96a40602dc9ad2484e43441
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/20170513/86911eb1/attachment.html>


More information about the vc mailing list