mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
Cleanup of MDEV-14974: --port ignored for --host=localhost
The old code added to 10.6 was inconsisting in how TCP/IP and socket connection was chosen. One got also a confusing warning in some cases. Examples: > ../client/mysql --print-defaults ../client/mysql would have been started with the following arguments: --socket=/tmp/mariadbd.sock --port=3307 --no-auto-rehash > ../client/mysql ERROR 2002 (HY000): Can't connect to local server through socket '/tmp/mariadbd.sock' (2) > ../client/mysql --print-defaults ../client/mysql would have been started with the following arguments: --socket=/tmp/mariadbd.sock --port=3307 --no-auto-rehash > ../client/mysql --port=3333 WARNING: Forcing protocol to TCP due to option specification. Please explicitly state intended protocol. ERROR 2002 (HY000): Can't connect to server on 'localhost' (111) > ../client/mysql --port=3333 --socket=sss ERROR 2002 (HY000): Can't connect to local server through socket 'sss' (2) > ../client/mysql --socket=sss --port=3333 ERROR 2002 (HY000): Can't connect to local server through socket 'sss' (2) Some notable things: - One gets a warning if one uses just --port if config file sets socket - Using port and socket gives no warning - Using socket and then port still uses socket This patch changes things the following ways: If --port= is given on the command line, the the protocol is automatically changed to "TCP/IP". - If --socket= is given on the command line, the protocol is automatically changed to "socket". - The last option wins - No warning is given if protocol changes automatically.
This commit is contained in:
@@ -172,8 +172,6 @@ File csv_file;
|
||||
|
||||
static uint opt_protocol= 0;
|
||||
|
||||
static uint protocol_to_force= MYSQL_PROTOCOL_DEFAULT;
|
||||
|
||||
static int get_options(int *argc,char ***argv);
|
||||
static uint opt_mysql_port= 0;
|
||||
|
||||
@@ -335,13 +333,6 @@ int main(int argc, char **argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Command line options override configured protocol */
|
||||
if (protocol_to_force > MYSQL_PROTOCOL_DEFAULT
|
||||
&& protocol_to_force != opt_protocol)
|
||||
{
|
||||
warn_protocol_override(host, &opt_protocol, protocol_to_force);
|
||||
}
|
||||
|
||||
sf_leaking_memory=0; /* from now on we cleanup properly */
|
||||
|
||||
/* Seed the random number generator if we will be using it. */
|
||||
@@ -744,9 +735,6 @@ static my_bool
|
||||
get_one_option(const struct my_option *opt, const char *argument,
|
||||
const char *filename)
|
||||
{
|
||||
/* 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) {
|
||||
case 'v':
|
||||
@@ -776,13 +764,6 @@ get_one_option(const struct my_option *opt, const char *argument,
|
||||
case 'W':
|
||||
#ifdef _WIN32
|
||||
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 OPT_MYSQL_PROTOCOL:
|
||||
@@ -792,45 +773,19 @@ get_one_option(const struct my_option *opt, const char *argument,
|
||||
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)
|
||||
if (filename[0] == '\0')
|
||||
{
|
||||
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;
|
||||
/* Port given on command line, switch protocol to use TCP */
|
||||
opt_protocol= MYSQL_PROTOCOL_TCP;
|
||||
}
|
||||
break;
|
||||
case 'S':
|
||||
/* If port and socket are set, fall back to default behavior */
|
||||
if (protocol_to_force == MYSQL_PROTOCOL_TCP)
|
||||
if (filename[0] == '\0')
|
||||
{
|
||||
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;
|
||||
/* Socket given on command line, switch protocol to use SOCKETSt */
|
||||
opt_protocol= MYSQL_PROTOCOL_SOCKET;
|
||||
}
|
||||
break;
|
||||
case '#':
|
||||
|
Reference in New Issue
Block a user