Commit 6349071f authored by unknown's avatar unknown

Merge pilot.blaudden:/home/msvensson/mysql/mysql-5.0-maint

into  pilot.blaudden:/home/msvensson/mysql/mysql-5.1-maint


client/mysql_upgrade.c:
  Auto merged
mysql-test/r/mysql_upgrade.result:
  Auto merged
mysql-test/t/mysql_upgrade.test:
  Auto merged
parents f7027dba 36cd228a
...@@ -17,14 +17,25 @@ ...@@ -17,14 +17,25 @@
#include <sslopt-vars.h> #include <sslopt-vars.h>
#include "../scripts/mysql_fix_privilege_tables_sql.c" #include "../scripts/mysql_fix_privilege_tables_sql.c"
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#ifndef WEXITSTATUS
# ifdef __WIN__
# define WEXITSTATUS(stat_val) (stat_val)
# else
# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
# endif
#endif
static char mysql_path[FN_REFLEN]; static char mysql_path[FN_REFLEN];
static char mysqlcheck_path[FN_REFLEN]; static char mysqlcheck_path[FN_REFLEN];
static char defaults_file_option[32+FN_REFLEN];
static my_bool opt_force, opt_verbose; static my_bool opt_force, opt_verbose;
static char *opt_user= (char*)"root"; static char *opt_user= (char*)"root";
static DYNAMIC_STRING ds_options; static DYNAMIC_STRING ds_args;
static char *opt_password= 0; static char *opt_password= 0;
static my_bool tty_password= 0; static my_bool tty_password= 0;
...@@ -35,8 +46,6 @@ static char *default_dbug_option= (char*) "d:t:O,/tmp/mysql_upgrade.trace"; ...@@ -35,8 +46,6 @@ static char *default_dbug_option= (char*) "d:t:O,/tmp/mysql_upgrade.trace";
static char **defaults_argv; static char **defaults_argv;
static File defaults_fd= -1;
static my_bool not_used; /* Can't use GET_BOOL without a value pointer */ static my_bool not_used; /* Can't use GET_BOOL without a value pointer */
#include <help_start.h> #include <help_start.h>
...@@ -105,14 +114,10 @@ static struct my_option my_long_options[]= ...@@ -105,14 +114,10 @@ static struct my_option my_long_options[]=
static void free_used_memory(void) static void free_used_memory(void)
{ {
/* Close the defaults file */
if (defaults_fd != -1)
my_close(defaults_fd, MYF(0));
/* Free memory allocated by 'load_defaults' */ /* Free memory allocated by 'load_defaults' */
free_defaults(defaults_argv); free_defaults(defaults_argv);
dynstr_free(&ds_options); dynstr_free(&ds_args);
} }
...@@ -159,30 +164,30 @@ static void verbose(const char *fmt, ...) ...@@ -159,30 +164,30 @@ static void verbose(const char *fmt, ...)
/* /*
Add one option - passed to mysql_upgrade on command line Add one option - passed to mysql_upgrade on command line
or by defaults file(my.cnf) - to a dynamic string that later or by defaults file(my.cnf) - to a dynamic string, in
can be written to a temporary file. In this way we pass the this way we pass the same arguments on to mysql and mysql_check
same arguments on to mysql and mysql_check
*/ */
static void add_one_option(DYNAMIC_STRING* ds, static void add_one_option(DYNAMIC_STRING* ds,
const struct my_option *opt, const struct my_option *opt,
const char* argument) const char* argument)
{
dynstr_append(ds, opt->name);
{
const char* eq= NullS;
const char* arg= NullS;
if (opt->arg_type != NO_ARG) if (opt->arg_type != NO_ARG)
{ {
dynstr_append(ds, "="); eq= "=";
switch (opt->var_type & GET_TYPE_MASK) { switch (opt->var_type & GET_TYPE_MASK) {
case GET_STR: case GET_STR:
case GET_STR_ALLOC: arg= argument;
dynstr_append(ds, argument);
break; break;
default: default:
die("internal error at %s: %d",__FILE__, __LINE__); die("internal error at %s: %d",__FILE__, __LINE__);
} }
} }
dynstr_append(ds, "\n"); dynstr_append_os_quoted(ds, "--", opt->name, eq, arg, NullS);
dynstr_append(&ds_args, " ");
} }
...@@ -211,8 +216,8 @@ get_one_option(int optid, const struct my_option *opt, ...@@ -211,8 +216,8 @@ get_one_option(int optid, const struct my_option *opt,
add_option= FALSE; add_option= FALSE;
if (argument) if (argument)
{ {
/* Add password to ds_options before overwriting the arg with x's */ /* Add password to ds_args before overwriting the arg with x's */
add_one_option(&ds_options, opt, argument); add_one_option(&ds_args, opt, argument);
while (*argument) while (*argument)
*argument++= 'x'; /* Destroy argument */ *argument++= 'x'; /* Destroy argument */
tty_password= 0; tty_password= 0;
...@@ -232,51 +237,14 @@ get_one_option(int optid, const struct my_option *opt, ...@@ -232,51 +237,14 @@ get_one_option(int optid, const struct my_option *opt,
/* /*
This is an option that is accpted by mysql_upgrade just so This is an option that is accpted by mysql_upgrade just so
it can be passed on to "mysql" and "mysqlcheck" it can be passed on to "mysql" and "mysqlcheck"
Save it in the ds_options string Save it in the ds_args string
*/ */
add_one_option(&ds_options, opt, argument); add_one_option(&ds_args, opt, argument);
} }
return 0; return 0;
} }
/*
Write the options that should be passed on to
mysql and mysqlcheck to a temporary file
*/
static void create_defaults_file(void)
{
static char defaults_file_path[FN_REFLEN];
DBUG_ENTER("create_defaults_file");
if ((defaults_fd= create_temp_file(defaults_file_path, NULL,
"cnf", O_CREAT | O_SHARE,
MYF(MY_WME))) < 0)
die("Failed to create temporary file for defaults");
DBUG_PRINT("info", ("Writing options: %s", ds_options.str));
if (my_write(defaults_fd, ds_options.str, ds_options.length,
MYF(MY_FNABP | MY_WME)))
die("Failed to write to '%s'", defaults_file_path);
/*
Dont close the temporary file yet, it will be used
by mysql and mysqlcheck
*/
/*
Create the option that should be added to
tools in order to use this file
*/
my_snprintf(defaults_file_option, sizeof(defaults_file_option),
"--defaults-file=%s", defaults_file_path);
DBUG_PRINT("info", ("defaults_file_option: %s", defaults_file_option));
DBUG_VOID_RETURN;
}
static int run_command(char* cmd, static int run_command(char* cmd,
DYNAMIC_STRING *ds_res) DYNAMIC_STRING *ds_res)
{ {
...@@ -466,7 +434,7 @@ static int run_query(const char *query, DYNAMIC_STRING *ds_res, ...@@ -466,7 +434,7 @@ static int run_query(const char *query, DYNAMIC_STRING *ds_res,
DBUG_ENTER("run_query"); DBUG_ENTER("run_query");
DBUG_PRINT("enter", ("query: %s", query)); DBUG_PRINT("enter", ("query: %s", query));
if ((fd= create_temp_file(query_file_path, NULL, if ((fd= create_temp_file(query_file_path, NULL,
"sql", O_CREAT | O_SHARE, "sql", O_CREAT | O_SHARE | O_RDWR,
MYF(MY_WME))) < 0) MYF(MY_WME))) < 0)
die("Failed to create temporary file for defaults"); die("Failed to create temporary file for defaults");
...@@ -476,7 +444,7 @@ static int run_query(const char *query, DYNAMIC_STRING *ds_res, ...@@ -476,7 +444,7 @@ static int run_query(const char *query, DYNAMIC_STRING *ds_res,
ret= run_tool(mysql_path, ret= run_tool(mysql_path,
ds_res, ds_res,
defaults_file_option, ds_args.str, // MASV... quoted?
"--database=mysql", "--database=mysql",
"--batch", /* Turns off pager etc. */ "--batch", /* Turns off pager etc. */
force ? "--force": "--skip-force", force ? "--force": "--skip-force",
...@@ -631,7 +599,7 @@ static int run_mysqlcheck_upgrade(void) ...@@ -631,7 +599,7 @@ static int run_mysqlcheck_upgrade(void)
verbose("Running 'mysqlcheck'..."); verbose("Running 'mysqlcheck'...");
return run_tool(mysqlcheck_path, return run_tool(mysqlcheck_path,
NULL, /* Send output from mysqlcheck directly to screen */ NULL, /* Send output from mysqlcheck directly to screen */
defaults_file_option, ds_args.str,
"--check-upgrade", "--check-upgrade",
"--all-databases", "--all-databases",
"--auto-repair", "--auto-repair",
...@@ -747,7 +715,7 @@ int main(int argc, char **argv) ...@@ -747,7 +715,7 @@ int main(int argc, char **argv)
setscreenmode(SCR_AUTOCLOSE_ON_EXIT); setscreenmode(SCR_AUTOCLOSE_ON_EXIT);
#endif #endif
if (init_dynamic_string(&ds_options, "[client]\n", 512, 256)) if (init_dynamic_string(&ds_args, "", 512, 256))
die("Out of memory"); die("Out of memory");
load_defaults("my", load_default_groups, &argc, &argv); load_defaults("my", load_default_groups, &argc, &argv);
...@@ -760,14 +728,12 @@ int main(int argc, char **argv) ...@@ -760,14 +728,12 @@ int main(int argc, char **argv)
{ {
opt_password= get_tty_password(NullS); opt_password= get_tty_password(NullS);
/* add password to defaults file */ /* add password to defaults file */
dynstr_append(&ds_options, "password="); dynstr_append_os_quoted(&ds_args, "--password=", opt_password, NullS);
dynstr_append(&ds_options, opt_password); dynstr_append(&ds_args, " ");
dynstr_append(&ds_options, "\n");
} }
/* add user to defaults file */ /* add user to defaults file */
dynstr_append(&ds_options, "user="); dynstr_append_os_quoted(&ds_args, "--user=", opt_user, NullS);
dynstr_append(&ds_options, opt_user); dynstr_append(&ds_args, " ");
dynstr_append(&ds_options, "\n");
/* Find mysql */ /* Find mysql */
find_tool(mysql_path, IF_WIN("mysql.exe", "mysql")); find_tool(mysql_path, IF_WIN("mysql.exe", "mysql"));
...@@ -775,13 +741,6 @@ int main(int argc, char **argv) ...@@ -775,13 +741,6 @@ int main(int argc, char **argv)
/* Find mysqlcheck */ /* Find mysqlcheck */
find_tool(mysqlcheck_path, IF_WIN("mysqlcheck.exe", "mysqlcheck")); find_tool(mysqlcheck_path, IF_WIN("mysqlcheck.exe", "mysqlcheck"));
/*
Create the defaults file(a small my.cnf) which will pass
all arguments accepted by mysql_upgrade on to mysqlcheck
and mysql command line client
*/
create_defaults_file();
/* /*
Read the mysql_upgrade_info file to check if mysql_upgrade Read the mysql_upgrade_info file to check if mysql_upgrade
already has been run for this installation of MySQL already has been run for this installation of MySQL
......
...@@ -76,5 +76,5 @@ mysql.time_zone_transition_type OK ...@@ -76,5 +76,5 @@ mysql.time_zone_transition_type OK
mysql.user OK mysql.user OK
DROP USER mysqltest1@'%'; DROP USER mysqltest1@'%';
Run mysql_upgrade with a non existing server socket Run mysql_upgrade with a non existing server socket
mysqlcheck: Got error: 2002: Can't connect to local MySQL server through socket 'var/tmp/no_sock_here' (2) when trying to connect mysqlcheck: Got error: 2005: Unknown MySQL server host 'not_existing_host' (1) when trying to connect
FATAL ERROR: Upgrade failed FATAL ERROR: Upgrade failed
...@@ -54,4 +54,4 @@ DROP USER mysqltest1@'%'; ...@@ -54,4 +54,4 @@ DROP USER mysqltest1@'%';
--replace_result $MYSQLTEST_VARDIR var --replace_result $MYSQLTEST_VARDIR var
--replace_regex /.*mysqlcheck.*: Got/mysqlcheck: Got/ --replace_regex /.*mysqlcheck.*: Got/mysqlcheck: Got/
--error 1 --error 1
--exec $MYSQL_UPGRADE --skip-verbose --force --socket=$MYSQLTEST_VARDIR/tmp/no_sock_here 2>&1 --exec $MYSQL_UPGRADE --skip-verbose --force --host=not_existing_host 2>&1
...@@ -106,6 +106,15 @@ int main(int argc, char *argv[]) ...@@ -106,6 +106,15 @@ int main(int argc, char *argv[])
curr++; curr++;
} }
} }
if (*(curr-1) != '\n')
{
/*
Some compilers have a max string length,
insert a newline at every 512th char in long
strings
*/
fprintf(out, "\"\n\"");
}
} }
fprintf(out, "\\\n\"};\n"); fprintf(out, "\\\n\"};\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment