]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3674] ntpq command 'execute only' using '~' prefix
authorJuergen Perlinger <perlinger@ntp.org>
Mon, 26 Oct 2020 06:58:13 +0000 (07:58 +0100)
committerJuergen Perlinger <perlinger@ntp.org>
Mon, 26 Oct 2020 06:58:13 +0000 (07:58 +0100)
bk: 5f967385v-Q810yFfSahGKBavK_9Kw

ChangeLog
ntpq/ntpq.c

index eeceaa9f10cb57b56caf561eaab50a81ec861f63..d1ea4ecfa800674ea1f3f50fd59eed0d70e71ea0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+---
+* [Bug 3674] ntpq command 'execute only' using '~' prefix <perlinger@ntp.org>
+  - idea+patch by Gerry Garvey
+
 ---
 (4.2.8p15) 2020/06/23 Released by Harlan Stenn <stenn@ntp.org>
 
index 0382c0f948d7d3487b91725d179e6920ea942a8a..d49408514721ba1a0fda6c82717b08f02d1ae344 100644 (file)
@@ -17,6 +17,9 @@
 #endif
 #ifdef SYS_WINNT
 # include <mswsock.h>
+# define PATH_DEVNULL  "NUL:"
+#else
+# define PATH_DEVNULL  "/dev/null"
 #endif
 #include <isc/net.h>
 #include <isc/result.h>
@@ -1608,6 +1611,7 @@ docmd(
        int ntok;
        static int i;
        struct xcmd *xcmd;
+       int executeonly = 0;
 
        /*
         * Tokenize the command line.  If nothing on it, return.
@@ -1616,6 +1620,14 @@ docmd(
        if (ntok == 0)
            return;
 
+       /*
+        * If command prefixed by '~', then quiet output
+        */
+       if (*tokens[0] == '~') {
+               executeonly++;
+               tokens[0]++;
+       }
+
        /*
         * Find the appropriate command description.
         */
@@ -1675,6 +1687,13 @@ docmd(
                        perror("");
                        return;
                }
+       } else if (executeonly) {               /* Redirect all output to null */
+               current_output = fopen(PATH_DEVNULL, "w");
+               if (current_output == NULL) {
+                       (void) fprintf(stderr, "***Error redirecting output to /dev/null: ");
+                       perror("");
+                       return;
+               }
        } else {
                current_output = stdout;
        }