netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Petr Písař" <ppisar@redhat.com>
To: <netdev@vger.kernel.org>
Cc: shemminger@vyatta.com, "Petr Písař" <ppisar@redhat.com>
Subject: [PATCH] Confirm success for each tc -batch command
Date: Thu, 19 Sep 2013 12:13:42 +0200	[thread overview]
Message-ID: <1379585622-1570-1-git-send-email-ppisar@redhat.com> (raw)

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>
---
 man/man8/tc.8 | 8 +++++++-
 tc/tc.c       | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/man/man8/tc.8 b/man/man8/tc.8
index e0acfeb..583eae2 100644
--- a/man/man8/tc.8
+++ b/man/man8/tc.8
@@ -49,7 +49,7 @@ DEV
 DEV
 
 .P
-.B tc [ -force ] -b\fR[\fIatch\fR] \fB[ filename ]
+.B tc [ -force ] [ -OK ] -b\fR[\fIatch\fR] \fB[ filename ]
 
 .ti 8
 .IR FORMAT " := {"
@@ -440,6 +440,12 @@ First failure will cause termination of tc.
 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.
+
 .SH HISTORY
 .B tc
 was written by Alexey N. Kuznetsov and added in Linux 2.2.
diff --git a/tc/tc.c b/tc/tc.c
index 9b50e74..b43bb47 100644
--- a/tc/tc.c
+++ b/tc/tc.c
@@ -39,6 +39,7 @@ int batch_mode = 0;
 int resolve_hosts = 0;
 int use_iec = 0;
 int force = 0;
+int ok = 0;
 struct rtnl_handle rth;
 
 static void *BODY = NULL;	/* cached handle dlopen(NULL) */
@@ -183,7 +184,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 }\n"
 	                "       OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -p[retty] | -b[atch] [filename] }\n");
 }
@@ -251,6 +252,9 @@ static int batch(const char *name)
 			ret = 1;
 			if (!force)
 				break;
+		} else if (ok) {
+			printf("OK\n");
+			fflush(stdout);
 		}
 	}
 	if (line)
@@ -288,6 +292,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)
-- 
1.8.3.1

                 reply	other threads:[~2013-09-19 10:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1379585622-1570-1-git-send-email-ppisar@redhat.com \
    --to=ppisar@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@vyatta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).