diff options
Diffstat (limited to 'client/mysqlslap.c')
-rw-r--r-- | client/mysqlslap.c | 65 |
1 files changed, 64 insertions, 1 deletions
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); |