From: Juergen Perlinger Date: Mon, 26 Oct 2020 06:58:13 +0000 (+0100) Subject: [Bug 3674] ntpq command 'execute only' using '~' prefix X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=afc9ec1c27d0e3249076adc833501485a4d2469b;p=thirdparty%2Fntp.git [Bug 3674] ntpq command 'execute only' using '~' prefix bk: 5f967385v-Q810yFfSahGKBavK_9Kw --- diff --git a/ChangeLog b/ChangeLog index eeceaa9f1..d1ea4ecfa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +--- +* [Bug 3674] ntpq command 'execute only' using '~' prefix + - idea+patch by Gerry Garvey + --- (4.2.8p15) 2020/06/23 Released by Harlan Stenn diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index 0382c0f94..d49408514 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -17,6 +17,9 @@ #endif #ifdef SYS_WINNT # include +# define PATH_DEVNULL "NUL:" +#else +# define PATH_DEVNULL "/dev/null" #endif #include #include @@ -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; }