maria-developers team mailing list archive
-
maria-developers team
-
Mailing list archive
-
Message #12876
Re: 4645a1e1950: MDEV-26238: Remove inconsistent behaviour of --default-* options in my_print_defaults
Hi, Rucha!
On Sep 07, Rucha Deodhar wrote:
> revision-id: 4645a1e1950 (mariadb-10.6.1-72-g4645a1e1950)
> parent(s): 21ce69123c1
> author: Rucha Deodhar
> committer: Rucha Deodhar
> timestamp: 2021-09-02 22:10:37 +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(). But
> handle_options() returns error and exits if an option is not found.
> We don't want to exit and give error because --defaults* options are still
> valid. So make a new commandline which doesn't have --defaults*
> option and pass it to handle_options(). 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..e2ec0b00923 100644
> --- a/extra/my_print_defaults.c
> +++ b/extra/my_print_defaults.c
> @@ -48,20 +48,6 @@ static struct my_option my_long_options[] =
you forgot the "config-file", which is here, just about "debug"
> {"debug", '#', "Output debug log", (char**) &default_dbug_option,
> (char**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
> #endif
> - {"defaults-file", 'c',
> - "Read this file only, do not read global or per-user config "
> - "files; should be the first option",
> - (char**) &config_file, (char*) &config_file, 0, GET_STR, REQUIRED_ARG,
> - 0, 0, 0, 0, 0, 0},
> - {"defaults-extra-file", 'e',
> - "Read this file after the global config file and before the config "
> - "file in the users home directory; should be the first option",
> - (void *)&my_defaults_extra_file, (void *)&my_defaults_extra_file, 0,
> - GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
> - {"defaults-group-suffix", 'g',
> - "In addition to the given groups, read also groups with this suffix",
> - (char**) &my_defaults_group_suffix, (char**) &my_defaults_group_suffix,
> - 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
> {"mysqld", 0, "Read the same set of groups that the mysqld binary does.",
> &opt_mysqld, &opt_mysqld, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
> {"no-defaults", 'n', "Return an empty string (useful for scripts).",
> @@ -109,9 +95,6 @@ get_one_option(const struct my_option *opt __attribute__((unused)),
> const char *filename __attribute__((unused)))
> {
> switch (opt->id) {
> - case 'c':
> - opt_defaults_file_used= 1;
> - break;
> case 'n':
> cleanup_and_exit(0);
> case 'I':
> @@ -141,49 +124,44 @@ static int get_options(int *argc,char ***argv)
> return 0;
> }
>
> -static char *make_args(const char *s1, const char *s2)
> -{
> - char *s= malloc(strlen(s1) + strlen(s2) + 1);
> - strmov(strmov(s, s1), s2);
> - return s;
> -}
> -
> int main(int argc, char **argv)
> {
> - int count= 0, error, no_defaults= 0;
> + int count, error, args_used;
> char **load_default_groups= 0, *tmp_arguments[6];
> - char **argument, **arguments, **org_argv;
> - int nargs, i= 0;
> + char **argument, **arguments, **org_argv, **new_argv, **pos;
> + int nargs, i= 0, index=0;
> MY_INIT(argv[0]);
>
> org_argv= argv;
> - if (*argv && !strcmp(*argv, "--no-defaults"))
> - {
> - argv++;
> - ++count;
> - no_defaults= 1;
> - }
> - /* Copy program name and --no-defaults if present*/
> + 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));
> + memcpy((char*) arguments, (char*) org_argv, count*sizeof(*org_argv));
> arguments[count]= 0;
>
> - /* Check out the args */
> - if (get_options(&argc,&argv))
> - cleanup_and_exit(1);
> -
> - if (!no_defaults)
> + /*
> + We already process --defaults* options at the beginning in
> + get_defaults_options(). So, now we we make a new commandline which
> + has all options except --defaults* options and pass it to handle_options()
> + instead of original commandline.
> + */
> + new_argv= (char**)malloc(argc*sizeof(*org_argv));
> + for (pos= org_argv; *pos; pos++)
> {
> + if (!is_prefix(*pos, "--defaults-extra-file=") &&
> + !is_prefix(*pos, "--defaults-file=") &&
> + !is_prefix(*pos, "--defaults-group-suffix="))
> + new_argv[index++]= *(pos);
Why are you doing it?
After get_defaults_options, you know how many arguments were default,
just skip args_used, and invoke handle_options on the rest.
Regards,
Sergei
VP of MariaDB Server Engineering
and security@xxxxxxxxxxx