diff options
author | Rucha Deodhar <rucha.deodhar@mariadb.com> | 2021-09-01 19:09:01 +0530 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2022-01-26 18:43:06 +0100 |
commit | 5217211e071d1c9943026b429baaaffe8ef8414a (patch) | |
tree | a1b2e84d10d81b2c0908d769e62b6bb765ac5e5e | |
parent | b18697fd3eb9bc2d88c03869109bcebcdf55a9a1 (diff) | |
download | mariadb-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.
-rw-r--r-- | extra/my_print_defaults.c | 64 | ||||
-rw-r--r-- | mysql-test/main/my_print_defaults.result | 31 | ||||
-rw-r--r-- | mysql-test/main/my_print_defaults.test | 78 | ||||
-rw-r--r-- | mysql-test/main/mysqldump.test | 4 |
4 files changed, 105 insertions, 72 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))) { diff --git a/mysql-test/main/my_print_defaults.result b/mysql-test/main/my_print_defaults.result index 64aa7b45ca8..45765de0a1a 100644 --- a/mysql-test/main/my_print_defaults.result +++ b/mysql-test/main/my_print_defaults.result @@ -14,10 +14,6 @@ # # 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 --key_buffer_size=20M --max_allowed_packet=250M @@ -25,27 +21,38 @@ # # Testing other options # -# Testing -c option ---key_buffer_size=20M ---max_allowed_packet=250M ---table_open_cache=1000 # Testing --defaults-file --key_buffer_size=20M --max_allowed_packet=250M --table_open_cache=1000 -# Testing -g option +# Testing --defaults-group-suffix --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 --no-defaults +# 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 -# Testing --no-defaults -# End of 10.5 Test +# End of 10.7 test diff --git a/mysql-test/main/my_print_defaults.test b/mysql-test/main/my_print_defaults.test index bfd4e563826..bb650f49e83 100644 --- a/mysql-test/main/my_print_defaults.test +++ b/mysql-test/main/my_print_defaults.test @@ -30,7 +30,7 @@ long_query_time=60 slow_query_log=1 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/tmp2.cnf @@ -55,10 +55,8 @@ max_allowed_packet=250M table_open_cache=1000 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 ---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/tmp2.cnf @@ -87,20 +85,80 @@ read_buffer_size=1M thread_cache_size=8 EOF ---echo # Testing -c option ---exec $MYSQL_MY_PRINT_DEFAULTS -c $MYSQLTEST_VARDIR/tmp/tmp2.cnf --mysqld mysql.server --echo # Testing --defaults-file --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 ---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 ---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/tmp3.cnf --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 diff --git a/mysql-test/main/mysqldump.test b/mysql-test/main/mysqldump.test index 3b8130be5f8..0786cf6f803 100644 --- a/mysql-test/main/mysqldump.test +++ b/mysql-test/main/mysqldump.test @@ -964,8 +964,8 @@ DROP TABLE t1, t2; [mysqltest1] port=1234 EOF ---exec $MYSQL_MY_PRINT_DEFAULTS -c $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-file=$MYSQLTEST_VARDIR/tmp/tmp.cnf mysqltest1 +--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-extra-file=$MYSQLTEST_VARDIR/tmp/tmp.cnf mysqltest1 mysqltest1 --remove_file $MYSQLTEST_VARDIR/tmp/tmp.cnf --echo # |