Skip to content

Commit 9d5c937

Browse files
committed
MDEV-7780 - Support for faking server version
Added --version=str (optional argument sets server version string).
1 parent cc8e863 commit 9d5c937

File tree

7 files changed

+28
-7
lines changed

7 files changed

+28
-7
lines changed

mysql-test/r/mysqld--help.result

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,8 @@ The following options may be given as the first argument:
11241124
CLIENT_STATISTICS, INDEX_STATISTICS and TABLE_STATISTICS
11251125
tables in the INFORMATION_SCHEMA
11261126
-v, --verbose Used with --help option for detailed help.
1127-
-V, --version Output version information and exit.
1127+
-V, --version[=name]
1128+
Output version information and exit.
11281129
--wait-timeout=# The number of seconds the server waits for activity on a
11291130
connection before closing it
11301131

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT @@version;
2+
@@version
3+
my_favorite_version
4+
1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--version="my_favorite_version"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SELECT @@version;
2+
perl;
3+
$cnt= grep /my_favorite_version/, `$ENV{MYSQL} -e status`;
4+
print "$cnt\n";
5+
EOF

sql/mysqld.cc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ DATE_TIME_FORMAT global_date_format, global_datetime_format, global_time_format;
631631
Time_zone *default_tz;
632632

633633
const char *mysql_real_data_home_ptr= mysql_real_data_home;
634-
char server_version[SERVER_VERSION_LENGTH];
634+
char server_version[SERVER_VERSION_LENGTH], *server_version_ptr;
635635
char *mysqld_unix_port, *opt_mysql_tmpdir;
636636
ulong thread_handling;
637637

@@ -7604,8 +7604,8 @@ struct my_option my_long_options[]=
76047604
0, 0, 0, 0, 0, 0},
76057605
{"verbose", 'v', "Used with --help option for detailed help.",
76067606
&opt_verbose, &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
7607-
{"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
7608-
NO_ARG, 0, 0, 0, 0, 0, 0},
7607+
{"version", 'V', "Output version information and exit.", 0, 0, 0, GET_STR,
7608+
OPT_ARG, 0, 0, 0, 0, 0, 0},
76097609
{"plugin-load", OPT_PLUGIN_LOAD,
76107610
"Semicolon-separated list of plugins to load, where each plugin is "
76117611
"specified as ether a plugin_name=library_file pair or only a library_file. "
@@ -8947,8 +8947,16 @@ mysqld_get_one_option(int optid, const struct my_option *opt, char *argument)
89478947
#include <sslopt-case.h>
89488948
#ifndef EMBEDDED_LIBRARY
89498949
case 'V':
8950-
print_version();
8951-
opt_abort= 1; // Abort after parsing all options
8950+
if (argument)
8951+
{
8952+
strmake(server_version, argument, sizeof(server_version) - 1);
8953+
set_sys_var_value_origin(&server_version_ptr, sys_var::CONFIG);
8954+
}
8955+
else
8956+
{
8957+
print_version();
8958+
opt_abort= 1; // Abort after parsing all options
8959+
}
89528960
break;
89538961
#endif /*EMBEDDED_LIBRARY*/
89548962
case 'W':
@@ -9641,6 +9649,8 @@ static int get_options(int *argc_ptr, char ***argv_ptr)
96419649

96429650
void set_server_version(void)
96439651
{
9652+
if (!IS_SYSVAR_AUTOSIZE(&server_version_ptr))
9653+
return;
96449654
char *end= strxmov(server_version, MYSQL_SERVER_VERSION,
96459655
MYSQL_SERVER_SUFFIX_STR, NullS);
96469656
#ifdef EMBEDDED_LIBRARY

sql/mysqld.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ extern uint mysql_real_data_home_len;
534534
extern const char *mysql_real_data_home_ptr;
535535
extern ulong thread_handling;
536536
extern "C" MYSQL_PLUGIN_IMPORT char server_version[SERVER_VERSION_LENGTH];
537+
extern char *server_version_ptr;
537538
extern MYSQL_PLUGIN_IMPORT char mysql_real_data_home[];
538539
extern char mysql_unpacked_real_data_home[];
539540
extern MYSQL_PLUGIN_IMPORT struct system_variables global_system_variables;

sql/sys_vars.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3368,7 +3368,6 @@ static Sys_var_mybool Sys_timed_mutexes(
33683368
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL), ON_UPDATE(NULL),
33693369
DEPRECATED(""));
33703370

3371-
static char *server_version_ptr;
33723371
static Sys_var_charptr Sys_version(
33733372
"version", "Server version",
33743373
READ_ONLY GLOBAL_VAR(server_version_ptr),

0 commit comments

Comments
 (0)