diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/mysql.cc | 49 | ||||
-rw-r--r-- | client/mysql_upgrade.c | 29 | ||||
-rw-r--r-- | client/mysqlbinlog.cc | 3 | ||||
-rw-r--r-- | client/mysqlcheck.c | 2 | ||||
-rw-r--r-- | client/mysqltest.cc | 57 |
5 files changed, 76 insertions, 64 deletions
diff --git a/client/mysql.cc b/client/mysql.cc index 5fe940eeca7..62a4de7a10e 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -1073,9 +1073,7 @@ static void print_table_data_xml(MYSQL_RES *result); static void print_tab_data(MYSQL_RES *result); static void print_table_data_vertically(MYSQL_RES *result); static void print_warnings(void); -static ulong start_timer(void); -static void end_timer(ulong start_time,char *buff); -static void mysql_end_timer(ulong start_time,char *buff); +static void end_timer(ulonglong start_time, char *buff); static void nice_time(double sec,char *buff,bool part_second); extern "C" sig_handler mysql_end(int sig) __attribute__ ((noreturn)); extern "C" sig_handler handle_sigint(int sig); @@ -3211,9 +3209,10 @@ static int com_go(String *buffer,char *line __attribute__((unused))) { char buff[200]; /* about 110 chars used so far */ - char time_buff[52+3+1]; /* time max + space&parens + NUL */ + char time_buff[53+3+1]; /* time max + space&parens + NUL */ MYSQL_RES *result; - ulong timer, warnings= 0; + ulonglong timer; + ulong warnings= 0; uint error= 0; int err= 0; @@ -3252,7 +3251,7 @@ com_go(String *buffer,char *line __attribute__((unused))) return 0; } - timer=start_timer(); + timer= microsecond_interval_timer(); executing_query= 1; error= mysql_real_query_for_lazy(buffer->ptr(),buffer->length()); report_progress_end(); @@ -3291,7 +3290,7 @@ com_go(String *buffer,char *line __attribute__((unused))) } if (verbose >= 3 || !opt_silent) - mysql_end_timer(timer,time_buff); + end_timer(timer, time_buff); else time_buff[0]= '\0'; @@ -5087,31 +5086,11 @@ void tee_putc(int c, FILE *file) putc(c, OUTFILE); } -#if defined(__WIN__) -#include <time.h> -#else -#include <sys/times.h> -#ifdef _SC_CLK_TCK // For mit-pthreads -#undef CLOCKS_PER_SEC -#define CLOCKS_PER_SEC (sysconf(_SC_CLK_TCK)) -#endif -#endif - -static ulong start_timer(void) -{ -#if defined(__WIN__) - return clock(); -#else - struct tms tms_tmp; - return times(&tms_tmp); -#endif -} - /** Write as many as 52+1 bytes to buff, in the form of a legible duration of time. - len("4294967296 days, 23 hours, 59 minutes, 60.00 seconds") -> 52 + len("4294967296 days, 23 hours, 59 minutes, 60.000 seconds") -> 53 */ static void nice_time(double sec,char *buff,bool part_second) { @@ -5138,24 +5117,20 @@ static void nice_time(double sec,char *buff,bool part_second) buff=strmov(buff," min "); } if (part_second) - sprintf(buff,"%.2f sec",sec); + sprintf(buff,"%.3f sec",sec); else sprintf(buff,"%d sec",(int) sec); } -static void end_timer(ulong start_time,char *buff) +static void end_timer(ulonglong start_time, char *buff) { - nice_time((double) (start_timer() - start_time) / - CLOCKS_PER_SEC,buff,1); -} - + double sec; -static void mysql_end_timer(ulong start_time,char *buff) -{ buff[0]=' '; buff[1]='('; - end_timer(start_time,buff+2); + sec= (microsecond_interval_timer() - start_time) / (double) (1000 * 1000); + nice_time(sec, buff + 2, 1); strmov(strend(buff),")"); } diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c index 7ba15b772b5..a6215d0a977 100644 --- a/client/mysql_upgrade.c +++ b/client/mysql_upgrade.c @@ -673,7 +673,7 @@ static int get_upgrade_info_file_name(char* name) */ -static int upgrade_already_done(void) +static int upgrade_already_done(myf flags) { FILE *in; char upgrade_info_file[FN_REFLEN]= {0}; @@ -681,17 +681,23 @@ static int upgrade_already_done(void) if (get_upgrade_info_file_name(upgrade_info_file)) return 0; /* Could not get filename => not sure */ - if (!(in= my_fopen(upgrade_info_file, O_RDONLY, MYF(0)))) + if (!(in= my_fopen(upgrade_info_file, O_RDONLY, flags))) return 0; /* Could not open file => not sure */ bzero(upgrade_from_version, sizeof(upgrade_from_version)); if (!fgets(upgrade_from_version, sizeof(upgrade_from_version), in)) { - /* Ignore, will be detected by strncmp() below */ + /* Preserve errno for caller */ + int save_errno= errno; + (void) my_fclose(in, flags); + errno= save_errno; + return 0; } - my_fclose(in, MYF(0)); + if (my_fclose(in, flags)) + return 0; + errno= 0; return (strncmp(upgrade_from_version, MYSQL_SERVER_VERSION, sizeof(MYSQL_SERVER_VERSION)-1)==0); } @@ -720,23 +726,24 @@ static void create_mysql_upgrade_info_file(void) { fprintf(stderr, "Could not create the upgrade info file '%s' in " - "the MySQL Servers datadir, errno: %d\n", + "the MariaDB Servers datadir, errno: %d\n", upgrade_info_file, errno); return; } /* Write new version to file */ - fputs(MYSQL_SERVER_VERSION, out); - my_fclose(out, MYF(0)); + my_fwrite(out, (uchar*) MYSQL_SERVER_VERSION, + sizeof(MYSQL_SERVER_VERSION), MY_WME); + my_fclose(out, MYF(MY_WME)); /* Check if the upgrad_info_file was properly created/updated It's not a fatal error -> just print a message if it fails */ - if (!upgrade_already_done()) + if (!upgrade_already_done(MY_WME)) fprintf(stderr, - "Could not write to the upgrade info file '%s' in " - "the MySQL Servers datadir, errno: %d\n", + "Upgrade file '%s' was not properly created. " + "Got error errno while checking file content: %d\n", upgrade_info_file, errno); return; } @@ -1191,7 +1198,7 @@ int main(int argc, char **argv) Read the mysql_upgrade_info file to check if mysql_upgrade already has been run for this installation of MySQL */ - if (!opt_force && upgrade_already_done()) + if (!opt_force && upgrade_already_done(0)) { printf("This installation of MySQL is already upgraded to %s, " "use --force if you still need to run mysql_upgrade\n", diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 2712e6ea668..30d00706a9f 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -32,7 +32,10 @@ #define MYSQL_CLIENT #undef MYSQL_SERVER #define TABLE TABLE_CLIENT +/* This hack is here to avoid adding COMPRESSED data types to libmariadb. */ +#define MYSQL_TYPE_TIME2 MYSQL_TYPE_TIME2,MYSQL_TYPE_BLOB_COMPRESSED=140,MYSQL_TYPE_VARCHAR_COMPRESSED=141 #include "client_priv.h" +#undef MYSQL_TYPE_TIME2 #include <my_time.h> #include <sslopt-vars.h> /* That one is necessary for defines of OPTION_NO_FOREIGN_KEY_CHECKS etc */ diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index c633be6b734..d5938776452 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -19,8 +19,6 @@ /* By Jani Tolonen, 2001-04-20, MySQL Development Team */ #define CHECK_VERSION "2.7.4-MariaDB" -/* Avoid warnings from %'s format */ -#define USING_MARIADB_SNPRINTF_EXTENSIONS #include "client_priv.h" #include <m_ctype.h> diff --git a/client/mysqltest.cc b/client/mysqltest.cc index b8a7673996a..914c0ac8621 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -5139,7 +5139,9 @@ int query_get_string(MYSQL* mysql, const char* query, static int my_kill(int pid, int sig) { + DBUG_PRINT("info", ("Killing server, pid: %d", pid)); #ifdef _WIN32 +#define SIGKILL 9 /* ignored anyway, see below */ HANDLE proc; if ((proc= OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid)) == NULL) return -1; @@ -5174,6 +5176,26 @@ static int my_kill(int pid, int sig) */ + +static int wait_until_dead(int pid, int timeout) +{ + DBUG_ENTER("wait_until_dead"); + /* Check that server dies */ + while (timeout--) + { + if (my_kill(pid, 0) < 0) + { + DBUG_PRINT("info", ("Process %d does not exist anymore", pid)); + DBUG_RETURN(0); + } + DBUG_PRINT("info", ("Sleeping, timeout: %d", timeout)); + /* Sleep one second */ + my_sleep(1000000L); + } + DBUG_RETURN(1); // Did not die +} + + void do_shutdown_server(struct st_command *command) { long timeout= opt_wait_for_pos_timeout ? opt_wait_for_pos_timeout / 5 : 300; @@ -5225,24 +5247,31 @@ void do_shutdown_server(struct st_command *command) } DBUG_PRINT("info", ("Got pid %d", pid)); - /* Tell server to shutdown if timeout > 0*/ + /* + If timeout == 0, it means we should kill the server hard, without + any shutdown or core (SIGKILL) + + If timeout is given, then we do things in the following order: + - mysql_shutdown() + - If server is not dead within timeout + - kill SIGABRT (to get a core) + - If server is not dead within new timeout + - kill SIGKILL + */ + if (timeout && mysql_shutdown(mysql, SHUTDOWN_DEFAULT)) die("mysql_shutdown failed"); - /* Check that server dies */ - while(timeout--){ - if (my_kill(pid, 0) < 0){ - DBUG_PRINT("info", ("Process %d does not exist anymore", pid)); - DBUG_VOID_RETURN; + if (!timeout || wait_until_dead(pid, timeout)) + { + if (timeout) + (void) my_kill(pid, SIGABRT); + /* Give server a few seconds to die in all cases */ + if (!timeout || wait_until_dead(pid, timeout < 5 ? 5 : timeout)) + { + (void) my_kill(pid, SIGKILL); } - DBUG_PRINT("info", ("Sleeping, timeout: %ld", timeout)); - my_sleep(1000000L); } - - /* Kill the server */ - DBUG_PRINT("info", ("Killing server, pid: %d", pid)); - (void)my_kill(pid, 9); - DBUG_VOID_RETURN; } @@ -8944,7 +8973,7 @@ static void dump_backtrace(void) #endif } fputs("Attempting backtrace...\n", stderr); - my_print_stacktrace(NULL, (ulong)my_thread_stack_size); + my_print_stacktrace(NULL, (ulong)my_thread_stack_size, 0); } #else |