Skip to content

Commit

Permalink
MDEV-25908: -e does not work for my_print_defaults
Browse files Browse the repository at this point in the history
Analysis: get_defaults_options() rewrites the value for my_defaults_file,
my_defaults_extra_file and  my_defaults_group_suffix to 0. So the config file
can't be read.
Fix: Let handle_options() handle --defaults* option and create a new command
line to pass it to load_defaults().
  • Loading branch information
mariadb-RuchaDeodhar committed Jul 26, 2021
1 parent e9ffed0 commit 0805cde
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 6 deletions.
34 changes: 28 additions & 6 deletions extra/my_print_defaults.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,28 +141,50 @@ 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, error, args_used;
int count= 0, error, no_defaults= 0;
char **load_default_groups= 0, *tmp_arguments[6];
char **argument, **arguments, **org_argv;
int nargs, i= 0;
MY_INIT(argv[0]);

org_argv= argv;
args_used= get_defaults_options(argv);

/* Copy defaults-xxx arguments & program name */
count=args_used;
if (*argv && !strcmp(*argv, "--no-defaults"))
{
argv++;
++count;
no_defaults= 1;
}
/* Copy program name and --no-defaults if present*/
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)
{
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);
Expand Down
38 changes: 38 additions & 0 deletions mysql-test/main/my_print_defaults.result
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,41 @@
--max_connections=1024
--long_query_time=60
--slow_query_log=1
#
# 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
--table_open_cache=1000
#
# 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
--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
--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
70 changes: 70 additions & 0 deletions mysql-test/main/my_print_defaults.test
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,77 @@ 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
--remove_file $MYSQLTEST_VARDIR/tmp/tmp1.cnf
--remove_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf


--echo #
--echo # MDEV-25908: -e does not work for 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=20M
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

--remove_file $MYSQLTEST_VARDIR/tmp/tmp1.cnf
--remove_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf

--echo #
--echo # Testing other options
--echo #


--write_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf
[mariadb]
key_buffer_size=20M
max_allowed_packet=250M
table_open_cache=1000
EOF

--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 -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

--echo # Testing --no-defaults
--exec $MYSQL_MY_PRINT_DEFAULTS --no-defaults

--remove_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf
--remove_file $MYSQLTEST_VARDIR/tmp/tmp3.cnf

--echo # End of 10.5 Test
1 change: 1 addition & 0 deletions mysql-test/main/mysqldump.result
Original file line number Diff line number Diff line change
Expand Up @@ -2688,6 +2688,7 @@ DROP TABLE t1, t2;
# (Problems with --defaults-extra-file option)
#
--port=1234
--port=1234
#
# Test of fix to Bug#12597 mysqldump dumps triggers wrongly
#
Expand Down

0 comments on commit 0805cde

Please sign in to comment.