Re: [ovs-dev] [PATCH v3] command-line.c: Support parsing ctl options via env variable
Thanks Ben and Ilya. From: Ben Pfaff Sent: Friday, October 25, 2019 12:48 PM To: amgin...@gmail.com Cc: d...@openvswitch.org ; Ginwala, Aliasgar Subject: Re: [ovs-dev] [PATCH v3] command-line.c: Support parsing ctl options via env variable On Fri, Oct 25, 2019 at 12:33:52PM -0700, amgin...@gmail.com wrote: > From: Aliasgar Ginwala > > Signed-off-by: Aliasgar Ginwala I tweaked this a little further and applied it to master as follows. Thank you! -8<--cut here-->8-- From: Aliasgar Ginwala Date: Fri, 25 Oct 2019 12:33:52 -0700 Subject: [PATCH] command-line: New function ovs_cmdl_env_parse_all(). This function allows an environment variable to be included in command-line parsing. It will receive its first user in an upcoming commit. Signed-off-by: Aliasgar Ginwala Signed-off-by: Ben Pfaff --- lib/command-line.c | 24 lib/command-line.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/lib/command-line.c b/lib/command-line.c index 9e000bd28d1a..967f4f5d5846 100644 --- a/lib/command-line.c +++ b/lib/command-line.c @@ -19,6 +19,7 @@ #include #include #include +#include "svec.h" #include "openvswitch/dynamic-string.h" #include "ovs-thread.h" #include "util.h" @@ -77,6 +78,29 @@ find_option_by_value(const struct option *options, int value) return NULL; } +/* Parses options set using environment variable. The caller specifies the + * supported options in environment variable. On success, adds the parsed + * env variables in 'argv', the number of options in 'argc', and returns argv. + * */ +char ** +ovs_cmdl_env_parse_all(int *argcp, char *argv[], const char *env_options) +{ +ovs_assert(*argcp > 0); + +struct svec args = SVEC_EMPTY_INITIALIZER; +svec_add(&args, argv[0]); +if (env_options) { +svec_parse_words(&args, env_options); +} +for (int i = 1; i < *argcp; i++) { +svec_add(&args, argv[i]); +} +svec_terminate(&args); + +*argcp = args.n; +return args.names; +} + /* Parses the command-line options in 'argc' and 'argv'. The caller specifies * the supported options in 'options'. On success, stores the parsed options * in '*pop', the number of options in '*n_pop', and returns NULL. On failure, diff --git a/lib/command-line.h b/lib/command-line.h index 9d62dc2501c5..fc2a2690f688 100644 --- a/lib/command-line.h +++ b/lib/command-line.h @@ -54,6 +54,9 @@ char *ovs_cmdl_parse_all(int argc, char *argv[], const struct option *, struct ovs_cmdl_parsed_option **, size_t *) OVS_WARN_UNUSED_RESULT; +char **ovs_cmdl_env_parse_all(int *argcp, char *argv_[], + const char *env_options); + void ovs_cmdl_print_options(const struct option *options); void ovs_cmdl_print_commands(const struct ovs_cmdl_command *commands); -- 2.21.0 ___ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev
Re: [ovs-dev] [PATCH v3] command-line.c: Support parsing ctl options via env variable
Bleep bloop. Greetings aginwala aginwala, I am a robot and I have tried out your patch. Thanks for your contribution. I encountered some error that I wasn't expecting. See the details below. git-am: Failed to merge in the changes. Patch failed at 0001 command-line.c: Support parsing ctl options via env variable The copy of the patch that failed is found in: /var/lib/jenkins/jobs/upstream_build_from_pw/workspace/.git/rebase-apply/patch When you have resolved this problem, run "git am --resolved". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". Please check this out. If you feel there has been an error, please email acon...@redhat.com Thanks, 0-day Robot ___ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev
Re: [ovs-dev] [PATCH v3] command-line.c: Support parsing ctl options via env variable
On Fri, Oct 25, 2019 at 12:33:52PM -0700, amgin...@gmail.com wrote: > From: Aliasgar Ginwala > > Signed-off-by: Aliasgar Ginwala I tweaked this a little further and applied it to master as follows. Thank you! -8<--cut here-->8-- From: Aliasgar Ginwala Date: Fri, 25 Oct 2019 12:33:52 -0700 Subject: [PATCH] command-line: New function ovs_cmdl_env_parse_all(). This function allows an environment variable to be included in command-line parsing. It will receive its first user in an upcoming commit. Signed-off-by: Aliasgar Ginwala Signed-off-by: Ben Pfaff --- lib/command-line.c | 24 lib/command-line.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/lib/command-line.c b/lib/command-line.c index 9e000bd28d1a..967f4f5d5846 100644 --- a/lib/command-line.c +++ b/lib/command-line.c @@ -19,6 +19,7 @@ #include #include #include +#include "svec.h" #include "openvswitch/dynamic-string.h" #include "ovs-thread.h" #include "util.h" @@ -77,6 +78,29 @@ find_option_by_value(const struct option *options, int value) return NULL; } +/* Parses options set using environment variable. The caller specifies the + * supported options in environment variable. On success, adds the parsed + * env variables in 'argv', the number of options in 'argc', and returns argv. + * */ +char ** +ovs_cmdl_env_parse_all(int *argcp, char *argv[], const char *env_options) +{ +ovs_assert(*argcp > 0); + +struct svec args = SVEC_EMPTY_INITIALIZER; +svec_add(&args, argv[0]); +if (env_options) { +svec_parse_words(&args, env_options); +} +for (int i = 1; i < *argcp; i++) { +svec_add(&args, argv[i]); +} +svec_terminate(&args); + +*argcp = args.n; +return args.names; +} + /* Parses the command-line options in 'argc' and 'argv'. The caller specifies * the supported options in 'options'. On success, stores the parsed options * in '*pop', the number of options in '*n_pop', and returns NULL. On failure, diff --git a/lib/command-line.h b/lib/command-line.h index 9d62dc2501c5..fc2a2690f688 100644 --- a/lib/command-line.h +++ b/lib/command-line.h @@ -54,6 +54,9 @@ char *ovs_cmdl_parse_all(int argc, char *argv[], const struct option *, struct ovs_cmdl_parsed_option **, size_t *) OVS_WARN_UNUSED_RESULT; +char **ovs_cmdl_env_parse_all(int *argcp, char *argv_[], + const char *env_options); + void ovs_cmdl_print_options(const struct option *options); void ovs_cmdl_print_commands(const struct ovs_cmdl_command *commands); -- 2.21.0 ___ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev
[ovs-dev] [PATCH v3] command-line.c: Support parsing ctl options via env variable
From: Aliasgar Ginwala Signed-off-by: Aliasgar Ginwala --- lib/command-line.c | 29 + lib/command-line.h | 3 +++ 2 files changed, 32 insertions(+) diff --git a/lib/command-line.c b/lib/command-line.c index 9e000bd28..2fc8b6e48 100644 --- a/lib/command-line.c +++ b/lib/command-line.c @@ -19,6 +19,7 @@ #include #include #include +#include "svec.h" #include "openvswitch/dynamic-string.h" #include "ovs-thread.h" #include "util.h" @@ -77,6 +78,34 @@ find_option_by_value(const struct option *options, int value) return NULL; } +/* Parses options set using environment variable. The caller specifies the + * supported options in environment variable. On success, adds the parsed + * env variables in 'argv', the number of options in 'argc', and returns argv. + * */ +char ** +ovs_cmdl_env_parse_all(int *argcp, char *argv[], + char *env_options) +{ +struct svec args = SVEC_EMPTY_INITIALIZER; + +/* argv[0] stays in place. */ +ovs_assert(*argcp > 0); +svec_add(&args, argv[0]); + +/* Anything from the environment variable goes next. */ +if (env_options) { +svec_parse_words(&args, env_options); +} + +/* Remaining command-line options go at the end. */ +for (int i = 1; i < *argcp; i++) { +svec_add(&args, argv[i]); +} + +*argcp = args.n; +return args.names; +} + /* Parses the command-line options in 'argc' and 'argv'. The caller specifies * the supported options in 'options'. On success, stores the parsed options * in '*pop', the number of options in '*n_pop', and returns NULL. On failure, diff --git a/lib/command-line.h b/lib/command-line.h index 9d62dc250..4b8f76da7 100644 --- a/lib/command-line.h +++ b/lib/command-line.h @@ -54,6 +54,9 @@ char *ovs_cmdl_parse_all(int argc, char *argv[], const struct option *, struct ovs_cmdl_parsed_option **, size_t *) OVS_WARN_UNUSED_RESULT; +char **ovs_cmdl_env_parse_all(int *argcp, char *argv_[], + char *env_options); + void ovs_cmdl_print_options(const struct option *options); void ovs_cmdl_print_commands(const struct ovs_cmdl_command *commands); -- 2.20.1 (Apple Git-117) ___ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev