Skip to content

Commit 0805cde

Browse files
MDEV-25908: -e does not work for my_print_defaults
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().
1 parent e9ffed0 commit 0805cde

File tree

4 files changed

+137
-6
lines changed

4 files changed

+137
-6
lines changed

extra/my_print_defaults.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,50 @@ static int get_options(int *argc,char ***argv)
141141
return 0;
142142
}
143143

144+
static char *make_args(const char *s1, const char *s2)
145+
{
146+
char *s= malloc(strlen(s1) + strlen(s2) + 1);
147+
strmov(strmov(s, s1), s2);
148+
return s;
149+
}
144150

145151
int main(int argc, char **argv)
146152
{
147-
int count, error, args_used;
153+
int count= 0, error, no_defaults= 0;
148154
char **load_default_groups= 0, *tmp_arguments[6];
149155
char **argument, **arguments, **org_argv;
150156
int nargs, i= 0;
151157
MY_INIT(argv[0]);
152158

153159
org_argv= argv;
154-
args_used= get_defaults_options(argv);
155-
156-
/* Copy defaults-xxx arguments & program name */
157-
count=args_used;
160+
if (*argv && !strcmp(*argv, "--no-defaults"))
161+
{
162+
argv++;
163+
++count;
164+
no_defaults= 1;
165+
}
166+
/* Copy program name and --no-defaults if present*/
158167
arguments= tmp_arguments;
159-
memcpy((char*) arguments, (char*) org_argv, count * sizeof(*org_argv));
168+
memcpy((char*) arguments, (char*) org_argv, (++count)*sizeof(*org_argv));
160169
arguments[count]= 0;
161170

162171
/* Check out the args */
163172
if (get_options(&argc,&argv))
164173
cleanup_and_exit(1);
165174

175+
if (!no_defaults)
176+
{
177+
if (opt_defaults_file_used)
178+
arguments[count++]= make_args("--defaults-file=", config_file);
179+
if (my_defaults_extra_file)
180+
arguments[count++]= make_args("--defaults-extra-file=",
181+
my_defaults_extra_file);
182+
if (my_defaults_group_suffix)
183+
arguments[count++]= make_args("--defaults-group-suffix=",
184+
my_defaults_group_suffix);
185+
arguments[count]= 0;
186+
}
187+
166188
nargs= argc + 1;
167189
if (opt_mysqld)
168190
nargs+= array_elements(mysqld_groups);

mysql-test/main/my_print_defaults.result

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,41 @@
1111
--max_connections=1024
1212
--long_query_time=60
1313
--slow_query_log=1
14+
#
15+
# MDEV-25908: -e does not work for my_print_defaults
16+
#
17+
# Testing -e
18+
--key_buffer_size=20M
19+
--max_allowed_packet=250M
20+
--table_open_cache=1000
21+
#Testing --defaults-extra-file
22+
--key_buffer_size=20M
23+
--max_allowed_packet=250M
24+
--table_open_cache=1000
25+
#
26+
# Testing other options
27+
#
28+
# Testing -c option
29+
--key_buffer_size=20M
30+
--max_allowed_packet=250M
31+
--table_open_cache=1000
32+
# Testing --defaults-file
33+
--key_buffer_size=20M
34+
--max_allowed_packet=250M
35+
--table_open_cache=1000
36+
# Testing -g option
37+
--key_buffer_size=20M
38+
--max_allowed_packet=250M
39+
--table_open_cache=1000
40+
--table_definition_cache=2000
41+
--read_buffer_size=1M
42+
--thread_cache_size=8
43+
# Testing --defaults-group-suffix
44+
--key_buffer_size=20M
45+
--max_allowed_packet=250M
46+
--table_open_cache=1000
47+
--table_definition_cache=2000
48+
--read_buffer_size=1M
49+
--thread_cache_size=8
50+
# Testing --no-defaults
51+
# End of 10.5 Test

mysql-test/main/my_print_defaults.test

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,77 @@ long_query_time=60
3030
slow_query_log=1
3131
EOF
3232

33+
--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-extra-file=$MYSQLTEST_VARDIR/tmp/tmp1.cnf -c $MYSQLTEST_VARDIR/tmp/tmp2.cnf --mysqld mysql.server
34+
--remove_file $MYSQLTEST_VARDIR/tmp/tmp1.cnf
35+
--remove_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf
36+
37+
38+
--echo #
39+
--echo # MDEV-25908: -e does not work for my_print_defaults
40+
--echo #
41+
42+
--write_file $MYSQLTEST_VARDIR/tmp/tmp1.cnf
43+
44+
[mariadb]
45+
key_buffer_size=20M
46+
max_allowed_packet=250M
47+
table_open_cache=1000
48+
EOF
49+
50+
--write_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf
51+
52+
[mariadb]
53+
key_buffer_size=20M
54+
max_allowed_packet=250M
55+
table_open_cache=1000
56+
EOF
57+
58+
--echo # Testing -e
59+
--exec $MYSQL_MY_PRINT_DEFAULTS -e $MYSQLTEST_VARDIR/tmp/tmp1.cnf -c $MYSQLTEST_VARDIR/tmp/tmp2.cnf --mysqld mysql.server
60+
--echo #Testing --defaults-extra-file
3361
--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-extra-file=$MYSQLTEST_VARDIR/tmp/tmp1.cnf -c $MYSQLTEST_VARDIR/tmp/tmp2.cnf --mysqld mysql.server
3462

3563
--remove_file $MYSQLTEST_VARDIR/tmp/tmp1.cnf
3664
--remove_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf
65+
66+
--echo #
67+
--echo # Testing other options
68+
--echo #
69+
70+
71+
--write_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf
72+
[mariadb]
73+
key_buffer_size=20M
74+
max_allowed_packet=250M
75+
table_open_cache=1000
76+
EOF
77+
78+
--write_file $MYSQLTEST_VARDIR/tmp/tmp3.cnf
79+
[mariadb]
80+
key_buffer_size=20M
81+
max_allowed_packet=250M
82+
table_open_cache=1000
83+
84+
[mariadb.1]
85+
table_definition_cache=2000
86+
read_buffer_size=1M
87+
thread_cache_size=8
88+
EOF
89+
90+
--echo # Testing -c option
91+
--exec $MYSQL_MY_PRINT_DEFAULTS -c $MYSQLTEST_VARDIR/tmp/tmp2.cnf --mysqld mysql.server
92+
--echo # Testing --defaults-file
93+
--exec $MYSQL_MY_PRINT_DEFAULTS --defaults-file=$MYSQLTEST_VARDIR/tmp/tmp2.cnf --mysqld mysql.server
94+
95+
--echo # Testing -g option
96+
--exec $MYSQL_MY_PRINT_DEFAULTS -c $MYSQLTEST_VARDIR/tmp/tmp3.cnf --mysqld mysql.server -g .1
97+
--echo # Testing --defaults-group-suffix
98+
--exec $MYSQL_MY_PRINT_DEFAULTS -c $MYSQLTEST_VARDIR/tmp/tmp3.cnf --mysqld mysql.server --defaults-group-suffix=.1
99+
100+
--echo # Testing --no-defaults
101+
--exec $MYSQL_MY_PRINT_DEFAULTS --no-defaults
102+
103+
--remove_file $MYSQLTEST_VARDIR/tmp/tmp2.cnf
104+
--remove_file $MYSQLTEST_VARDIR/tmp/tmp3.cnf
105+
106+
--echo # End of 10.5 Test

mysql-test/main/mysqldump.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,6 +2688,7 @@ DROP TABLE t1, t2;
26882688
# (Problems with --defaults-extra-file option)
26892689
#
26902690
--port=1234
2691+
--port=1234
26912692
#
26922693
# Test of fix to Bug#12597 mysqldump dumps triggers wrongly
26932694
#

0 commit comments

Comments
 (0)