ovs-ofctl: Make add-flows command read from stdin if file name is "-".
authorBen Pfaff <blp@nicira.com>
Wed, 9 Mar 2011 22:44:20 +0000 (14:44 -0800)
committerBen Pfaff <blp@nicira.com>
Thu, 10 Mar 2011 00:22:00 +0000 (16:22 -0800)
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 <paul@nicira.com>
tests/ofproto.at
utilities/ovs-ofctl.8.in
utilities/ovs-ofctl.c

index f266f34..9506756 100644 (file)
@@ -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:
index 95b0884..3472cc1 100644 (file)
@@ -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.
 .
index a96b77a..f7605f7 100644 (file)
@@ -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