[Commits] 5ec237c: MDEV-7780 - Support for faking server version

Sergey Vojtovich svoj at mariadb.org
Fri Nov 27 09:26:54 EET 2015


revision-id: 5ec237c093e3236ca1b19f65f31f6fb5e1d8179a (mariadb-10.1.8-80-g5ec237c)
parent(s): 3e69db83a792e7de8a7e7dc501a75f9f22bb6196
committer: Sergey Vojtovich
timestamp: 2015-11-27 11:26:52 +0400
message:

MDEV-7780 - Support for faking server version

Added --version=str (optional argument sets server version string).

---
 mysql-test/r/mysqld--help.result           |  3 ++-
 mysql-test/suite/sys_vars/r/version.result |  4 ++++
 mysql-test/suite/sys_vars/t/version.opt    |  1 +
 mysql-test/suite/sys_vars/t/version.test   |  5 +++++
 sql/mysqld.cc                              | 20 +++++++++++++++-----
 sql/mysqld.h                               |  1 +
 sql/sys_vars.cc                            |  1 -
 7 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/mysql-test/r/mysqld--help.result b/mysql-test/r/mysqld--help.result
index 7a6541b..c109ad2 100644
--- a/mysql-test/r/mysqld--help.result
+++ b/mysql-test/r/mysqld--help.result
@@ -1124,7 +1124,8 @@ The following options may be given as the first argument:
  CLIENT_STATISTICS, INDEX_STATISTICS and TABLE_STATISTICS
  tables in the INFORMATION_SCHEMA
  -v, --verbose       Used with --help option for detailed help.
- -V, --version       Output version information and exit.
+ -V, --version[=name] 
+ Output version information and exit.
  --wait-timeout=#    The number of seconds the server waits for activity on a
  connection before closing it
 
diff --git a/mysql-test/suite/sys_vars/r/version.result b/mysql-test/suite/sys_vars/r/version.result
new file mode 100644
index 0000000..29a2fb8
--- /dev/null
+++ b/mysql-test/suite/sys_vars/r/version.result
@@ -0,0 +1,4 @@
+SELECT @@version;
+@@version
+my_favorite_version
+1
diff --git a/mysql-test/suite/sys_vars/t/version.opt b/mysql-test/suite/sys_vars/t/version.opt
new file mode 100644
index 0000000..9b6be9b
--- /dev/null
+++ b/mysql-test/suite/sys_vars/t/version.opt
@@ -0,0 +1 @@
+--version="my_favorite_version"
diff --git a/mysql-test/suite/sys_vars/t/version.test b/mysql-test/suite/sys_vars/t/version.test
new file mode 100644
index 0000000..7955bf8
--- /dev/null
+++ b/mysql-test/suite/sys_vars/t/version.test
@@ -0,0 +1,5 @@
+SELECT @@version;
+perl;
+  $cnt= grep /my_favorite_version/, `$ENV{MYSQL} -e status`;
+  print "$cnt\n";
+EOF
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index da98629..0694cb0 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -631,7 +631,7 @@ DATE_TIME_FORMAT global_date_format, global_datetime_format, global_time_format;
 Time_zone *default_tz;
 
 const char *mysql_real_data_home_ptr= mysql_real_data_home;
-char server_version[SERVER_VERSION_LENGTH];
+char server_version[SERVER_VERSION_LENGTH], *server_version_ptr;
 char *mysqld_unix_port, *opt_mysql_tmpdir;
 ulong thread_handling;
 
@@ -7630,8 +7630,8 @@ struct my_option my_long_options[]=
    0, 0, 0, 0, 0, 0},
   {"verbose", 'v', "Used with --help option for detailed help.",
    &opt_verbose, &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
-   NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_STR,
+   OPT_ARG, 0, 0, 0, 0, 0, 0},
   {"plugin-load", OPT_PLUGIN_LOAD,
    "Semicolon-separated list of plugins to load, where each plugin is "
    "specified as ether a plugin_name=library_file pair or only a library_file. "
@@ -8973,8 +8973,16 @@ mysqld_get_one_option(int optid, const struct my_option *opt, char *argument)
 #include <sslopt-case.h>
 #ifndef EMBEDDED_LIBRARY
   case 'V':
-    print_version();
-    opt_abort= 1;                    // Abort after parsing all options
+    if (argument)
+    {
+      strmake(server_version, argument, sizeof(server_version) - 1);
+      set_sys_var_value_origin(&server_version_ptr, sys_var::CONFIG);
+    }
+    else
+    {
+      print_version();
+      opt_abort= 1;                    // Abort after parsing all options
+    }
     break;
 #endif /*EMBEDDED_LIBRARY*/
   case 'W':
@@ -9667,6 +9675,8 @@ static int get_options(int *argc_ptr, char ***argv_ptr)
 
 void set_server_version(void)
 {
+  if (!IS_SYSVAR_AUTOSIZE(&server_version_ptr))
+    return;
   char *end= strxmov(server_version, MYSQL_SERVER_VERSION,
                      MYSQL_SERVER_SUFFIX_STR, NullS);
 #ifdef EMBEDDED_LIBRARY
diff --git a/sql/mysqld.h b/sql/mysqld.h
index 21ff4f4..e06c70a 100644
--- a/sql/mysqld.h
+++ b/sql/mysqld.h
@@ -534,6 +534,7 @@ extern uint mysql_real_data_home_len;
 extern const char *mysql_real_data_home_ptr;
 extern ulong thread_handling;
 extern "C" MYSQL_PLUGIN_IMPORT char server_version[SERVER_VERSION_LENGTH];
+extern char *server_version_ptr;
 extern MYSQL_PLUGIN_IMPORT char mysql_real_data_home[];
 extern char mysql_unpacked_real_data_home[];
 extern MYSQL_PLUGIN_IMPORT struct system_variables global_system_variables;
diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc
index f5c2f6b..982cce6 100644
--- a/sql/sys_vars.cc
+++ b/sql/sys_vars.cc
@@ -3368,7 +3368,6 @@ static Sys_var_mybool Sys_timed_mutexes(
        NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL), ON_UPDATE(NULL),
        DEPRECATED(""));
 
-static char *server_version_ptr;
 static Sys_var_charptr Sys_version(
        "version", "Server version",
        READ_ONLY GLOBAL_VAR(server_version_ptr),


More information about the commits mailing list