Commit e8069d0a authored by unknown's avatar unknown

Merge pilot.blaudden:/home/msvensson/mysql/bug25074/my50-bug25074

into  pilot.blaudden:/home/msvensson/mysql/bug25074/my51-bug25074-new


client/mysql_upgrade.c:
  Manual merge
parents 7f2a0dd9 91b3b312
...@@ -54,6 +54,8 @@ static char *default_dbug_option= (char*) "d:t:O,/tmp/mysql_upgrade.trace"; ...@@ -54,6 +54,8 @@ static char *default_dbug_option= (char*) "d:t:O,/tmp/mysql_upgrade.trace";
#endif #endif
static my_bool info_flag= 0, tty_password= 0; static my_bool info_flag= 0, tty_password= 0;
static char **defaults_argv;
static struct my_option my_long_options[]= static struct my_option my_long_options[]=
{ {
{"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG, {"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
...@@ -282,6 +284,10 @@ static int create_defaults_file(const char *path, const char *forced_path) ...@@ -282,6 +284,10 @@ static int create_defaults_file(const char *path, const char *forced_path)
DYNAMIC_STRING buf; DYNAMIC_STRING buf;
extra_default_t *d; extra_default_t *d;
DBUG_ENTER("create_defaults_file");
DBUG_PRINT("enter", ("path: %s, forced_path: %s", path, forced_path));
/* Delete any previous defaults file generated by mysql_upgrade */
my_delete(path, MYF(0)); my_delete(path, MYF(0));
defaults_file= my_open(path, O_BINARY | O_CREAT | O_WRONLY | O_EXCL, defaults_file= my_open(path, O_BINARY | O_CREAT | O_WRONLY | O_EXCL,
...@@ -298,6 +304,7 @@ static int create_defaults_file(const char *path, const char *forced_path) ...@@ -298,6 +304,7 @@ static int create_defaults_file(const char *path, const char *forced_path)
goto error; goto error;
} }
/* Copy forced_path file into the defaults_file being generated */
if (forced_path) if (forced_path)
{ {
forced_file= my_open(forced_path, O_RDONLY, MYF(MY_FAE | MY_WME)); forced_file= my_open(forced_path, O_RDONLY, MYF(MY_FAE | MY_WME));
...@@ -306,6 +313,7 @@ static int create_defaults_file(const char *path, const char *forced_path) ...@@ -306,6 +313,7 @@ static int create_defaults_file(const char *path, const char *forced_path)
ret= 1; ret= 1;
goto error; goto error;
} }
DBUG_PRINT("info", ("Copying from %s to %s", forced_path, path));
do do
{ {
cnt= my_read(forced_file, buf.str, buf.max_length, MYF(MY_WME)); cnt= my_read(forced_file, buf.str, buf.max_length, MYF(MY_WME));
...@@ -316,10 +324,12 @@ static int create_defaults_file(const char *path, const char *forced_path) ...@@ -316,10 +324,12 @@ static int create_defaults_file(const char *path, const char *forced_path)
my_close(forced_file, MYF(0)); my_close(forced_file, MYF(0));
goto error; goto error;
} }
DBUG_PRINT("info", ("%s", buf.str));
} while (cnt == buf.max_length); } while (cnt == buf.max_length);
my_close(forced_file, MYF(0)); my_close(forced_file, MYF(0));
} }
/* Write all extra_default options into the [client] section */
dynstr_set(&buf, "\n[client]"); dynstr_set(&buf, "\n[client]");
if (opt_password) if (opt_password)
{ {
...@@ -330,6 +340,7 @@ static int create_defaults_file(const char *path, const char *forced_path) ...@@ -330,6 +340,7 @@ static int create_defaults_file(const char *path, const char *forced_path)
goto error; goto error;
} }
} }
DBUG_PRINT("info", ("Writing extra_defaults to file"));
while (extra_defaults) while (extra_defaults)
{ {
int len; int len;
...@@ -338,6 +349,7 @@ static int create_defaults_file(const char *path, const char *forced_path) ...@@ -338,6 +349,7 @@ static int create_defaults_file(const char *path, const char *forced_path)
len= d->n_len + d->v_len + 1; len= d->n_len + d->v_len + 1;
if (buf.length + len >= buf.max_length) /* to avoid realloc() */ if (buf.length + len >= buf.max_length) /* to avoid realloc() */
{ {
if (my_write(defaults_file, buf.str, buf.length, MYF(MY_FNABP | MY_WME))) if (my_write(defaults_file, buf.str, buf.length, MYF(MY_FNABP | MY_WME)))
{ {
ret= 1; ret= 1;
...@@ -345,15 +357,16 @@ static int create_defaults_file(const char *path, const char *forced_path) ...@@ -345,15 +357,16 @@ static int create_defaults_file(const char *path, const char *forced_path)
} }
dynstr_set(&buf, NULL); dynstr_set(&buf, NULL);
} }
if (dynstr_append_mem(&buf, "\n", 1) if (dynstr_append_mem(&buf, "\n", 1) ||
|| dynstr_append_mem(&buf, d->name, d->n_len) dynstr_append_mem(&buf, d->name, d->n_len) ||
|| (d->v_len && (dynstr_append_mem(&buf, "=", 1) (d->v_len && (dynstr_append_mem(&buf, "=", 1) ||
|| dynstr_append_mem(&buf, d->value, d->v_len)))) dynstr_append_mem(&buf, d->value, d->v_len))))
{ {
ret= 1; ret= 1;
goto error; goto error;
} }
my_delete((gptr)d, MYF(0)); DBUG_PRINT("info", ("%s", buf.str));
my_free((gptr)d, MYF(0));
list_pop(extra_defaults); /* pop off the head */ list_pop(extra_defaults); /* pop off the head */
} }
if (my_write(defaults_file, buf.str, buf.length, MYF(MY_FNABP | MY_WME))) if (my_write(defaults_file, buf.str, buf.length, MYF(MY_FNABP | MY_WME)))
...@@ -373,7 +386,7 @@ static int create_defaults_file(const char *path, const char *forced_path) ...@@ -373,7 +386,7 @@ static int create_defaults_file(const char *path, const char *forced_path)
my_delete(path, MYF(0)); my_delete(path, MYF(0));
out: out:
return ret; DBUG_RETURN(ret);
} }
...@@ -450,12 +463,8 @@ int main(int argc, char **argv) ...@@ -450,12 +463,8 @@ int main(int argc, char **argv)
char *forced_defaults_file; char *forced_defaults_file;
char *forced_extra_defaults; char *forced_extra_defaults;
char *local_defaults_group_suffix; char *local_defaults_group_suffix;
const char *script_line;
char *upgrade_defaults_path= 0; char path[FN_REFLEN], upgrade_defaults_path[FN_REFLEN];
char *defaults_to_use= NULL;
int upgrade_defaults_created= 0;
char path[FN_REFLEN];
DYNAMIC_STRING cmdline; DYNAMIC_STRING cmdline;
MY_INIT(argv[0]); MY_INIT(argv[0]);
...@@ -469,6 +478,7 @@ int main(int argc, char **argv) ...@@ -469,6 +478,7 @@ int main(int argc, char **argv)
&local_defaults_group_suffix); &local_defaults_group_suffix);
load_defaults("my", load_default_groups, &argc, &argv); load_defaults("my", load_default_groups, &argc, &argv);
defaults_argv= argv;
/* /*
Must init_dynamic_string before handle_options because string is freed Must init_dynamic_string before handle_options because string is freed
...@@ -516,25 +526,19 @@ int main(int argc, char **argv) ...@@ -516,25 +526,19 @@ int main(int argc, char **argv)
goto error; goto error;
} }
/* /*
Create the modified defaults file to be used by mysqlcheck Create the modified defaults file to be used by mysqlcheck
and mysql tools and mysql command line client
*/ */
fn_format(path, UPGRADE_DEFAULTS_NAME, datadir, "", MYF(0)); fn_format(upgrade_defaults_path, UPGRADE_DEFAULTS_NAME, datadir, "", MYF(0));
upgrade_defaults_path= my_strdup(path, MYF(0)); create_defaults_file(upgrade_defaults_path, forced_extra_defaults);
if (extra_defaults)
{
ret= create_defaults_file(upgrade_defaults_path, forced_extra_defaults);
if (ret)
goto error;
defaults_to_use= upgrade_defaults_path;
upgrade_defaults_created= 1;
}
else
defaults_to_use= forced_extra_defaults;
/*
Read the mysql_upgrade_info file to check if mysql_upgrade
already has been done
Maybe this could be done a little earlier?
*/
if (!find_file(MYSQL_UPGRADE_INFO_NAME, datadir, MY_SEARCH_SELF, if (!find_file(MYSQL_UPGRADE_INFO_NAME, datadir, MY_SEARCH_SELF,
path, sizeof(path), NULL, NullS) path, sizeof(path), NULL, NullS)
&& !opt_force) && !opt_force)
...@@ -553,7 +557,9 @@ int main(int argc, char **argv) ...@@ -553,7 +557,9 @@ int main(int argc, char **argv)
goto fix_priv_tables; goto fix_priv_tables;
} }
} }
/* Find mysqlcheck */
if (find_file(mysqlcheck_name, basedir, MYF(0), path, sizeof(path), if (find_file(mysqlcheck_name, basedir, MYF(0), path, sizeof(path),
"bin", EXTRA_CLIENT_PATHS, NullS)) "bin", EXTRA_CLIENT_PATHS, NullS))
{ {
...@@ -575,13 +581,13 @@ int main(int argc, char **argv) ...@@ -575,13 +581,13 @@ int main(int argc, char **argv)
dynstr_append_os_quoted(&cmdline, path, NullS); dynstr_append_os_quoted(&cmdline, path, NullS);
} }
if (defaults_to_use) /*
{ All settings have been written to the "upgrade_defaults_path"
dynstr_append(&cmdline, " "); instruct mysqlcheck to only read options from that file
dynstr_append_os_quoted(&cmdline, "--defaults-extra-file=", */
defaults_to_use, NullS); dynstr_append(&cmdline, " ");
} dynstr_append_os_quoted(&cmdline, "--defaults-file=",
upgrade_defaults_path, NullS);
dynstr_append(&cmdline, " "); dynstr_append(&cmdline, " ");
dynstr_append_os_quoted(&cmdline, "--check-upgrade", NullS); dynstr_append_os_quoted(&cmdline, "--check-upgrade", NullS);
dynstr_append(&cmdline, " "); dynstr_append(&cmdline, " ");
...@@ -594,9 +600,10 @@ int main(int argc, char **argv) ...@@ -594,9 +600,10 @@ int main(int argc, char **argv)
dynstr_append(&cmdline, "\""); dynstr_append(&cmdline, "\"");
#endif /* __WIN__ */ #endif /* __WIN__ */
/* Execute mysqlcheck */
if (opt_verbose) if (opt_verbose)
printf("Running %s\n", cmdline.str); printf("Running %s\n", cmdline.str);
DBUG_PRINT("info", ("Running: %s", cmdline.str));
ret= system(cmdline.str); ret= system(cmdline.str);
if (ret) if (ret)
{ {
...@@ -610,6 +617,7 @@ int main(int argc, char **argv) ...@@ -610,6 +617,7 @@ int main(int argc, char **argv)
goto error; goto error;
fix_priv_tables: fix_priv_tables:
/* Find mysql */
if (find_file(mysql_name, basedir, MYF(0), path, sizeof(path), if (find_file(mysql_name, basedir, MYF(0), path, sizeof(path),
"bin", EXTRA_CLIENT_PATHS, NullS)) "bin", EXTRA_CLIENT_PATHS, NullS))
{ {
...@@ -631,6 +639,7 @@ int main(int argc, char **argv) ...@@ -631,6 +639,7 @@ int main(int argc, char **argv)
dynstr_append_os_quoted(&cmdline, path, NullS); dynstr_append_os_quoted(&cmdline, path, NullS);
} }
/* Find mysql_fix_privililege_tables.sql */
if (find_file(MYSQL_FIX_PRIV_TABLES_NAME, basedir, MYF(0), if (find_file(MYSQL_FIX_PRIV_TABLES_NAME, basedir, MYF(0),
path, sizeof(path), path, sizeof(path),
"support_files", "share", "share/mysql", "scripts", "support_files", "share", "share/mysql", "scripts",
...@@ -646,15 +655,14 @@ int main(int argc, char **argv) ...@@ -646,15 +655,14 @@ int main(int argc, char **argv)
" where MySQL is installed"); " where MySQL is installed");
goto error; goto error;
} }
else
script_line= my_strdup(path, MYF(0));
if (defaults_to_use) /*
{ All settings have been written to the "upgrade_defaults_path",
dynstr_append(&cmdline, " "); instruct mysql to only read options from that file
dynstr_append_os_quoted(&cmdline, "--defaults-extra-file=", */
defaults_to_use, NullS); dynstr_append(&cmdline, " ");
} dynstr_append_os_quoted(&cmdline, "--defaults-file=",
upgrade_defaults_path, NullS);
dynstr_append(&cmdline, " "); dynstr_append(&cmdline, " ");
dynstr_append_os_quoted(&cmdline, "--force", NullS); dynstr_append_os_quoted(&cmdline, "--force", NullS);
dynstr_append(&cmdline, " "); dynstr_append(&cmdline, " ");
...@@ -666,14 +674,15 @@ int main(int argc, char **argv) ...@@ -666,14 +674,15 @@ int main(int argc, char **argv)
dynstr_append(&cmdline, " "); dynstr_append(&cmdline, " ");
dynstr_append_os_quoted(&cmdline, "--database=mysql", NullS); dynstr_append_os_quoted(&cmdline, "--database=mysql", NullS);
dynstr_append(&cmdline, " < "); dynstr_append(&cmdline, " < ");
dynstr_append_os_quoted(&cmdline, script_line, NullS); dynstr_append_os_quoted(&cmdline, path, NullS);
#ifdef __WIN__ #ifdef __WIN__
dynstr_append(&cmdline, "\""); dynstr_append(&cmdline, "\"");
#endif /* __WIN__ */ #endif /* __WIN__ */
/* Execute "mysql --force < mysql_fix_privilege_tables.sql" */
if (opt_verbose) if (opt_verbose)
printf("Running %s\n", cmdline.str); printf("Running %s\n", cmdline.str);
DBUG_PRINT("info", ("Running: %s", cmdline.str));
ret= system(cmdline.str); ret= system(cmdline.str);
if (ret) if (ret)
fprintf(stderr, "Error executing '%s'\n", cmdline.str); fprintf(stderr, "Error executing '%s'\n", cmdline.str);
...@@ -681,9 +690,10 @@ int main(int argc, char **argv) ...@@ -681,9 +690,10 @@ int main(int argc, char **argv)
error: error:
dynstr_free(&cmdline); dynstr_free(&cmdline);
if (upgrade_defaults_created) /* Delete the generated defaults file */
my_delete(upgrade_defaults_path, MYF(0)); my_delete(upgrade_defaults_path, MYF(0));
free_defaults(defaults_argv);
my_end(info_flag ? MY_CHECK_ERROR : 0); my_end(info_flag ? MY_CHECK_ERROR : 0);
return ret; return ret;
} }
......
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