[Spice-devel] [PATCH x11spice 1/2] Bug fix: --config=<filename> did not work.

Uri Lublin uril at redhat.com
Thu Jul 18 15:21:41 UTC 2019


On 7/18/19 5:31 PM, Jeremy White wrote:
> Signed-off-by: Jeremy White <jwhite at codeweavers.com>

Hi,

The patch looks good to me.
See a comment below.

> ---
>   src/options.c | 24 ++++++++++++++++++++++--
>   1 file changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/src/options.c b/src/options.c
> index b7f487c5..0d3138d0 100644
> --- a/src/options.c
> +++ b/src/options.c
> @@ -213,14 +213,34 @@ void options_handle_ssl_file_options(options_t *options,
>       options->ssl.ciphersuite = string_option(userkey, systemkey, "ssl", "ciphersuite");
>   }
>   
> +/* In general, we want to parse the config file options before the command line
> +**  arguments.  However, the command line argument to specify a config file is
> +**  the exception.  We manually parse this out now, so we can simplify the
> +**  flow of control later. */
>   void options_handle_user_config(int argc, char *argv[], options_t *options)
>   {
>       int i;
> -    for (i = 1; i < argc - 1; i++)
> -        if (strcmp(argv[i], "--config") == 0 || strcmp(argv[i], "-config") == 0) {
> +    char *p, *q;
> +
> +    /* getopt long is complex; it supports [-]-config[=]filename */

I too find it confusing.
Note that this is the behavior of getopt_long_only.
We can switch to using getopt_long (but you would still need to
look for '=').

Uri.

> +    for (i = 1; i < argc; i++) {
> +        p = strstr(argv[i], "--config");
> +        if (p != argv[i]) {
> +            p = strstr(argv[i], "-config");
> +        }
> +        if (p != argv[i]) {
> +            continue;
> +        }
> +        q = strstr(p, "=");
> +        if (q) {
> +            options->user_config_file = strdup(q + 1);
> +            continue;
> +        }
> +        if (i < argc - 1) {
>               options->user_config_file = strdup(argv[i + 1]);
>               i++;
>           }
> +    }
>   }
>   
>   int options_parse_arguments(int argc, char *argv[], options_t *options)
> 



More information about the Spice-devel mailing list