mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-14974: --port ignored for --host=localhost
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 Reviewers: ======== Sergei Golubchik <serg@mariadb.com> Vladislav Vaintroub <wlad@mariadb.com>
This commit is contained in:
@@ -206,6 +206,8 @@ static uint opt_protocol=0;
|
||||
static const char *opt_protocol_type= "";
|
||||
static CHARSET_INFO *charset_info= &my_charset_latin1;
|
||||
|
||||
static uint protocol_to_force= MYSQL_PROTOCOL_DEFAULT;
|
||||
|
||||
#include "sslopt-vars.h"
|
||||
|
||||
const char *default_dbug_option="d:t:o,/tmp/mariadb.trace";
|
||||
@@ -1162,6 +1164,9 @@ int main(int argc,char *argv[])
|
||||
close(stdout_fileno_copy); /* Clean up dup(). */
|
||||
}
|
||||
|
||||
/* We need to know if protocol-related options originate from CLI args */
|
||||
my_defaults_mark_files = TRUE;
|
||||
|
||||
load_defaults_or_exit("my", load_default_groups, &argc, &argv);
|
||||
defaults_argv=argv;
|
||||
if ((status.exit_status= get_options(argc, (char **) argv)))
|
||||
@@ -1171,6 +1176,14 @@ int main(int argc,char *argv[])
|
||||
exit(status.exit_status);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
||||
if (status.batch && !status.line_buff &&
|
||||
!(status.line_buff= batch_readline_init(MAX_BATCH_BUFFER_SIZE, stdin)))
|
||||
{
|
||||
@@ -1715,8 +1728,11 @@ static void usage(int version)
|
||||
|
||||
|
||||
my_bool
|
||||
get_one_option(const struct my_option *opt, const char *argument, const char *)
|
||||
get_one_option(const struct my_option *opt, const char *argument, const char *filename)
|
||||
{
|
||||
/* Track when protocol is set via CLI to not force port TCP protocol override */
|
||||
static my_bool ignore_protocol_override = FALSE;
|
||||
|
||||
switch(opt->id) {
|
||||
case OPT_CHARSETS_DIR:
|
||||
strmake_buf(mysql_charsets_dir, argument);
|
||||
@@ -1781,6 +1797,14 @@ get_one_option(const struct my_option *opt, const char *argument, const char *)
|
||||
opt->name)) <= 0)
|
||||
exit(1);
|
||||
#endif
|
||||
|
||||
/* Specification of protocol via CLI trumps implicit overrides */
|
||||
if (filename[0] == '\0')
|
||||
{
|
||||
ignore_protocol_override = TRUE;
|
||||
protocol_to_force = MYSQL_PROTOCOL_DEFAULT;
|
||||
}
|
||||
|
||||
break;
|
||||
case OPT_SERVER_ARG:
|
||||
#ifdef EMBEDDED_LIBRARY
|
||||
@@ -1872,6 +1896,13 @@ get_one_option(const struct my_option *opt, const char *argument, const char *)
|
||||
#ifdef __WIN__
|
||||
opt_protocol = MYSQL_PROTOCOL_PIPE;
|
||||
opt_protocol_type= "pipe";
|
||||
|
||||
/* Prioritize pipe if explicit via command line */
|
||||
if (filename[0] == '\0')
|
||||
{
|
||||
ignore_protocol_override = TRUE;
|
||||
protocol_to_force = MYSQL_PROTOCOL_DEFAULT;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
#include <sslopt-case.h>
|
||||
@@ -1883,6 +1914,38 @@ get_one_option(const struct my_option *opt, const char *argument, const char *)
|
||||
status.exit_status= 0;
|
||||
mysql_end(-1);
|
||||
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;
|
||||
case 'I':
|
||||
case '?':
|
||||
usage(0);
|
||||
|
Reference in New Issue
Block a user