From 1e1d00a5036e3ff1430b830aa674d9e446655633 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 26 Jan 2012 15:45:34 -0800 Subject: [PATCH] ovs-ofctl: New "ofctl/set-output-file" unixctl command. This will be useful in unit tests, to allow switching output to a new file during "ovs-ofctl monitor" runtime. Signed-off-by: Ben Pfaff --- utilities/ovs-ofctl.8.in | 5 +++++ utilities/ovs-ofctl.c | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/utilities/ovs-ofctl.8.in b/utilities/ovs-ofctl.8.in index fc9b699d..51144f2b 100644 --- a/utilities/ovs-ofctl.8.in +++ b/utilities/ovs-ofctl.8.in @@ -1207,6 +1207,11 @@ process. The supported commands are listed below. Causes \fBovs\-ofctl\fR to gracefully terminate. This command applies only when executing the \fBmonitor\fR or \fBsnoop\fR commands. . +.IP "\fBofctl/set\-output\-file \fIfile\fR" +Causes all subsequent output to go to \fIfile\fR instead of stderr. +This command applies only when executing the \fBmonitor\fR or +\fBsnoop\fR commands. +. .IP "\fBofctl/send \fIofmsg\fR..." Sends each \fIofmsg\fR, specified as a sequence of hex digits that express an OpenFlow message, on the OpenFlow connection. This command diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index f0b52757..a7906057 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -902,6 +903,24 @@ ofctl_send(struct unixctl_conn *conn, int argc, ds_destroy(&reply); } +static void +ofctl_set_output_file(struct unixctl_conn *conn, int argc OVS_UNUSED, + const char *argv[], void *aux OVS_UNUSED) +{ + int fd; + + fd = open(argv[1], O_CREAT | O_TRUNC | O_WRONLY, 0666); + if (fd < 0) { + unixctl_command_reply(conn, 501, strerror(errno)); + return; + } + + fflush(stderr); + dup2(fd, STDERR_FILENO); + close(fd); + unixctl_command_reply(conn, 200, ""); +} + static void monitor_vconn(struct vconn *vconn) { @@ -918,6 +937,8 @@ monitor_vconn(struct vconn *vconn) unixctl_command_register("exit", "", 0, 0, ofctl_exit, &exiting); unixctl_command_register("ofctl/send", "OFMSG...", 1, INT_MAX, ofctl_send, vconn); + unixctl_command_register("ofctl/set-output-file", "FILE", 1, 1, + ofctl_set_output_file, NULL); daemonize_complete(); for (;;) { -- 2.30.2