naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

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

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