naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

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

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