From 70315176de81b49b7dcd4d65f09991f3217813af Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 9 Mar 2011 14:44:20 -0800 Subject: [PATCH] ovs-ofctl: Make add-flows command read from stdin if file name is "-". It is conventional for Unix tools to read from standard input if "-" is specified as a file name. It's easy for "ovs-ofctl add-flows" to behave this way, too, so this commit implements it. Suggested-by: Paul Ingram --- tests/ofproto.at | 2 +- utilities/ovs-ofctl.8.in | 3 ++- utilities/ovs-ofctl.c | 6 ++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/ofproto.at b/tests/ofproto.at index f266f34b..95067561 100644 --- a/tests/ofproto.at +++ b/tests/ofproto.at @@ -46,7 +46,7 @@ AT_SETUP([ofproto - basic flow_mod commands]) OFPROTO_START AT_CHECK([ovs-ofctl dump-flows br0 | STRIP_XIDS], [0], [NXST_FLOW reply: ]) -AT_CHECK([ovs-ofctl add-flow br0 in_port=1,actions=0]) +AT_CHECK([echo 'in_port=1,actions=0' | ovs-ofctl add-flows br0 -]) AT_CHECK([ovs-ofctl add-flow br0 in_port=0,actions=1]) AT_CHECK([ovs-ofctl dump-flows br0 | STRIP_XIDS | STRIP_DURATION], [0], [dnl NXST_FLOW reply: diff --git a/utilities/ovs-ofctl.8.in b/utilities/ovs-ofctl.8.in index 95b08842..3472cc1a 100644 --- a/utilities/ovs-ofctl.8.in +++ b/utilities/ovs-ofctl.8.in @@ -132,7 +132,8 @@ below. . .TP \fBadd\-flows \fIswitch file\fR -Add flow entries as described in \fIfile\fR to \fIswitch\fR's +Add the flow entries listed in \fIfile\fR, or supplied on \fBstdin\fR +if \fIfile\fR is \fB\-\fR, to \fIswitch\fR's tables. Each line in \fIfile\fR is a flow entry in the format described in \fBFlow Syntax\fR, below. . diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index a96b77a9..f7605f78 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -692,7 +692,7 @@ do_add_flows(int argc OVS_UNUSED, char *argv[]) struct vconn *vconn; FILE *file; - file = fopen(argv[2], "r"); + file = !strcmp(argv[2], "-") ? stdin : fopen(argv[2], "r"); if (file == NULL) { ovs_fatal(errno, "%s: open", argv[2]); } @@ -707,7 +707,9 @@ do_add_flows(int argc OVS_UNUSED, char *argv[]) } vconn_close(vconn); - fclose(file); + if (file != stdin) { + fclose(file); + } } static void -- 2.30.2