bb0118f
From 3c4b5a852d5bb9070c7fb4428aa50f2e3e1f6e1b Mon Sep 17 00:00:00 2001
bb0118f
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
bb0118f
Date: Thu, 19 Sep 2013 11:25:49 +0200
bb0118f
Subject: [PATCH] Confirm success for each tc -batch command
bb0118f
MIME-Version: 1.0
bb0118f
Content-Type: text/plain; charset=UTF-8
bb0118f
Content-Transfer-Encoding: 8bit
bb0118f
bb0118f
If `tc -force -batch' is fed by a controlling program from a pipe,
bb0118f
it's not possible to recognize when a command has been processes
bb0118f
successfully.
bb0118f
bb0118f
This patch adds an optional `-OK' option to the tc(8) tool, so `tc
bb0118f
-force -OK -batch' will print "OK\n" to standard output on each
bb0118f
successfully completed tc command.
bb0118f
bb0118f
Signed-off-by: Petr Písař <ppisar@redhat.com>
bb0118f
---
bb0118f
 man/man8/tc.8 | 8 +++++++-
bb0118f
 tc/tc.c       | 8 +++++++-
bb0118f
 2 files changed, 14 insertions(+), 2 deletions(-)
bb0118f
bb0118f
diff --git a/man/man8/tc.8 b/man/man8/tc.8
bb0118f
index e0acfeb..583eae2 100644
bb0118f
--- a/man/man8/tc.8
bb0118f
+++ b/man/man8/tc.8
bb0118f
@@ -49,7 +49,7 @@ DEV
bb0118f
 DEV
bb0118f
 
bb0118f
 .P
bb0118f
-.B tc [ -force ] -b\fR[\fIatch\fR] \fB[ filename ]
bb0118f
+.B tc [ -force ] [ -OK ] -b\fR[\fIatch\fR] \fB[ filename ]
bb0118f
 
bb0118f
 .ti 8
bb0118f
 .IR FORMAT " := {"
bb0118f
@@ -440,6 +440,12 @@ First failure will cause termination of tc.
bb0118f
 don't terminate tc on errors in batch mode.
bb0118f
 If there were any errors during execution of the commands, the application return code will be non zero.
bb0118f
 
bb0118f
+.TP
bb0118f
+.BR "\-OK"
bb0118f
+in batch mode, print
bb0118f
+.B OK
bb0118f
+and a new line on standard output after each successfully interpreted command.
bb0118f
+
bb0118f
 .SH HISTORY
bb0118f
 .B tc
bb0118f
 was written by Alexey N. Kuznetsov and added in Linux 2.2.
bb0118f
diff --git a/tc/tc.c b/tc/tc.c
bb0118f
index 9b50e74..b43bb47 100644
bb0118f
--- a/tc/tc.c
bb0118f
+++ b/tc/tc.c
bb0118f
@@ -39,6 +39,7 @@ int batch_mode = 0;
bb0118f
 int resolve_hosts = 0;
bb0118f
 int use_iec = 0;
bb0118f
 int force = 0;
bb0118f
+int ok = 0;
bb0118f
 struct rtnl_handle rth;
bb0118f
 
bb0118f
 static void *BODY = NULL;	/* cached handle dlopen(NULL) */
bb0118f
@@ -183,7 +184,7 @@ noexist:
bb0118f
 static void usage(void)
bb0118f
 {
bb0118f
 	fprintf(stderr, "Usage: tc [ OPTIONS ] OBJECT { COMMAND | help }\n"
bb0118f
-			"       tc [-force] -batch filename\n"
bb0118f
+			"       tc [-force] [-OK] -batch filename\n"
bb0118f
 	                "where  OBJECT := { qdisc | class | filter | action | monitor }\n"
bb0118f
 	                "       OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -p[retty] | -b[atch] [filename] }\n");
bb0118f
 }
bb0118f
@@ -251,6 +252,9 @@ static int batch(const char *name)
bb0118f
 			ret = 1;
bb0118f
 			if (!force)
bb0118f
 				break;
bb0118f
+		} else if (ok) {
bb0118f
+			printf("OK\n");
bb0118f
+			fflush(stdout);
bb0118f
 		}
bb0118f
 	}
bb0118f
 	if (line)
bb0118f
@@ -288,6 +292,8 @@ int main(int argc, char **argv)
bb0118f
 			return 0;
bb0118f
 		} else if (matches(argv[1], "-force") == 0) {
bb0118f
 			++force;
bb0118f
+		} else if (matches(argv[1], "-OK") == 0) {
bb0118f
+			++ok;
bb0118f
 		} else 	if (matches(argv[1], "-batch") == 0) {
bb0118f
 			argc--;	argv++;
bb0118f
 			if (argc <= 1)
bb0118f
-- 
bb0118f
1.8.3.1
bb0118f