#At file:///Users/malff/BZR_TREE/mysql-trunk-bugfixing-55873/ based on revid:jonathan.perkin@stripped
3197 Marc Alff 2010-08-11
Bug#55873 short startup options do not work in 5.5
Before this fix, the server did not recognize 'short' (as in -a) options
but only 'long' (as in --ansi) options in the startup command line.
The root cause is that handle_options() did not honor the my_getopt_skip_unknown flag
when parsing 'short' options.
The fix changes handle_options(), so that my_getopt_skip_unknown is honored in all cases.
added:
mysql-test/suite/perfschema/r/bad_option_3.result
mysql-test/suite/perfschema/r/bad_option_4.result
mysql-test/suite/perfschema/r/short_option.result
mysql-test/suite/perfschema/t/bad_option_3.test
mysql-test/suite/perfschema/t/bad_option_4.test
mysql-test/suite/perfschema/t/short_option-master.opt
mysql-test/suite/perfschema/t/short_option.test
modified:
mysys/my_getopt.c
=== added file 'mysql-test/suite/perfschema/r/bad_option_3.result'
--- a/mysql-test/suite/perfschema/r/bad_option_3.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/perfschema/r/bad_option_3.result 2010-08-11 17:00:26 +0000
@@ -0,0 +1,2 @@
+Found: unknown option '-x'
+Found: Aborting
=== added file 'mysql-test/suite/perfschema/r/bad_option_4.result'
--- a/mysql-test/suite/perfschema/r/bad_option_4.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/perfschema/r/bad_option_4.result 2010-08-11 17:00:26 +0000
@@ -0,0 +1,4 @@
+Found: bad_option_h_param
+Found: bad_option_h_param
+Found: bad_option_h_param
+Found: Aborting
=== added file 'mysql-test/suite/perfschema/r/short_option.result'
--- a/mysql-test/suite/perfschema/r/short_option.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/perfschema/r/short_option.result 2010-08-11 17:00:26 +0000
@@ -0,0 +1,6 @@
+select 'Ok, the server started' as result;
+result
+Ok, the server started
+select @@SQL_MODE;
+@@SQL_MODE
+REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ANSI
=== added file 'mysql-test/suite/perfschema/t/bad_option_3.test'
--- a/mysql-test/suite/perfschema/t/bad_option_3.test 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/perfschema/t/bad_option_3.test 2010-08-11 17:00:26 +0000
@@ -0,0 +1,49 @@
+# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
+
+# Tests for PERFORMANCE_SCHEMA
+# Check error handling for invalid server start options
+
+--source include/not_embedded.inc
+--source include/have_perfschema.inc
+
+let $outfile= $MYSQLTEST_VARDIR/tmp/bad_option_3.txt;
+--error 0,1
+--remove_file $outfile
+--error 2
+--exec $MYSQLD_BOOTSTRAP_CMD --loose-console -a -x > $outfile 2>&1
+
+perl;
+ use strict;
+ use warnings;
+ my $fname= "$ENV{'MYSQLTEST_VARDIR'}/tmp/bad_option_3.txt";
+ open(FILE, "<", $fname) or die;
+ my @lines= <FILE>;
+ # those must be in the file for the test to pass
+ my @patterns=
+ ("unknown option '-x'",
+ "Aborting");
+ foreach my $one_line (@lines)
+ {
+ foreach my $one_pattern (@patterns)
+ {
+ # print pattern, not line, to get a stable output
+ print "Found: $one_pattern\n" if ($one_line =~ /$one_pattern/);
+ }
+ }
+ close FILE;
+EOF
+--remove_file $outfile
+
=== added file 'mysql-test/suite/perfschema/t/bad_option_4.test'
--- a/mysql-test/suite/perfschema/t/bad_option_4.test 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/perfschema/t/bad_option_4.test 2010-08-11 17:00:26 +0000
@@ -0,0 +1,49 @@
+# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
+
+# Tests for PERFORMANCE_SCHEMA
+# Check error handling for invalid server start options
+
+--source include/not_embedded.inc
+--source include/have_perfschema.inc
+
+let $outfile= $MYSQLTEST_VARDIR/tmp/bad_option_4.txt;
+--error 0,1
+--remove_file $outfile
+--error 1
+--exec $MYSQLD_BOOTSTRAP_CMD --loose-console -a -h bad_option_h_param > $outfile 2>&1
+
+perl;
+ use strict;
+ use warnings;
+ my $fname= "$ENV{'MYSQLTEST_VARDIR'}/tmp/bad_option_4.txt";
+ open(FILE, "<", $fname) or die;
+ my @lines= <FILE>;
+ # those must be in the file for the test to pass
+ my @patterns=
+ ("bad_option_h_param",
+ "Aborting");
+ foreach my $one_line (@lines)
+ {
+ foreach my $one_pattern (@patterns)
+ {
+ # print pattern, not line, to get a stable output
+ print "Found: $one_pattern\n" if ($one_line =~ /$one_pattern/);
+ }
+ }
+ close FILE;
+EOF
+--remove_file $outfile
+
=== added file 'mysql-test/suite/perfschema/t/short_option-master.opt'
--- a/mysql-test/suite/perfschema/t/short_option-master.opt 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/perfschema/t/short_option-master.opt 2010-08-11 17:00:26 +0000
@@ -0,0 +1 @@
+-a
=== added file 'mysql-test/suite/perfschema/t/short_option.test'
--- a/mysql-test/suite/perfschema/t/short_option.test 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/perfschema/t/short_option.test 2010-08-11 17:00:26 +0000
@@ -0,0 +1,23 @@
+# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
+
+# Tests for PERFORMANCE_SCHEMA
+# Check server start for short server start options
+
+select 'Ok, the server started' as result;
+
+# Should contain ANSI, since we started the server with -a (stands for --ansi)
+select @@SQL_MODE;
+
=== modified file 'mysys/my_getopt.c'
--- a/mysys/my_getopt.c 2010-07-16 21:00:50 +0000
+++ b/mysys/my_getopt.c 2010-08-11 17:00:26 +0000
@@ -464,6 +464,17 @@ int handle_options(int *argc, char ***ar
}
if (!opt_found)
{
+ if (my_getopt_skip_unknown)
+ {
+ /*
+ Preserve this unknown short option.
+ If there are any parameters associated with this short option,
+ as in "-X p1 p2 p3", parameters like p1 p2 p3 will be copied
+ in the result by the outer loop.
+ */
+ (*argv)[argvpos++]= *pos;
+ break;
+ }
if (my_getopt_print_errors)
my_getopt_error_reporter(ERROR_LEVEL,
"%s: unknown option '-%c'",
@@ -471,15 +482,21 @@ int handle_options(int *argc, char ***ar
return EXIT_UNKNOWN_OPTION;
}
}
- (*argc)--; /* option handled (short), decrease argument count */
- continue;
+ if (opt_found)
+ {
+ (*argc)--; /* option handled (short), decrease argument count */
+ continue;
+ }
}
if ((error= setval(optp, value, argument, set_maximum_value)))
return error;
if (get_one_option && get_one_option(optp->id, optp, argument))
return EXIT_UNSPECIFIED_ERROR;
- (*argc)--; /* option handled (short or long), decrease argument count */
+ if (opt_found)
+ {
+ (*argc)--; /* option handled (short or long), decrease argument count */
+ }
}
else /* non-option found */
(*argv)[argvpos++]= cur_arg;
Attachment: [text/bzr-bundle] bzr/marc.alff@oracle.com-20100811170026-4zly1vhhbr47n43e.bundle