[ovs-dev] [async-msgs 09/13] ovs-ofctl: New "ofctl/set-output-file" unixctl command.

Ethan Jackson ethan at nicira.com
Thu Feb 9 01:50:32 UTC 2012


Looks good,
Ethan


On Thu, Jan 26, 2012 at 15:53, Ben Pfaff <blp at nicira.com> wrote:
> 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 <blp at nicira.com>
> ---
>  utilities/ovs-ofctl.8.in |    5 +++++
>  utilities/ovs-ofctl.c    |   21 +++++++++++++++++++++
>  2 files changed, 26 insertions(+), 0 deletions(-)
>
> diff --git a/utilities/ovs-ofctl.8.in b/utilities/ovs-ofctl.8.in
> index 415dddc..afde46c 100644
> --- a/utilities/ovs-ofctl.8.in
> +++ b/utilities/ovs-ofctl.8.in
> @@ -1137,6 +1137,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 0006bd6..4995354 100644
> --- a/utilities/ovs-ofctl.c
> +++ b/utilities/ovs-ofctl.c
> @@ -24,6 +24,7 @@
>  #include <stdlib.h>
>  #include <string.h>
>  #include <unistd.h>
> +#include <sys/fcntl.h>
>  #include <sys/stat.h>
>  #include <sys/time.h>
>
> @@ -901,6 +902,24 @@ ofctl_send(struct unixctl_conn *conn, int argc,
>  }
>
>  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)
>  {
>     struct unixctl_server *server;
> @@ -937,6 +956,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();
>
>     /* Now get stderr back. */
> --
> 1.7.2.5
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev



More information about the dev mailing list