naccyde / rpms / iproute

Forked from rpms/iproute 10 months ago
Clone

Blame SOURCES/0001-Confirm-success-for-each-tc-batch-command.patch

e9acfd
From d9a1dc236a9bcc06f04d609e2654f76c6a9459e7 Mon Sep 17 00:00:00 2001
e9acfd
From: Phil Sutter <psutter@redhat.com>
e9acfd
Date: Mon, 14 Dec 2015 21:02:18 +0100
e9acfd
Subject: [PATCH] Confirm success for each tc -batch command
e9acfd
MIME-Version: 1.0
e9acfd
Content-Type: text/plain; charset=UTF-8
e9acfd
Content-Transfer-Encoding: 8bit
e9acfd
e9acfd
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=977844
e9acfd
Upstream Status: Rejected.
e9acfd
e9acfd
The original patch has been extended by the related man page additions
e9acfd
which were contained in another local patch.
e9acfd
e9acfd
commit 8c5024483cbbfdc092945a00be05d917485b9af3
e9acfd
Author: Petr Písař <ppisar@redhat.com>
e9acfd
Date:   Thu Sep 19 11:25:49 2013 +0200
e9acfd
e9acfd
    Confirm success for each tc -batch command
e9acfd
e9acfd
    If `tc -force -batch' is fed by a controlling program from a pipe,
e9acfd
    it's not possible to recognize when a command has been processes
e9acfd
    successfully.
e9acfd
e9acfd
    This patch adds an optional `-OK' option to the tc(8) tool, so `tc
e9acfd
    -force -OK -batch' will print "OK\n" to standard output on each
e9acfd
    successfully completed tc command.
e9acfd
e9acfd
    Signed-off-by: Petr Písař <ppisar@redhat.com>
e9acfd
e9acfd
Signed-off-by: Phil Sutter <psutter@redhat.com>
e9acfd
---
e9acfd
 man/man8/tc.8 | 8 +++++++-
e9acfd
 tc/tc.c       | 8 +++++++-
e9acfd
 2 files changed, 14 insertions(+), 2 deletions(-)
e9acfd
e9acfd
diff --git a/man/man8/tc.8 b/man/man8/tc.8
e9acfd
index f96911a..a341a8f 100644
e9acfd
--- a/man/man8/tc.8
e9acfd
+++ b/man/man8/tc.8
e9acfd
@@ -62,7 +62,7 @@ tc \- show / manipulate traffic control settings
e9acfd
 .P
e9acfd
 .ti 8
e9acfd
 .IR OPTIONS " := {"
e9acfd
-\fB[ -force ] -b\fR[\fIatch\fR] \fB[ filename ] \fR|
e9acfd
+\fB[ -force ] [ -OK ] -b\fR[\fIatch\fR] \fB[ filename ] \fR|
e9acfd
 \fB[ \fB-n\fR[\fIetns\fR] name \fB] \fR|
e9acfd
 \fB[ \fB-nm \fR| \fB-nam\fR[\fIes\fR] \fB] \fR|
e9acfd
 \fB[ \fR{ \fB-cf \fR| \fB-c\fR[\fIonf\fR] \fR} \fB[ filename ] \fB] \fR}
e9acfd
@@ -603,6 +603,12 @@ don't terminate tc on errors in batch mode.
e9acfd
 If there were any errors during execution of the commands, the application return code will be non zero.
e9acfd
 
e9acfd
 .TP
e9acfd
+.BR "\-OK"
e9acfd
+in batch mode, print
e9acfd
+.B OK
e9acfd
+and a new line on standard output after each successfully interpreted command.
e9acfd
+
e9acfd
+.TP
e9acfd
 .BR "\-n" , " \-net" , " \-netns " <NETNS>
e9acfd
 switches
e9acfd
 .B tc
e9acfd
diff --git a/tc/tc.c b/tc/tc.c
e9acfd
index 8e64a82..360c9f1 100644
e9acfd
--- a/tc/tc.c
e9acfd
+++ b/tc/tc.c
e9acfd
@@ -42,6 +42,7 @@ int batch_mode;
e9acfd
 int resolve_hosts;
e9acfd
 int use_iec;
e9acfd
 int force;
e9acfd
+int ok;
e9acfd
 bool use_names;
e9acfd
 
e9acfd
 static char *conf_file;
e9acfd
@@ -188,7 +189,7 @@ noexist:
e9acfd
 static void usage(void)
e9acfd
 {
e9acfd
 	fprintf(stderr, "Usage: tc [ OPTIONS ] OBJECT { COMMAND | help }\n"
e9acfd
-			"       tc [-force] -batch filename\n"
e9acfd
+			"       tc [-force] [-OK] -batch filename\n"
e9acfd
 			"where  OBJECT := { qdisc | class | filter | action | monitor | exec }\n"
e9acfd
 	                "       OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -p[retty] | -b[atch] [filename] | -n[etns] name |\n"
e9acfd
 			"                    -nm | -nam[es] | { -cf | -conf } path }\n");
e9acfd
@@ -254,6 +255,9 @@ static int batch(const char *name)
e9acfd
 			ret = 1;
e9acfd
 			if (!force)
e9acfd
 				break;
e9acfd
+		} else if (ok) {
e9acfd
+			printf("OK\n");
e9acfd
+			fflush(stdout);
e9acfd
 		}
e9acfd
 	}
e9acfd
 	if (line)
e9acfd
@@ -293,6 +297,8 @@ int main(int argc, char **argv)
e9acfd
 			return 0;
e9acfd
 		} else if (matches(argv[1], "-force") == 0) {
e9acfd
 			++force;
e9acfd
+		} else if (matches(argv[1], "-OK") == 0) {
e9acfd
+			++ok;
e9acfd
 		} else if (matches(argv[1], "-batch") == 0) {
e9acfd
 			argc--;	argv++;
e9acfd
 			if (argc <= 1)
e9acfd
-- 
e9acfd
1.8.3.1
e9acfd