diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/client_priv.h | 58 | ||||
-rw-r--r-- | client/mysql.cc | 65 | ||||
-rw-r--r-- | client/mysqladmin.cc | 66 | ||||
-rw-r--r-- | client/mysqlbinlog.cc | 58 | ||||
-rw-r--r-- | client/mysqlcheck.c | 68 | ||||
-rw-r--r-- | client/mysqldump.c | 68 | ||||
-rw-r--r-- | client/mysqlimport.c | 67 | ||||
-rw-r--r-- | client/mysqlshow.c | 67 | ||||
-rw-r--r-- | client/mysqlslap.c | 65 |
9 files changed, 574 insertions, 8 deletions
diff --git a/client/client_priv.h b/client/client_priv.h index 64818d2ab8d..7178c1b7ef0 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -136,3 +136,61 @@ enum options_client Name of the sys schema database. */ #define SYS_SCHEMA_DB_NAME "sys" + +/** + The --socket CLI option has different meanings + across different operating systems. + */ +#ifndef __WIN__ +#define SOCKET_PROTOCOL_TO_FORCE MYSQL_PROTOCOL_SOCKET +#else +#define SOCKET_PROTOCOL_TO_FORCE MYSQL_PROTOCOL_PIPE +#endif + +/** + Utility function to implicitly change the connection protocol to a + consistent value given the command line arguments. Additionally, + warns the user that the protocol has been changed. + + Arguments: + @param [in] host Name of the host to connect to + @param [in, out] opt_protocol Location of the protocol option + variable to update + @param [in] new_protocol New protocol to force +*/ +static inline void warn_protocol_override(char *host, + uint *opt_protocol, + uint new_protocol) +{ + DBUG_ASSERT(new_protocol == MYSQL_PROTOCOL_TCP + || new_protocol == SOCKET_PROTOCOL_TO_FORCE); + + + if ((host == NULL + || strncmp(host, LOCAL_HOST, sizeof(LOCAL_HOST)-1) == 0)) + { + const char *protocol_name; + + if (*opt_protocol == MYSQL_PROTOCOL_DEFAULT +#ifndef __WIN__ + && new_protocol == MYSQL_PROTOCOL_SOCKET +#else + && new_protocol == MYSQL_PROTOCOL_TCP +#endif + ) + { + /* This is already the default behavior, do nothing */ + return; + } + + protocol_name= sql_protocol_typelib.type_names[new_protocol-1]; + + fprintf(stderr, "%s %s %s\n", + "WARNING: Forcing protocol to ", + protocol_name, + " due to option specification. " + "Please explicitly state intended protocol."); + + *opt_protocol = new_protocol; + } +} diff --git a/client/mysql.cc b/client/mysql.cc index 433fbd281b9..6f0758744a8 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -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); diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc index e40e82f8038..ef7fb56d43f 100644 --- a/client/mysqladmin.cc +++ b/client/mysqladmin.cc @@ -54,6 +54,8 @@ static bool sql_log_bin_off= false; static uint opt_protocol=0; static myf error_flags; /* flags to pass to my_printf_error, like ME_BELL */ +static uint protocol_to_force= MYSQL_PROTOCOL_DEFAULT; + /* When using extended-status relatively, ex_val_max_len is the estimated maximum length for any relative value printed by extended-status. The @@ -241,8 +243,12 @@ static const char *load_default_groups[]= 0 }; 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 overrides */ + static my_bool ignore_protocol_override = FALSE; + switch(opt->id) { case 'c': opt_count_iterations= 1; @@ -274,6 +280,13 @@ get_one_option(const struct my_option *opt, const char *argument, const char *) 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 '#': @@ -309,6 +322,46 @@ get_one_option(const struct my_option *opt, const char *argument, const char *) 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; } return 0; @@ -323,6 +376,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; + load_defaults_or_exit("my", load_default_groups, &argc, &argv); save_argv = argv; /* Save for free_defaults */ @@ -331,6 +388,13 @@ int main(int argc,char *argv[]) temp_argv= mask_password(argc, &argv); temp_argc= argc; + /* 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); + } + if (debug_info_flag) my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO; if (debug_check_flag) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index fd31ab6694e..870145e35e0 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -98,6 +98,8 @@ static const char *output_prefix= ""; static char **defaults_argv= 0; static MEM_ROOT glob_root; +static uint protocol_to_force= MYSQL_PROTOCOL_DEFAULT; + #ifndef DBUG_OFF static const char *default_dbug_option = "d:t:o,/tmp/mariadb-binlog.trace"; const char *current_dbug_option= default_dbug_option; @@ -1959,9 +1961,13 @@ static my_time_t convert_str_to_timestamp(const char* str) extern "C" 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) { bool tty_password=0; + + /* Track when protocol is set via CLI to not force overrides */ + static my_bool ignore_protocol_override = FALSE; + switch (opt->id) { #ifndef DBUG_OFF case '#': @@ -2011,6 +2017,14 @@ get_one_option(const struct my_option *opt, const char *argument, const char *) sf_leaking_memory= 1; /* no memory leak reports here */ die(); } + + /* Specification of protocol via CLI trumps implicit overrides */ + if (filename[0] == '\0') + { + ignore_protocol_override = TRUE; + protocol_to_force = MYSQL_PROTOCOL_DEFAULT; + } + break; #ifdef WHEN_FLASHBACK_REVIEW_READY case opt_flashback_review: @@ -2092,6 +2106,38 @@ get_one_option(const struct my_option *opt, const char *argument, const char *) case OPT_PRINT_ROW_EVENT_POSITIONS: print_row_event_positions_used= 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 'v': if (argument == disabled_my_option) verbose= 0; @@ -3049,6 +3095,9 @@ int main(int argc, char** argv) my_init_time(); // for time functions tzset(); // set tzname + /* We need to know if protocol-related options originate from CLI args */ + my_defaults_mark_files = TRUE; + load_defaults_or_exit("my", load_groups, &argc, &argv); defaults_argv= argv; @@ -3062,6 +3111,13 @@ int main(int argc, char** argv) parse_args(&argc, (char***)&argv); + /* 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); + } + if (!argc || opt_version) { if (!opt_version) 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; diff --git a/client/mysqldump.c b/client/mysqldump.c index 0da44ccd399..13ecd205d9e 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -192,6 +192,8 @@ FILE *stderror_file=0; static uint opt_protocol= 0; static char *opt_plugin_dir= 0, *opt_default_auth= 0; +static uint protocol_to_force= MYSQL_PROTOCOL_DEFAULT; + /* Dynamic_string wrapper functions. In this file use these wrappers, they will terminate the process if there is @@ -860,8 +862,12 @@ uchar* get_table_key(const char *entry, size_t *length, static my_bool get_one_option(const struct my_option *opt, const char *argument, - const char *filename __attribute__((unused))) + const char *filename) { + + /* Track when protocol is set via CLI to not force overrides */ + static my_bool ignore_protocol_override = FALSE; + switch (opt->id) { case 'p': if (argument == disabled_my_option) @@ -892,6 +898,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 'N': @@ -1042,11 +1055,51 @@ 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 (int) OPT_DEFAULT_CHARSET: if (default_charset == disabled_my_option) default_charset= (char *)mysql_universal_client_charset; 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; } return 0; } @@ -1059,6 +1112,9 @@ static int get_options(int *argc, char ***argv) opt_max_allowed_packet= *mysql_params->p_max_allowed_packet; opt_net_buffer_length= *mysql_params->p_net_buffer_length; + /* We need to know if protocol-related options originate from CLI args */ + my_defaults_mark_files = TRUE; + md_result_file= stdout; load_defaults_or_exit("my", load_default_groups, argc, argv); defaults_argv= *argv; @@ -1090,6 +1146,16 @@ static int get_options(int *argc, char ***argv) return(ho_error); /* + 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); + } + + + /* Dumping under --system=stats with --replace or --inser-ignore is safe and will not retult into race condition. Otherwise dump only structure and ignore data by default while dumping. diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 99b46ce3c6b..32022146230 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -63,6 +63,9 @@ static uint opt_mysql_port= 0, opt_protocol= 0; static char * opt_mysql_unix_port=0; static char *opt_plugin_dir= 0, *opt_default_auth= 0; static longlong opt_ignore_lines= -1; + +static uint protocol_to_force= MYSQL_PROTOCOL_DEFAULT; + #include <sslopt-vars.h> static char **argv_to_free; @@ -222,8 +225,11 @@ file. The SQL command 'LOAD DATA INFILE' is used to import the rows.\n"); static my_bool get_one_option(const struct my_option *opt, const char *argument, - const char *filename __attribute__((unused))) + const char *filename) { + /* Track when protocol is set via CLI to not force overrides */ + static my_bool ignore_protocol_override = FALSE; + switch(opt->id) { case 'p': if (argument == disabled_my_option) @@ -250,6 +256,14 @@ get_one_option(const struct my_option *opt, const char *argument, case 'W': opt_protocol = MYSQL_PROTOCOL_PIPE; opt_local_file=1; + + /* Prioritize pipe if explicit via command line */ + if (filename[0] == '\0') + { + ignore_protocol_override = TRUE; + protocol_to_force = MYSQL_PROTOCOL_DEFAULT; + } + break; #endif case OPT_MYSQL_PROTOCOL: @@ -259,6 +273,46 @@ 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) + { + 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 '#': DBUG_PUSH(argument ? argument : "d:t:o"); @@ -645,6 +699,9 @@ 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; + load_defaults_or_exit("my", load_default_groups, &argc, &argv); /* argv is changed in the program */ argv_to_free= argv; @@ -653,6 +710,14 @@ int main(int argc, char **argv) free_defaults(argv_to_free); return(1); } + + /* 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 */ if (opt_use_threads && !lock_tables) diff --git a/client/mysqlshow.c b/client/mysqlshow.c index a89f4eb1dd2..d09839d04a8 100644 --- a/client/mysqlshow.c +++ b/client/mysqlshow.c @@ -41,6 +41,8 @@ static char *opt_plugin_dir= 0, *opt_default_auth= 0; static uint opt_protocol=0; +static uint protocol_to_force= MYSQL_PROTOCOL_DEFAULT; + static void get_options(int *argc,char ***argv); static uint opt_mysql_port=0; static int list_dbs(MYSQL *mysql,const char *wild); @@ -70,11 +72,23 @@ int main(int argc, char **argv) static char **defaults_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; + load_defaults_or_exit("my", load_default_groups, &argc, &argv); defaults_argv=argv; get_options(&argc,&argv); + + /* 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 */ wild=0; if (argc) @@ -290,8 +304,12 @@ are shown."); static my_bool get_one_option(const struct my_option *opt, const char *argument, - const char *filename __attribute__((unused))) + const char *filename) { + + /* Track when protocol is set via CLI to not force overrides */ + static my_bool ignore_protocol_override = FALSE; + switch(opt->id) { case 'v': opt_verbose++; @@ -320,6 +338,13 @@ get_one_option(const struct my_option *opt, const char *argument, 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 OPT_MYSQL_PROTOCOL: @@ -329,6 +354,46 @@ 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) + { + 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 '#': DBUG_PUSH(argument ? argument : "d:t:o"); diff --git a/client/mysqlslap.c b/client/mysqlslap.c index 1109ffbf3c8..f456d9b1841 100644 --- a/client/mysqlslap.c +++ b/client/mysqlslap.c @@ -173,6 +173,8 @@ 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; @@ -319,6 +321,9 @@ 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; + load_defaults_or_exit("my", load_default_groups, &argc, &argv); defaults_argv=argv; if (get_options(&argc,&argv)) @@ -327,6 +332,14 @@ int main(int argc, char **argv) my_end(0); 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. */ @@ -727,8 +740,11 @@ 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) { + /* 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': @@ -758,6 +774,13 @@ get_one_option(const struct my_option *opt, const char *argument, 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 OPT_MYSQL_PROTOCOL: @@ -767,6 +790,46 @@ 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) + { + 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 '#': DBUG_PUSH(argument ? argument : default_dbug_option); |