summaryrefslogtreecommitdiff
path: root/extra/my_print_defaults.c
diff options
context:
space:
mode:
authorRucha Deodhar <rucha.deodhar@mariadb.com>2021-09-01 19:09:01 +0530
committerSergei Golubchik <serg@mariadb.org>2022-01-26 18:43:06 +0100
commit5217211e071d1c9943026b429baaaffe8ef8414a (patch)
treea1b2e84d10d81b2c0908d769e62b6bb765ac5e5e /extra/my_print_defaults.c
parentb18697fd3eb9bc2d88c03869109bcebcdf55a9a1 (diff)
downloadmariadb-git-5217211e071d1c9943026b429baaaffe8ef8414a.tar.gz
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 and pass rest of them to handle_options(). Also, removed -e, -g and -c because only my_print_defaults supports them.
Diffstat (limited to 'extra/my_print_defaults.c')
-rw-r--r--extra/my_print_defaults.c64
1 files changed, 16 insertions, 48 deletions
diff --git a/extra/my_print_defaults.c b/extra/my_print_defaults.c
index b7f52382721..ef2f483556a 100644
--- a/extra/my_print_defaults.c
+++ b/extra/my_print_defaults.c
@@ -48,20 +48,6 @@ static struct my_option my_long_options[] =
{"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,50 +124,35 @@ 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;
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;
+ /*
+ We already process --defaults* options at the beginning in
+ get_defaults_options(). So skip --defaults* options and
+ pass remaining options to handle_options().
+ */
+ org_argv+=args_used-1;
+ argc-=args_used-1;
+
/* Check out the args */
- if (get_options(&argc,&argv))
+ if (get_options(&argc,&org_argv))
cleanup_and_exit(1);
- if (!no_defaults)
- {
- if (opt_defaults_file_used)
- arguments[count++]= make_args("--defaults-file=", config_file);
- if (my_defaults_extra_file)
- arguments[count++]= make_args("--defaults-extra-file=",
- my_defaults_extra_file);
- if (my_defaults_group_suffix)
- arguments[count++]= make_args("--defaults-group-suffix=",
- my_defaults_group_suffix);
- arguments[count]= 0;
- }
-
nargs= argc + 1;
if (opt_mysqld)
nargs+= array_elements(mysqld_groups);
@@ -201,7 +169,7 @@ int main(int argc, char **argv)
for (; mysqld_groups[i]; i++)
load_default_groups[i]= (char*) mysqld_groups[i];
}
- memcpy(load_default_groups + i, argv, (argc + 1) * sizeof(*argv));
+ memcpy(load_default_groups + i, org_argv, (argc + 1) * sizeof(*org_argv));
if ((error= load_defaults(config_file, (const char **) load_default_groups,
&count, &arguments)))
{