← Back to team overview

maria-developers team mailing list archive

Re: a00410a2ee4: MDEV-26238: Remove inconsistent behaviour of --default-* options in my_print_defaults

 

Hi, Rucha!

On Sep 11, Rucha Deodhar wrote:
> revision-id: a00410a2ee4 (mariadb-10.6.1-77-ga00410a2ee4)
> parent(s): 76149650764
> author: Rucha Deodhar
> committer: Rucha Deodhar
> timestamp: 2021-09-11 16:30:38 +0530
> message:
> 
> MDEV-26238: Remove inconsistent behaviour of --default-* options
> in my_print_defaults
> 
> Analysis: --defaults* option is recognized anywhere in the commandline
> instead of only at the beginning because handle_options() recognizes
> options in any order.
> Fix: use get_defaults_options() which recognizes --defaults* options only at
> the beginning. After this is done, we only want to recognize other options
> given in any order which can be done using handle_options(). So (only) skip
> --defaults* options, combine it with program name to pass it to handle_options()
> (because we skip program name in handle_options() too). Also, removed -e, -g and
> -c because only my_print_defaults supports them.
> 
> diff --git a/extra/my_print_defaults.c b/extra/my_print_defaults.c
> index b7f52382721..0253614b410 100644
> --- a/extra/my_print_defaults.c
>  ++ b/extra/my_print_defaults.c
> @@ -141,50 +124,49 @@ static int get_options(int *argc,char ***argv)
>    return 0;
>  }
>  
>  int main(int argc, char **argv)
>  {
>    int count, error, args_used;
>    char **load_default_groups= 0, *tmp_arguments[6];
>    char **argument, **arguments, **org_argv, **new_argv, **pos;
>    int nargs, i= 0, index=1;
>    MY_INIT(argv[0]);
>  
>    org_argv= argv;
>    args_used= get_defaults_options(argv);
>  
>    /* Copy defaults-xxx arguments & program name */
>    count= args_used;
>    arguments= tmp_arguments;
>    memcpy((char*) arguments, (char*) org_argv, count*sizeof(*org_argv));
>    arguments[count]= 0;

you're still overdoing it. you can do just

    argv+= args_used-1;
    argc+= args_used-1;
    get_options(&argc,&argv);

no need to allocate or copy anything. Isn't it simpler?

>    /*
>       We already process --defaults* options at the beginning in
>       get_defaults_options(). So skip only --defaults* options and
>       pass program name and remaining options to handle_options().
>    */
>  
>    new_argv= (char**)malloc(argc*sizeof(*org_argv));
>    memcpy((char*)new_argv, (char*)org_argv, 1*(sizeof(*new_argv)));
>    org_argv++;
>  
>    /* We want to skip --defaults* option only */
>    if (!is_prefix(*org_argv, "--no-defaults"))
>      org_argv+= args_used-1;
>  
>    for (pos= org_argv; *pos; pos++)
>       new_argv[index++]= *(pos);
>  
>    new_argv[index]= 0;
>    argc= index;
>  
>    memcpy((char*)argv, (char*)new_argv, index*(sizeof(*new_argv)));
>  
>    /* Check out the args. */
>    if (get_options(&argc,&argv))
>      cleanup_and_exit(1);
>  
>    nargs= argc + 1;
>    if (opt_mysqld)
>      nargs+= array_elements(mysqld_groups);
Regards,
Sergei
VP of MariaDB Server Engineering
and security@xxxxxxxxxxx