diff mbox

[iproute] Confirm success for each tc -batch command

Message ID 1446120596-10399-1-git-send-email-phil@nwl.cc
State Rejected, archived
Delegated to: stephen hemminger
Headers show

Commit Message

Phil Sutter Oct. 29, 2015, 12:09 p.m. UTC
If `tc -force -batch' is fed by a controlling program from a pipe,
it's not possible to recognize when a command has been processes
successfully.

This patch adds an optional `-OK' option to the tc(8) tool, so `tc
-force -OK -batch' will print "OK\n" to standard output on each
successfully completed tc command.

Signed-off-by: Petr Písař <ppisar@redhat.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 man/man8/tc.8 | 8 +++++++-
 tc/tc.c       | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

Comments

stephen hemminger Nov. 3, 2015, 8:46 p.m. UTC | #1
On Thu, 29 Oct 2015 13:09:56 +0100
Phil Sutter <phil@nwl.cc> wrote:

> If `tc -force -batch' is fed by a controlling program from a pipe,
> it's not possible to recognize when a command has been processes
> successfully.
> 
> This patch adds an optional `-OK' option to the tc(8) tool, so `tc
> -force -OK -batch' will print "OK\n" to standard output on each
> successfully completed tc command.
> 
> Signed-off-by: Petr Písař <ppisar@redhat.com>
> Signed-off-by: Phil Sutter <phil@nwl.cc>

Why use batch mode if you are feeding it from a pipe?
This seems like unnecessary feature creep.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Phil Sutter Nov. 3, 2015, 11:35 p.m. UTC | #2
On Tue, Nov 03, 2015 at 12:46:21PM -0800, Stephen Hemminger wrote:
> On Thu, 29 Oct 2015 13:09:56 +0100
> Phil Sutter <phil@nwl.cc> wrote:
> 
> > If `tc -force -batch' is fed by a controlling program from a pipe,
> > it's not possible to recognize when a command has been processes
> > successfully.
> > 
> > This patch adds an optional `-OK' option to the tc(8) tool, so `tc
> > -force -OK -batch' will print "OK\n" to standard output on each
> > successfully completed tc command.
> > 
> > Signed-off-by: Petr Písař <ppisar@redhat.com>
> > Signed-off-by: Phil Sutter <phil@nwl.cc>
> 
> Why use batch mode if you are feeding it from a pipe?
> This seems like unnecessary feature creep.

This turned up when searching the list of iproute2 patches in RHEL6 for
unpublished changes. It dates back to a feature request from 2012 by a
customer who wanted to know when a command piped into tc was finished
processing. Looking at the ticket again, it appears you rejected this
patch in 2013 already. So I guess everything has been said but "sorry
for the noise"!

Cheers, Phil
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/man/man8/tc.8 b/man/man8/tc.8
index 700b960..4c5c079 100644
--- a/man/man8/tc.8
+++ b/man/man8/tc.8
@@ -61,7 +61,7 @@  DEV
 .P
 .ti 8
 .IR OPTIONS " := {"
-\fB[ -force ] -b\fR[\fIatch\fR] \fB[ filename ] \fR|
+\fB[ -force ] [ -OK ] -b\fR[\fIatch\fR] \fB[ filename ] \fR|
 \fB[ \fB-n\fR[\fIetns\fR] name \fB] \fR|
 \fB[ \fB-nm \fR| \fB-nam\fR[\fIes\fR] \fB] \fR|
 \fB[ \fR{ \fB-cf \fR| \fB-c\fR[\fIonf\fR] \fR} \fB[ filename ] \fB] \fR}
@@ -588,6 +588,12 @@  don't terminate tc on errors in batch mode.
 If there were any errors during execution of the commands, the application return code will be non zero.
 
 .TP
+.BR "\-OK"
+in batch mode, print
+.B OK
+and a new line on standard output after each successfully interpreted command.
+
+.TP
 .BR "\-n" , " \-net" , " \-netns " <NETNS>
 switches
 .B tc
diff --git a/tc/tc.c b/tc/tc.c
index 1707867..2918da0 100644
--- a/tc/tc.c
+++ b/tc/tc.c
@@ -43,6 +43,7 @@  int resolve_hosts = 0;
 int use_iec = 0;
 int force = 0;
 bool use_names = false;
+int ok = 0;
 
 static char *conf_file;
 
@@ -190,7 +191,7 @@  noexist:
 static void usage(void)
 {
 	fprintf(stderr, "Usage: tc [ OPTIONS ] OBJECT { COMMAND | help }\n"
-			"       tc [-force] -batch filename\n"
+			"       tc [-force] [-OK] -batch filename\n"
 	                "where  OBJECT := { qdisc | class | filter | action | monitor | exec }\n"
 	                "       OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -p[retty] | -b[atch] [filename] | "
 			"-n[etns] name |\n"
@@ -257,6 +258,9 @@  static int batch(const char *name)
 			ret = 1;
 			if (!force)
 				break;
+		} else if (ok) {
+			printf("OK\n");
+			fflush(stdout);
 		}
 	}
 	if (line)
@@ -296,6 +300,8 @@  int main(int argc, char **argv)
 			return 0;
 		} else if (matches(argv[1], "-force") == 0) {
 			++force;
+		} else if (matches(argv[1], "-OK") == 0) {
+			++ok;
 		} else if (matches(argv[1], "-batch") == 0) {
 			argc--;	argv++;
 			if (argc <= 1)