Skip to content

Commit

Permalink
Merge from mysql-5.1-bugteam.
Browse files Browse the repository at this point in the history
--BZR--
revision-id: [email protected]
property-branch-nick: mysql-trunk-bugfixing
testament3-sha1: 1231231b6cc034bdeea58ac280b5970d8bcf76a2
  • Loading branch information
Alexander Nozdrin committed Sep 16, 2009
2 parents 4384105 + 951e5cc commit 36f1ff0
Show file tree
Hide file tree
Showing 171 changed files with 6,904 additions and 1,050 deletions.
Binary file modified .bzrfileids
Binary file not shown.
9 changes: 5 additions & 4 deletions BUILD/check-cpu
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ check_cpu () {
Alpha*EV6*)
cpu_arg="ev6";
;;
#Core 2 Duo
*Intel*Core\(TM\)2*)
cpu_arg="nocona"
core2="yes"
;;
# Intel ia32
*Intel*Core*|*X[eE][oO][nN]*)
# a Xeon is just another pentium4 ...
Expand Down Expand Up @@ -137,10 +142,6 @@ check_cpu () {
*i386*)
cpu_arg="i386"
;;
#Core 2 Duo
*Intel*Core\(TM\)2*)
cpu_arg="nocona"
;;
# Intel ia64
*Itanium*)
cpu_arg="itanium"
Expand Down
21 changes: 11 additions & 10 deletions client/mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extern "C" {
#endif

#undef bcmp // Fix problem with new readline
#if defined( __WIN__)
#if defined(__WIN__)
#include <conio.h>
#elif !defined(__NETWARE__)
#include <readline/readline.h>
Expand All @@ -106,7 +106,7 @@ extern "C" {
#define cmp_database(cs,A,B) strcmp((A),(B))
#endif

#if !defined( __WIN__) && !defined(__NETWARE__) && !defined(THREAD)
#if !defined(__WIN__) && !defined(__NETWARE__) && !defined(THREAD)
#define USE_POPEN
#endif

Expand Down Expand Up @@ -1862,7 +1862,7 @@ static int read_and_execute(bool interactive)
if (opt_outfile && glob_buffer.is_empty())
fflush(OUTFILE);

#if defined( __WIN__) || defined(__NETWARE__)
#if defined(__WIN__) || defined(__NETWARE__)
tee_fputs(prompt, stdout);
#if defined(__NETWARE__)
line=fgets(linebuffer, sizeof(linebuffer)-1, stdin);
Expand All @@ -1873,7 +1873,7 @@ static int read_and_execute(bool interactive)
if (p != NULL)
*p = '\0';
}
#else defined(__WIN__)
#else
if (!tmpbuf.is_alloced())
tmpbuf.alloc(65535);
tmpbuf.length(0);
Expand All @@ -1899,7 +1899,7 @@ static int read_and_execute(bool interactive)
if (opt_outfile)
fputs(prompt, OUTFILE);
line= readline(prompt);
#endif /* defined( __WIN__) || defined(__NETWARE__) */
#endif /* defined(__WIN__) || defined(__NETWARE__) */

/*
When Ctrl+d or Ctrl+z is pressed, the line may be NULL on some OS
Expand Down Expand Up @@ -1947,10 +1947,10 @@ static int read_and_execute(bool interactive)
}
}

#if defined( __WIN__) || defined(__NETWARE__)
#if defined(__WIN__) || defined(__NETWARE__)
buffer.free();
#endif
#if defined( __WIN__)
#if defined(__WIN__)
tmpbuf.free();
#endif

Expand Down Expand Up @@ -3819,7 +3819,8 @@ com_edit(String *buffer,char *line __attribute__((unused)))
!(editor = (char *)getenv("VISUAL")))
editor = "vi";
strxmov(buff,editor," ",filename,NullS);
(void) system(buff);
if(system(buff) == -1)
goto err;

MY_STAT stat_arg;
if (!my_stat(filename,&stat_arg,MYF(MY_WME)))
Expand Down Expand Up @@ -4602,7 +4603,7 @@ void tee_putc(int c, FILE *file)
putc(c, OUTFILE);
}

#if defined( __WIN__) || defined(__NETWARE__)
#if defined(__WIN__) || defined(__NETWARE__)
#include <time.h>
#else
#include <sys/times.h>
Expand All @@ -4614,7 +4615,7 @@ void tee_putc(int c, FILE *file)

static ulong start_timer(void)
{
#if defined( __WIN__) || defined(__NETWARE__)
#if defined(__WIN__) || defined(__NETWARE__)
return clock();
#else
struct tms tms_tmp;
Expand Down
3 changes: 2 additions & 1 deletion client/mysql_upgrade.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ static int upgrade_already_done(void)
FILE *in;
char upgrade_info_file[FN_REFLEN]= {0};
char buf[sizeof(MYSQL_SERVER_VERSION)+1];
char *res;

if (get_upgrade_info_file_name(upgrade_info_file))
return 0; /* Could not get filename => not sure */
Expand All @@ -564,7 +565,7 @@ static int upgrade_already_done(void)
will be detected by the strncmp
*/
bzero(buf, sizeof(buf));
fgets(buf, sizeof(buf), in);
res= fgets(buf, sizeof(buf), in);

my_fclose(in, MYF(0));

Expand Down
138 changes: 104 additions & 34 deletions client/mysqladmin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#endif
#include <sys/stat.h>
#include <mysql.h>
#include <sql_common.h>

#define ADMIN_VERSION "8.42"
#define MAX_MYSQL_VAR 512
Expand Down Expand Up @@ -353,6 +354,11 @@ int main(int argc,char *argv[])

if (sql_connect(&mysql, option_wait))
{
/*
We couldn't get an initial connection and will definitely exit.
The following just determines the exit-code we'll give.
*/

unsigned int err= mysql_errno(&mysql);
if (err >= CR_MIN_ERROR && err <= CR_MAX_ERROR)
error= 1;
Expand All @@ -371,41 +377,79 @@ int main(int argc,char *argv[])
}
else
{
while (!interrupted)
/*
--count=0 aborts right here. Otherwise iff --sleep=t ("interval")
is given a t!=0, we get an endless loop, or n iterations if --count=n
was given an n!=0. If --sleep wasn't given, we get one iteration.
To wit, --wait loops the connection-attempts, while --sleep loops
the command execution (endlessly if no --count is given).
*/

while (!interrupted && (!opt_count_iterations || nr_iterations))
{
new_line = 0;
if ((error=execute_commands(&mysql,argc,commands)))

if ((error= execute_commands(&mysql,argc,commands)))
{
/*
Unknown/malformed command always aborts and can't be --forced.
If the user got confused about the syntax, proceeding would be
dangerous ...
*/
if (error > 0)
break; /* Wrong command error */
if (!option_force)
break;

/*
Command was well-formed, but failed on the server. Might succeed
on retry (if conditions on server change etc.), but needs --force
to retry.
*/
if (!option_force)
break;
} /* if((error= ... */

if (interval) /* --sleep=interval given */
{
/*
If connection was dropped (unintentionally, or due to SHUTDOWN),
re-establish it if --wait ("retry-connect") was given and user
didn't signal for us to die. Otherwise, signal failure.
*/

if (mysql.net.vio == 0)
{
if (option_wait && !interrupted)
{
mysql_close(&mysql);
if (!sql_connect(&mysql, option_wait))
{
sleep(1); /* Don't retry too rapidly */
continue; /* Retry */
}
sleep(1);
sql_connect(&mysql, option_wait);
/*
continue normally and decrease counters so that
"mysqladmin --count=1 --wait=1 shutdown"
cannot loop endlessly.
*/
}
error=1;
break;
}
}
if (interval)
{
if (opt_count_iterations && --nr_iterations == 0)
break;
else
{
/*
connexion broke, and we have no order to re-establish it. fail.
*/
if (!option_force)
error= 1;
break;
}
} /* lost connection */

sleep(interval);
if (new_line)
puts("");
}
else
break;
}
mysql_close(&mysql);
}
break; /* no --sleep, done looping */
} /* command-loop */
} /* got connection */

mysql_close(&mysql);
my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
my_free(user,MYF(MY_ALLOW_ZERO_PTR));
#ifdef HAVE_SMEM
Expand All @@ -423,6 +467,17 @@ sig_handler endprog(int signal_number __attribute__((unused)))
interrupted=1;
}

/**
@brief connect to server, optionally waiting for same to come up
@param mysql connection struct
@param wait wait for server to come up?
(0: no, ~0: forever, n: cycles)
@return Operation result
@retval 0 success
@retval 1 failure
*/

static my_bool sql_connect(MYSQL *mysql, uint wait)
{
Expand All @@ -431,7 +486,7 @@ static my_bool sql_connect(MYSQL *mysql, uint wait)
for (;;)
{
if (mysql_real_connect(mysql,host,user,opt_password,NullS,tcp_port,
unix_port, 0))
unix_port, CLIENT_REMEMBER_OPTIONS))
{
mysql->reconnect= 1;
if (info)
Expand All @@ -442,9 +497,9 @@ static my_bool sql_connect(MYSQL *mysql, uint wait)
return 0;
}

if (!wait)
if (!wait) // was or reached 0, fail
{
if (!option_silent)
if (!option_silent) // print diagnostics
{
if (!host)
host= (char*) LOCAL_HOST;
Expand All @@ -468,11 +523,18 @@ static my_bool sql_connect(MYSQL *mysql, uint wait)
}
return 1;
}

if (wait != (uint) ~0)
wait--; /* One less retry */
wait--; /* count down, one less retry */

if ((mysql_errno(mysql) != CR_CONN_HOST_ERROR) &&
(mysql_errno(mysql) != CR_CONNECTION_ERROR))
{
/*
Error is worse than "server doesn't answer (yet?)";
fail even if we still have "wait-coins" unless --force
was also given.
*/
fprintf(stderr,"Got error: %s\n", mysql_error(mysql));
if (!option_force)
return 1;
Expand All @@ -496,11 +558,18 @@ static my_bool sql_connect(MYSQL *mysql, uint wait)
}


/*
Execute a command.
Return 0 on ok
-1 on retryable error
1 on fatal error
/**
@brief Execute all commands
@details We try to execute all commands we were given, in the order
given, but return with non-zero as soon as we encounter trouble.
By that token, individual commands can be considered a conjunction
with boolean short-cut.
@return success?
@retval 0 Yes! ALL commands worked!
@retval 1 No, one failed and will never work (malformed): fatal error!
@retval -1 No, one failed on the server, may work next time!
*/

static int execute_commands(MYSQL *mysql,int argc, char **argv)
Expand Down Expand Up @@ -570,7 +639,6 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)
mysql_error(mysql));
return -1;
}
mysql_close(mysql); /* Close connection to avoid error messages */
argc=1; /* force SHUTDOWN to be the last command */
if (got_pidfile)
{
Expand Down Expand Up @@ -1036,14 +1104,16 @@ static void usage(void)
static int drop_db(MYSQL *mysql, const char *db)
{
char name_buff[FN_REFLEN+20], buf[10];
char *input;

if (!option_force)
{
puts("Dropping the database is potentially a very bad thing to do.");
puts("Any data stored in the database will be destroyed.\n");
printf("Do you really want to drop the '%s' database [y/N] ",db);
fflush(stdout);
VOID(fgets(buf,sizeof(buf)-1,stdin));
if ((*buf != 'y') && (*buf != 'Y'))
input= fgets(buf, sizeof(buf)-1, stdin);
if (!input || ((*input != 'y') && (*input != 'Y')))
{
puts("\nOK, aborting database drop!");
return -1;
Expand Down
6 changes: 3 additions & 3 deletions client/mysqldump.c
Original file line number Diff line number Diff line change
Expand Up @@ -5008,22 +5008,22 @@ int main(int argc, char **argv)
exit_code= get_options(&argc, &argv);
if (exit_code)
{
free_resources(0);
free_resources();
exit(exit_code);
}

if (log_error_file)
{
if(!(stderror_file= freopen(log_error_file, "a+", stderr)))
{
free_resources(0);
free_resources();
exit(EX_MYSQLERR);
}
}

if (connect_to_db(current_host, current_user, opt_password))
{
free_resources(0);
free_resources();
exit(EX_MYSQLERR);
}
if (!path)
Expand Down
Loading

0 comments on commit 36f1ff0

Please sign in to comment.