diff options
Diffstat (limited to 'client/mysqltest.cc')
-rw-r--r-- | client/mysqltest.cc | 152 |
1 files changed, 42 insertions, 110 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 60a203ccedd..2a9560e8903 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -146,7 +146,7 @@ struct property { my_bool *var; /* Actual variable */ my_bool set; /* Has been set for ONE command */ my_bool old; /* If set, thus is the old value */ - my_bool reverse; /* Varible is true if disabled */ + my_bool reverse; /* Variable is true if disabled */ const char *env_name; /* Env. variable name */ }; @@ -185,7 +185,7 @@ static uint opt_tail_lines= 0; static uint opt_connect_timeout= 0; static uint opt_wait_for_pos_timeout= 0; - +static const uint default_wait_for_pos_timeout= 300; static char delimiter[MAX_DELIMITER_LENGTH]= ";"; static uint delimiter_length= 1; @@ -566,7 +566,7 @@ DYNAMIC_ARRAY regex_arr; /* stores a list of st_regex subsitutions */ Temporary storage areas for substitutions. To reduce unnessary copying and memory freeing/allocation, we pre-allocate two buffers, and alternate their use, one for input/one for output, the roles changing on the next -st_regex substition. At the end of substitutions buf points to the +st_regex substitution. At the end of substitutions buf points to the one containing the final result. */ char* buf; @@ -587,10 +587,10 @@ ATTRIBUTE_NORETURN static void cleanup_and_exit(int exit_code); ATTRIBUTE_NORETURN -void really_die(const char *msg); -void report_or_die(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2); -ATTRIBUTE_NORETURN ATTRIBUTE_FORMAT(printf, 1, 2) -void die(const char *fmt, ...); +static void really_die(const char *msg); +void report_or_die(const char *fmt, ...); +ATTRIBUTE_NORETURN +static void die(const char *fmt, ...); static void make_error_message(char *buf, size_t len, const char *fmt, va_list args); ATTRIBUTE_NORETURN ATTRIBUTE_FORMAT(printf, 1, 2) void abort_not_supported_test(const char *fmt, ...); @@ -717,7 +717,7 @@ public: DBUG_ASSERT(ds->str); #ifdef EXTRA_DEBUG - DBUG_PRINT("extra", ("str: %*s", (int) ds->length, ds->str)); + DBUG_DUMP("extra", (uchar*) ds->str, ds->length); #endif if (fwrite(ds->str, 1, ds->length, m_file) != ds->length) @@ -1155,71 +1155,6 @@ void do_eval(DYNAMIC_STRING *query_eval, const char *query, /* - Run query and dump the result to stderr in vertical format - - NOTE! This function should be safe to call when an error - has occurred and thus any further errors will be ignored (although logged) - - SYNOPSIS - show_query - mysql - connection to use - query - query to run - -*/ - -static void show_query(MYSQL* mysql, const char* query) -{ - MYSQL_RES* res; - DBUG_ENTER("show_query"); - - if (!mysql) - DBUG_VOID_RETURN; - - if (mysql_query(mysql, query)) - { - log_msg("Error running query '%s': %d %s", - query, mysql_errno(mysql), mysql_error(mysql)); - DBUG_VOID_RETURN; - } - - if ((res= mysql_store_result(mysql)) == NULL) - { - /* No result set returned */ - DBUG_VOID_RETURN; - } - - { - MYSQL_ROW row; - unsigned int i; - unsigned int row_num= 0; - unsigned int num_fields= mysql_num_fields(res); - MYSQL_FIELD *fields= mysql_fetch_fields(res); - - fprintf(stderr, "=== %s ===\n", query); - while ((row= mysql_fetch_row(res))) - { - unsigned long *lengths= mysql_fetch_lengths(res); - row_num++; - - fprintf(stderr, "---- %d. ----\n", row_num); - for(i= 0; i < num_fields; i++) - { - fprintf(stderr, "%s\t%.*s\n", - fields[i].name, - (int)lengths[i], row[i] ? row[i] : "NULL"); - } - } - for (i= 0; i < strlen(query)+8; i++) - fprintf(stderr, "="); - fprintf(stderr, "\n\n"); - } - mysql_free_result(res); - - DBUG_VOID_RETURN; -} - - -/* Show any warnings just before the error. Since the last error is added to the warning stack, only print @@warning_count-1 warnings. @@ -1377,7 +1312,7 @@ void check_command_args(struct st_command *command, /* Check required arg */ if (arg->ds->length == 0 && arg->required) - die("Missing required argument '%s' to command '%.*s'", arg->argname, + die("Missing required argument '%s' to command '%.*b'", arg->argname, command->first_word_len, command->query); } @@ -1386,7 +1321,7 @@ void check_command_args(struct st_command *command, while(ptr <= command->end && *ptr != '#') { if (*ptr && *ptr != ' ') - die("Extra argument '%s' passed to '%.*s'", + die("Extra argument '%s' passed to '%.*b'", ptr, command->first_word_len, command->query); ptr++; } @@ -1406,7 +1341,7 @@ void handle_command_error(struct st_command *command, uint error, if (command->abort_on_error) { - report_or_die("command \"%.*s\" failed with error: %u my_errno: %d " + report_or_die("command \"%.*b\" failed with error: %u my_errno: %d " "errno: %d", command->first_word_len, command->query, error, my_errno, sys_errno); @@ -1424,7 +1359,7 @@ void handle_command_error(struct st_command *command, uint error, DBUG_VOID_RETURN; } if (command->expected_errors.count > 0) - report_or_die("command \"%.*s\" failed with wrong error: %u " + report_or_die("command \"%.*b\" failed with wrong error: %u " "my_errno: %d errno: %d", command->first_word_len, command->query, error, my_errno, sys_errno); @@ -1433,7 +1368,7 @@ void handle_command_error(struct st_command *command, uint error, command->expected_errors.err[0].code.errnum != 0) { /* Error code we wanted was != 0, i.e. not an expected success */ - report_or_die("command \"%.*s\" succeeded - should have failed with " + report_or_die("command \"%.*b\" succeeded - should have failed with " "errno %d...", command->first_word_len, command->query, command->expected_errors.err[0].code.errnum); @@ -1620,7 +1555,7 @@ static void make_error_message(char *buf, size_t len, const char *fmt, va_list a s+= my_snprintf(s, end -s, "\n", start_lineno); } -void die(const char *fmt, ...) +static void die(const char *fmt, ...) { char buff[DIE_BUFF_SIZE]; va_list args; @@ -1629,7 +1564,7 @@ void die(const char *fmt, ...) really_die(buff); } -void really_die(const char *msg) +static void really_die(const char *msg) { static int dying= 0; fflush(stdout); @@ -2387,7 +2322,7 @@ static int strip_surrounding(char* str, char c1, char c2) static void strip_parentheses(struct st_command *command) { if (strip_surrounding(command->first_argument, '(', ')')) - die("%.*s - argument list started with '%c' must be ended with '%c'", + die("%.*b - argument list started with '%c' must be ended with '%c'", command->first_word_len, command->query, '(', ')'); } @@ -3043,7 +2978,7 @@ void eval_expr(VAR *v, const char *p, const char **p_end, /* Make sure there was just a $variable and nothing else */ const char* end= *p_end + 1; if (end < expected_end && !open_end) - die("Found junk '%.*s' after $variable in expression", + die("Found junk '%.*b' after $variable in expression", (int)(expected_end - end - 1), end); DBUG_VOID_RETURN; @@ -3175,7 +3110,7 @@ void open_file(const char *name) strxnmov(buff, sizeof(buff), opt_overlay_dir, suffix, name, NullS); /* - Overlayed rty/include/thing.inc can contain the line + Overlaid rty/include/thing.inc can contain the line --source thing.inc which would mean to include qwe/include/thing.inc. But it looks like including "itself", so don't try to open the file, @@ -3537,10 +3472,10 @@ int do_modify_var(struct st_command *command, const char *p= command->first_argument; VAR* v; if (!*p) - die("Missing argument to %.*s", command->first_word_len, + die("Missing argument to %.*b", command->first_word_len, command->query); if (*p != '$') - die("The argument to %.*s must be a variable (start with $)", + die("The argument to %.*b must be a variable (start with $)", command->first_word_len, command->query); v= var_get(p, &p, 1, 0); if (! v->is_int) @@ -4808,9 +4743,6 @@ void do_sync_with_master2(struct st_command *command, long offset, if (!result_str || result < 0) { /* master_pos_wait returned NULL or < 0 */ - show_query(mysql, "SHOW MASTER STATUS"); - show_query(mysql, "SHOW SLAVE STATUS"); - show_query(mysql, "SHOW PROCESSLIST"); fprintf(stderr, "analyze: sync_with_master\n"); if (!result_str) @@ -4821,18 +4753,18 @@ void do_sync_with_master2(struct st_command *command, long offset, information is not initialized, the arguments are incorrect, or an error has occurred */ - die("%.*s failed: '%s' returned NULL " \ + die("%.*b failed: '%s' returned NULL " \ "indicating slave SQL thread failure", command->first_word_len, command->query, query_buf); } if (result == -1) - die("%.*s failed: '%s' returned -1 " \ + die("%.*b failed: '%s' returned -1 " \ "indicating timeout after %d seconds", command->first_word_len, command->query, query_buf, timeout); else - die("%.*s failed: '%s' returned unknown result :%d", + die("%.*b failed: '%s' returned unknown result :%d", command->first_word_len, command->query, query_buf, result); } @@ -4887,7 +4819,7 @@ int do_save_master_pos() mysql_errno(mysql), mysql_error(mysql)); if (!(res = mysql_store_result(mysql))) - die("mysql_store_result() retuned NULL for '%s'", query); + die("mysql_store_result() returned NULL for '%s'", query); if (!(row = mysql_fetch_row(res))) die("empty result in show master status"); strnmov(master_pos.file, row[0], sizeof(master_pos.file)-1); @@ -4997,17 +4929,17 @@ int do_sleep(struct st_command *command, my_bool real_sleep) while (my_isspace(charset_info, *p)) p++; if (!*p) - die("Missing argument to %.*s", command->first_word_len, + die("Missing argument to %.*b", command->first_word_len, command->query); sleep_start= p; /* Check that arg starts with a digit, not handled by my_strtod */ if (!my_isdigit(charset_info, *sleep_start)) - die("Invalid argument to %.*s \"%s\"", command->first_word_len, + die("Invalid argument to %.*b \"%s\"", command->first_word_len, command->query, sleep_start); sleep_val= my_strtod(sleep_start, &sleep_end, &error); check_eol_junk_line(sleep_end); if (error) - die("Invalid argument to %.*s \"%s\"", command->first_word_len, + die("Invalid argument to %.*b \"%s\"", command->first_word_len, command->query, command->first_argument); dynstr_free(&ds_sleep); @@ -5142,6 +5074,8 @@ void do_shutdown_server(struct st_command *command) }; DBUG_ENTER("do_shutdown_server"); + /* the wait-for-pos' default based value of 'timeout' must fit to MDEV-23511 */ + compile_time_assert(default_wait_for_pos_timeout / 5 >= 60); check_command_args(command, command->first_argument, shutdown_args, sizeof(shutdown_args)/sizeof(struct command_arg), ' '); @@ -5405,7 +5339,7 @@ void do_get_errcodes(struct st_command *command) p++; } - /* Convert the sting to int */ + /* Convert the string to int */ if (!str2int(start, 10, (long) INT_MIN, (long) INT_MAX, &val)) die("Invalid argument to error: '%s'", command->first_argument); @@ -5797,7 +5731,7 @@ int connect_n_handle_errors(struct st_command *command, dynstr_append_mem(ds, delimiter, delimiter_length); dynstr_append_mem(ds, "\n", 1); } - /* Simlified logging if enabled */ + /* Simplified logging if enabled */ if (!disable_connect_log && !disable_query_log) { replace_dynstr_append(ds, command->query); @@ -6010,7 +5944,7 @@ void do_connect(struct st_command *command) csname= strdup(con_options + sizeof("CHARSET=") - 1); } else - die("Illegal option to connect: %.*s", + die("Illegal option to connect: %.*b", (int) (end - con_options), con_options); /* Process next option */ con_options= end; @@ -6337,7 +6271,7 @@ void do_block(enum block_cmd cmd, struct st_command* command) enum block_op operand= find_operand(curr_ptr); if (operand == ILLEG_OP) - die("Found junk '%.*s' after $variable in condition", + die("Found junk '%.*b' after $variable in condition", (int)(expr_end - curr_ptr), curr_ptr); /* We could silently allow this, but may be confusing */ @@ -7126,7 +7060,7 @@ static struct my_option my_long_options[] = {"wait_for_pos_timeout", 0, "Number of seconds to wait for master_pos_wait", &opt_wait_for_pos_timeout, &opt_wait_for_pos_timeout, 0, GET_UINT, - REQUIRED_ARG, 300, 0, 3600 * 12, 0, 0, 0}, + REQUIRED_ARG, default_wait_for_pos_timeout, 0, 3600 * 12, 0, 0, 0}, {"plugin_dir", 0, "Directory for client-side plugins.", &opt_plugin_dir, &opt_plugin_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -8261,7 +8195,7 @@ void handle_no_error(struct st_command *command) SYNPOSIS run_query_stmt mysql - mysql handle - command - currrent command pointer + command - current command pointer query - query string to execute query_len - length query string to execute ds - output buffer where to store result form query @@ -8501,7 +8435,7 @@ end: /* Create a util connection if one does not already exists and use that to run the query - This is done to avoid implict commit when creating/dropping objects such + This is done to avoid implicit commit when creating/dropping objects such as view, sp etc. */ @@ -8542,7 +8476,7 @@ int util_query(MYSQL* org_mysql, const char* query){ SYNPOSIS run_query() mysql mysql handle - command currrent command pointer + command current command pointer flags control the phased/stages of query execution to be performed if QUERY_SEND_FLAG bit is on, the query will be sent. If QUERY_REAP_FLAG @@ -9130,10 +9064,6 @@ static void init_signal_handling(void) struct sigaction sa; DBUG_ENTER("init_signal_handling"); -#ifdef HAVE_STACKTRACE - my_init_stacktrace(); -#endif - sa.sa_flags = SA_RESETHAND | SA_NODEFER; sigemptyset(&sa.sa_mask); sigprocmask(SIG_SETMASK, &sa.sa_mask, NULL); @@ -9534,6 +9464,7 @@ int main(int argc, char **argv) case Q_LET: do_let(command); break; case Q_EVAL_RESULT: die("'eval_result' command is deprecated"); + break; // never called but keep compiler calm case Q_EVAL: case Q_EVALP: case Q_QUERY_VERTICAL: @@ -10258,6 +10189,7 @@ void append_replace_regex(char* expr, char *expr_end, struct st_replace_regex* r return; err: + my_free(res->regex_arr.buffer); my_free(res); die("Error parsing replace_regex \"%s\"", expr); } @@ -10303,7 +10235,7 @@ int multi_reg_replace(struct st_replace_regex* r,char* val) if (!reg_replace(&out_buf, buf_len_p, re.pattern, re.replace, in_buf, re.icase)) { - /* if the buffer has been reallocated, make adjustements */ + /* if the buffer has been reallocated, make adjustments */ if (save_out_buf != out_buf) { if (save_out_buf == r->even_buf) @@ -10570,7 +10502,7 @@ typedef struct st_rep_set { uint found_len; /* Best match to date */ int found_offset; uint table_offset; - uint size_of_bits; /* For convinience */ + uint size_of_bits; /* For convenience */ } REP_SET; typedef struct st_rep_sets { @@ -10673,7 +10605,7 @@ REPLACE *init_replace(char * *from, char * *to,uint count, DBUG_RETURN(0); } (void) make_new_set(&sets); /* Set starting set */ - make_sets_invisible(&sets); /* Hide previus sets */ + make_sets_invisible(&sets); /* Hide previous sets */ used_sets=-1; word_states=make_new_set(&sets); /* Start of new word */ start_states=make_new_set(&sets); /* This is first state */ |