diff options
author | Brandon Nesterenko <brandon.nesterenko@mariadb.com> | 2021-05-10 11:10:53 -0600 |
---|---|---|
committer | Brandon Nesterenko <brandon.nesterenko@mariadb.com> | 2021-05-10 13:36:42 -0600 |
commit | 7c1231a6d59edd319fe8a5f3cb5782fc641d9a0a (patch) | |
tree | 2ed1deff4b9fcf684426f4c038c894cdf51ce80f /client/mysqlcheck.c | |
parent | f8665314d4ba190679001b81bb7d9fd7a38fc0f6 (diff) | |
download | mariadb-git-bb-10.6-MDEV-14974.tar.gz |
MDEV-14974: --port ignored for --host=localhostbb-10.6-MDEV-1497410.6-MDEV-14974
Problem:
=======
MariaDB's command line utilities (e.g., mysql,
mysqldump, etc) silently ignore connection
property options (e.g., --port and --socket)
when protocol is not explicitly set via the
command-line for localhost connections.
Fix:
===
If connection properties are specified without a
protocol, override the protocol to be consistent.
For example, if --port is specified, automatically
set protocol=tcp.
Caveats:
=======
* When multiple connection properties are
specified, nothing is overridden
* If protocol is is set via the command-line,
its value is used
Diffstat (limited to 'client/mysqlcheck.c')
-rw-r--r-- | client/mysqlcheck.c | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index fb3103a318d..cf0d86bbcf5 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -57,6 +57,8 @@ DYNAMIC_ARRAY tables4repair, tables4rebuild, alter_table_cmds; DYNAMIC_ARRAY views4repair; static uint opt_protocol=0; +static uint protocol_to_force= MYSQL_PROTOCOL_DEFAULT; + enum operations { DO_CHECK=1, DO_REPAIR, DO_ANALYZE, DO_OPTIMIZE, DO_FIX_NAMES }; const char *operation_name[]= { @@ -286,9 +288,13 @@ static void usage(void) static my_bool get_one_option(const struct my_option *opt, const char *argument, - const char *filename __attribute__((unused))) + const char *filename) { int orig_what_to_do= what_to_do; + + /* Track when protocol is set via CLI to not force overrides */ + static my_bool ignore_protocol_override = FALSE; + DBUG_ENTER("get_one_option"); switch(opt->id) { @@ -351,6 +357,13 @@ get_one_option(const struct my_option *opt, case 'W': #ifdef __WIN__ opt_protocol = MYSQL_PROTOCOL_PIPE; + + /* Prioritize pipe if explicit via command line */ + if (filename[0] == '\0') + { + ignore_protocol_override = TRUE; + protocol_to_force = MYSQL_PROTOCOL_DEFAULT; + } #endif break; case '#': @@ -374,6 +387,46 @@ get_one_option(const struct my_option *opt, sf_leaking_memory= 1; /* no memory leak reports here */ exit(1); } + + /* Specification of protocol via CLI trumps implicit overrides */ + if (filename[0] == '\0') + { + ignore_protocol_override = TRUE; + protocol_to_force = MYSQL_PROTOCOL_DEFAULT; + } + + break; + case 'P': + /* If port and socket are set, fall back to default behavior */ + if (protocol_to_force == SOCKET_PROTOCOL_TO_FORCE) + { + ignore_protocol_override = TRUE; + protocol_to_force = MYSQL_PROTOCOL_DEFAULT; + } + + /* If port is set via CLI, try to force protocol to TCP */ + if (filename[0] == '\0' && + !ignore_protocol_override && + protocol_to_force == MYSQL_PROTOCOL_DEFAULT) + { + protocol_to_force = MYSQL_PROTOCOL_TCP; + } + break; + case 'S': + /* If port and socket are set, fall back to default behavior */ + if (protocol_to_force == MYSQL_PROTOCOL_TCP) + { + ignore_protocol_override = TRUE; + protocol_to_force = MYSQL_PROTOCOL_DEFAULT; + } + + /* Prioritize socket if set via command line */ + if (filename[0] == '\0' && + !ignore_protocol_override && + protocol_to_force == MYSQL_PROTOCOL_DEFAULT) + { + protocol_to_force = SOCKET_PROTOCOL_TO_FORCE; + } break; } @@ -1179,6 +1232,10 @@ int main(int argc, char **argv) MY_INIT(argv[0]); sf_leaking_memory=1; /* don't report memory leaks on early exits */ + + /* We need to know if protocol-related options originate from CLI args */ + my_defaults_mark_files = TRUE; + /* ** Check out the args */ @@ -1186,6 +1243,15 @@ int main(int argc, char **argv) defaults_argv= argv; if (get_options(&argc, &argv)) goto end1; + + + /* Command line options override configured protocol */ + if (protocol_to_force > MYSQL_PROTOCOL_DEFAULT + && protocol_to_force != opt_protocol) + { + warn_protocol_override(current_host, &opt_protocol, protocol_to_force); + } + sf_leaking_memory=0; /* from now on we cleanup properly */ ret= EX_MYSQLERR; |