mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
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.
This commit is contained in:
committed by
Sergei Golubchik
parent
b18697fd3e
commit
5217211e07
@@ -48,20 +48,6 @@ static struct my_option my_long_options[] =
|
|||||||
{"debug", '#', "Output debug log", (char**) &default_dbug_option,
|
{"debug", '#', "Output debug log", (char**) &default_dbug_option,
|
||||||
(char**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
|
(char**) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
|
||||||
#endif
|
#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.",
|
{"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},
|
&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).",
|
{"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)))
|
const char *filename __attribute__((unused)))
|
||||||
{
|
{
|
||||||
switch (opt->id) {
|
switch (opt->id) {
|
||||||
case 'c':
|
|
||||||
opt_defaults_file_used= 1;
|
|
||||||
break;
|
|
||||||
case 'n':
|
case 'n':
|
||||||
cleanup_and_exit(0);
|
cleanup_and_exit(0);
|
||||||
case 'I':
|
case 'I':
|
||||||
@@ -141,49 +124,34 @@ static int get_options(int *argc,char ***argv)
|
|||||||
return 0;
|
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 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 **load_default_groups= 0, *tmp_arguments[6];
|
||||||
char **argument, **arguments, **org_argv;
|
char **argument, **arguments, **org_argv;
|
||||||
int nargs, i= 0;
|
int nargs, i= 0;
|
||||||
MY_INIT(argv[0]);
|
MY_INIT(argv[0]);
|
||||||
|
|
||||||
org_argv= argv;
|
org_argv= argv;
|
||||||
if (*argv && !strcmp(*argv, "--no-defaults"))
|
args_used= get_defaults_options(argv);
|
||||||
{
|
|
||||||
argv++;
|
/* Copy defaults-xxx arguments & program name */
|
||||||
++count;
|
count= args_used;
|
||||||
no_defaults= 1;
|
|
||||||
}
|
|
||||||
/* Copy program name and --no-defaults if present*/
|
|
||||||
arguments= tmp_arguments;
|
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;
|
arguments[count]= 0;
|
||||||
|
|
||||||
/* Check out the args */
|
/*
|
||||||
if (get_options(&argc,&argv))
|
We already process --defaults* options at the beginning in
|
||||||
cleanup_and_exit(1);
|
get_defaults_options(). So skip --defaults* options and
|
||||||
|
pass remaining options to handle_options().
|
||||||
|
*/
|
||||||
|
org_argv+=args_used-1;
|
||||||
|
argc-=args_used-1;
|
||||||
|
|
||||||
if (!no_defaults)
|
/* Check out the args */
|
||||||
{
|
if (get_options(&argc,&org_argv))
|
||||||
if (opt_defaults_file_used)
|
cleanup_and_exit(1);
|
||||||
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;
|
nargs= argc + 1;
|
||||||
if (opt_mysqld)
|
if (opt_mysqld)
|
||||||
@@ -201,7 +169,7 @@ int main(int argc, char **argv)
|
|||||||
for (; mysqld_groups[i]; i++)
|
for (; mysqld_groups[i]; i++)
|
||||||
load_default_groups[i]= (char*) mysqld_groups[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,
|
if ((error= load_defaults(config_file, (const char **) load_default_groups,
|
||||||
&count, &arguments)))
|
&count, &arguments)))
|
||||||
{
|
{
|
||||||
|
@@ -14,10 +14,6 @@
|
|||||||
#
|
#
|
||||||
# MDEV-25908: -e does not work for my_print_defaults
|
# MDEV-25908: -e does not work for my_print_defaults
|
||||||
#
|
#
|
||||||
# Testing -e
|
|
||||||
--key_buffer_size=20M
|
|
||||||
--max_allowed_packet=250M
|
|
||||||
--table_open_cache=1000
|
|
||||||
#Testing --defaults-extra-file
|
#Testing --defaults-extra-file
|
||||||
--key_buffer_size=20M
|
--key_buffer_size=20M
|
||||||
--max_allowed_packet=250M
|
--max_allowed_packet=250M
|
||||||
@@ -25,21 +21,10 @@
|
|||||||
#
|
#
|
||||||
# Testing other options
|
# Testing other options
|
||||||
#
|
#
|
||||||
# Testing -c option
|
|
||||||
--key_buffer_size=20M
|
|
||||||
--max_allowed_packet=250M
|
|
||||||
--table_open_cache=1000
|
|
||||||
# Testing --defaults-file
|
# Testing --defaults-file
|
||||||
--key_buffer_size=20M
|
--key_buffer_size=20M
|
||||||
--max_allowed_packet=250M
|
--max_allowed_packet=250M
|
||||||
--table_open_cache=1000
|
--table_open_cache=1000
|
||||||
# Testing -g option
|
|
||||||
--key_buffer_size=20M
|
|
||||||
--max_allowed_packet=250M
|
|
||||||
--table_open_cache=1000
|
|
||||||
--table_definition_cache=2000
|
|
||||||
--read_buffer_size=1M
|
|
||||||
--thread_cache_size=8
|
|
||||||
# Testing --defaults-group-suffix
|
# Testing --defaults-group-suffix
|
||||||
--key_buffer_size=20M
|
--key_buffer_size=20M
|
||||||
--max_allowed_packet=250M
|
--max_allowed_packet=250M
|
||||||
@@ -49,3 +34,25 @@
|
|||||||
--thread_cache_size=8
|
--thread_cache_size=8
|
||||||
# Testing --no-defaults
|
# Testing --no-defaults
|
||||||
# End of 10.5 Test
|
# End of 10.5 Test
|
||||||
|
# Beginning of 10.7 test
|
||||||
|
#
|
||||||
|
# MDEV-26238: Remove inconsistent behaviour of --default-* options in
|
||||||
|
# my_print_defaults
|
||||||
|
#
|
||||||
|
# checking that --defaults* option only works when mentioned at beginning
|
||||||
|
# Testing --defaults-file at beginning only
|
||||||
|
--key_buffer_size=20M
|
||||||
|
--max_allowed_packet=250M
|
||||||
|
--table_open_cache=1000
|
||||||
|
# Testing --defaults-extra-file works at beginning only
|
||||||
|
--key_buffer_size=20M
|
||||||
|
--max_allowed_packet=250M
|
||||||
|
--table_open_cache=1000
|
||||||
|
# Testing --defaults-group-suffix works at beginning only
|
||||||
|
--key_buffer_size=20M
|
||||||
|
--max_allowed_packet=250M
|
||||||
|
--table_open_cache=1000
|
||||||
|
--table_definition_cache=2000
|
||||||
|
--read_buffer_size=1M
|
||||||
|
--thread_cache_size=8
|
||||||
|
# End of 10.7 test
|
||||||
|
@@ -30,7 +30,7 @@ long_query_time=60
|
|||||||
slow_query_log=1
|
slow_query_log=1
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-extra-file=$MYSQLTEST_VARDIR/tmp/tmp1.cnf -c $MYSQLTEST_VARDIR/tmp/tmp2.cnf --mysqld mysql.server
|
--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-extra-file=$MYSQLTEST_VARDIR/tmp/tmp1.cnf --defaults-file=$MYSQLTEST_VARDIR/tmp/tmp2.cnf --mysqld mysql.server
|
||||||
--remove_file $MYSQLTEST_VARDIR/tmp/tmp1.cnf
|
--remove_file $MYSQLTEST_VARDIR/tmp/tmp1.cnf
|
||||||
--remove_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf
|
--remove_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf
|
||||||
|
|
||||||
@@ -55,10 +55,8 @@ max_allowed_packet=250M
|
|||||||
table_open_cache=1000
|
table_open_cache=1000
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
--echo # Testing -e
|
|
||||||
--exec $MYSQL_MY_PRINT_DEFAULTS -e $MYSQLTEST_VARDIR/tmp/tmp1.cnf -c $MYSQLTEST_VARDIR/tmp/tmp2.cnf --mysqld mysql.server
|
|
||||||
--echo #Testing --defaults-extra-file
|
--echo #Testing --defaults-extra-file
|
||||||
--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-extra-file=$MYSQLTEST_VARDIR/tmp/tmp1.cnf -c $MYSQLTEST_VARDIR/tmp/tmp2.cnf --mysqld mysql.server
|
--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-extra-file=$MYSQLTEST_VARDIR/tmp/tmp1.cnf --defaults-file=$MYSQLTEST_VARDIR/tmp/tmp2.cnf --mysqld mysql.server
|
||||||
|
|
||||||
--remove_file $MYSQLTEST_VARDIR/tmp/tmp1.cnf
|
--remove_file $MYSQLTEST_VARDIR/tmp/tmp1.cnf
|
||||||
--remove_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf
|
--remove_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf
|
||||||
@@ -87,20 +85,80 @@ read_buffer_size=1M
|
|||||||
thread_cache_size=8
|
thread_cache_size=8
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
--echo # Testing -c option
|
|
||||||
--exec $MYSQL_MY_PRINT_DEFAULTS -c $MYSQLTEST_VARDIR/tmp/tmp2.cnf --mysqld mysql.server
|
|
||||||
--echo # Testing --defaults-file
|
--echo # Testing --defaults-file
|
||||||
--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-file=$MYSQLTEST_VARDIR/tmp/tmp2.cnf --mysqld mysql.server
|
--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-file=$MYSQLTEST_VARDIR/tmp/tmp2.cnf --mysqld mysql.server
|
||||||
|
|
||||||
--echo # Testing -g option
|
|
||||||
--exec $MYSQL_MY_PRINT_DEFAULTS -c $MYSQLTEST_VARDIR/tmp/tmp3.cnf --mysqld mysql.server -g .1
|
|
||||||
--echo # Testing --defaults-group-suffix
|
--echo # Testing --defaults-group-suffix
|
||||||
--exec $MYSQL_MY_PRINT_DEFAULTS -c $MYSQLTEST_VARDIR/tmp/tmp3.cnf --mysqld mysql.server --defaults-group-suffix=.1
|
--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-file=$MYSQLTEST_VARDIR/tmp/tmp3.cnf --defaults-group-suffix=.1 --mysqld mysql.server
|
||||||
|
|
||||||
--echo # Testing --no-defaults
|
--echo # Testing --no-defaults
|
||||||
--exec $MYSQL_MY_PRINT_DEFAULTS --no-defaults
|
--exec $MYSQL_MY_PRINT_DEFAULTS --no-defaults --mysqld
|
||||||
|
|
||||||
--remove_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf
|
--remove_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf
|
||||||
--remove_file $MYSQLTEST_VARDIR/tmp/tmp3.cnf
|
--remove_file $MYSQLTEST_VARDIR/tmp/tmp3.cnf
|
||||||
|
|
||||||
--echo # End of 10.5 Test
|
--echo # End of 10.5 Test
|
||||||
|
|
||||||
|
--echo # Beginning of 10.7 test
|
||||||
|
|
||||||
|
--echo #
|
||||||
|
--echo # MDEV-26238: Remove inconsistent behaviour of --default-* options in
|
||||||
|
--echo # my_print_defaults
|
||||||
|
--echo #
|
||||||
|
|
||||||
|
--write_file $MYSQLTEST_VARDIR/tmp/tmp1.cnf
|
||||||
|
[mariadb]
|
||||||
|
key_buffer_size=20M
|
||||||
|
max_allowed_packet=250M
|
||||||
|
table_open_cache=1000
|
||||||
|
EOF
|
||||||
|
|
||||||
|
--write_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf
|
||||||
|
[mariadb]
|
||||||
|
key_buffer_size=10M
|
||||||
|
max_allowed_packet=250M
|
||||||
|
table_open_cache=1000
|
||||||
|
EOF
|
||||||
|
|
||||||
|
--write_file $MYSQLTEST_VARDIR/tmp/tmp3.cnf
|
||||||
|
[mariadb]
|
||||||
|
key_buffer_size=30M
|
||||||
|
max_allowed_packet=250M
|
||||||
|
table_open_cache=1000
|
||||||
|
EOF
|
||||||
|
|
||||||
|
--echo # checking that --defaults* option only works when mentioned at beginning
|
||||||
|
|
||||||
|
--echo # Testing --defaults-file at beginning only
|
||||||
|
--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-file=$MYSQLTEST_VARDIR/tmp/tmp1.cnf --mysqld
|
||||||
|
--error 7
|
||||||
|
--exec $MYSQL_MY_PRINT_DEFAULTS --mysqld --defaults-file=$MYSQLTEST_VARDIR/tmp/tmp1.cnf
|
||||||
|
--remove_file $MYSQLTEST_VARDIR/tmp/tmp3.cnf
|
||||||
|
|
||||||
|
--echo # Testing --defaults-extra-file works at beginning only
|
||||||
|
--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-file=$MYSQLTEST_VARDIR/tmp/tmp1.cnf --defaults-extra-file=$MYSQLTEST_VARDIR/tmp/tmp2.cnf --mysqld
|
||||||
|
--error 7
|
||||||
|
--exec $MYSQL_MY_PRINT_DEFAULTS --mysqld --defaults-file=$MYSQLTEST_VARDIR/tmp/tmp1.cnf --defaults-extra-file=$MYSQLTEST_VARDIR/tmp/tmp2.cnf
|
||||||
|
|
||||||
|
--write_file $MYSQLTEST_VARDIR/tmp/tmp3.cnf
|
||||||
|
[mariadb]
|
||||||
|
key_buffer_size=20M
|
||||||
|
max_allowed_packet=250M
|
||||||
|
table_open_cache=1000
|
||||||
|
|
||||||
|
[mariadb.1]
|
||||||
|
table_definition_cache=2000
|
||||||
|
read_buffer_size=1M
|
||||||
|
thread_cache_size=8
|
||||||
|
EOF
|
||||||
|
|
||||||
|
--echo # Testing --defaults-group-suffix works at beginning only
|
||||||
|
--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-file=$MYSQLTEST_VARDIR/tmp/tmp3.cnf --defaults-group-suffix=.1 --mysqld
|
||||||
|
--error 7
|
||||||
|
--exec $MYSQL_MY_PRINT_DEFAULTS --mysqld --defaults-file=$MYSQLTEST_VARDIR/tmp/tmp3.cnf --defaults-group-suffix=.1
|
||||||
|
|
||||||
|
--remove_file $MYSQLTEST_VARDIR/tmp/tmp1.cnf
|
||||||
|
--remove_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf
|
||||||
|
--remove_file $MYSQLTEST_VARDIR/tmp/tmp3.cnf
|
||||||
|
|
||||||
|
--echo # End of 10.7 test
|
||||||
|
@@ -964,8 +964,8 @@ DROP TABLE t1, t2;
|
|||||||
[mysqltest1]
|
[mysqltest1]
|
||||||
port=1234
|
port=1234
|
||||||
EOF
|
EOF
|
||||||
--exec $MYSQL_MY_PRINT_DEFAULTS -c $MYSQLTEST_VARDIR/tmp/tmp.cnf mysqltest1
|
--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-file=$MYSQLTEST_VARDIR/tmp/tmp.cnf mysqltest1
|
||||||
--exec $MYSQL_MY_PRINT_DEFAULTS -e $MYSQLTEST_VARDIR/tmp/tmp.cnf mysqltest1 mysqltest1
|
--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-extra-file=$MYSQLTEST_VARDIR/tmp/tmp.cnf mysqltest1 mysqltest1
|
||||||
--remove_file $MYSQLTEST_VARDIR/tmp/tmp.cnf
|
--remove_file $MYSQLTEST_VARDIR/tmp/tmp.cnf
|
||||||
|
|
||||||
--echo #
|
--echo #
|
||||||
|
Reference in New Issue
Block a user