Below is the list of changes that have just been committed into a local
5.0 repository of ted. When ted does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2006-10-26 16:30:16+04:00, ted@stripped +1 -0
BUG#20100 fix: mysql_upgrade modified to also accept all
the communication paramenters from the cammand line
and pass 'em correctly to both mysqlcheck and mysql
client/mysql_upgrade.c@stripped, 2006-10-26 16:30:14+04:00, ted@stripped +244 -69
Now mysql_upgrade passes all the parameters specified on
the command line to both mysqlcheck and mysql through
the upgrade_defaults file
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: ted
# Host: ted.mysql.internal
# Root: /home/ted/src/mysql/mysql-5.0-maint
--- 1.7/client/mysql_upgrade.c 2006-10-26 16:30:32 +04:00
+++ 1.8/client/mysql_upgrade.c 2006-10-26 16:30:32 +04:00
@@ -16,6 +16,8 @@
#include "client_priv.h"
#include <my_dir.h>
+#include <my_list.h>
+#include <sslopt-vars.h>
#ifdef __WIN__
const char *mysqlcheck_name= "mysqlcheck.exe";
@@ -25,11 +27,20 @@
const char *mysql_name= "mysql";
#endif /*__WIN__*/
-static my_bool opt_force= 0, opt_verbose= 0, tty_password= 0;
+extern TYPELIB sql_protocol_typelib;
+
+static my_bool opt_force= 0, opt_verbose= 0, tty_password= 0, opt_compress = 0;
static char *user= (char*) "root", *basedir= 0, *datadir= 0, *opt_password= 0;
-static my_bool upgrade_defaults_created= 0;
+static char *current_host = 0;
+static char *opt_default_charset = 0, *opt_charsets_dir = 0;
+#ifdef HAVE_SMEM
+static char *shared_memory_base_name=0;
+#endif
+static char *opt_protocol=0;
static my_string opt_mysql_port, opt_mysql_unix_port= 0;
+#ifndef DBG_OFF
static char *default_dbug_option= (char*) "d:t:O,/tmp/comp_err.trace";
+#endif
static my_bool info_flag= 0;
static struct my_option my_long_options[]=
@@ -50,23 +61,45 @@
#endif
{"debug-info", 'T', "Print some debug info at exit.", (gptr *) & info_flag,
(gptr *) & info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
- {"force", 'f', "Continue even if we get an sql-error.",
+ {"default-character-set", OPT_DEFAULT_CHARSET,
+ "Set the default character set.", (gptr*) &opt_default_charset,
+ (gptr*) &opt_default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"force", 'f', "Force execution of mysqlcheck even if mysql_upgrade "
+ "has already been executed for the current version of MySQL.",
(gptr*) &opt_force, (gptr*) &opt_force, 0, GET_BOOL, NO_ARG, 0, 0,
0, 0, 0, 0},
+ {"character-sets-dir", OPT_CHARSETS_DIR,
+ "Directory where character sets are.", (gptr*) &opt_charsets_dir,
+ (gptr*) &opt_charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"compress", OPT_COMPRESS, "Use compression in server/client protocol.",
+ (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
+ 0, 0, 0},
+ {"host",'h', "Connect to host.", (gptr*) ¤t_host,
+ (gptr*) ¤t_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"password", 'p',
"Password to use when connecting to server. If password is not given it's solicited on
the tty.",
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
+#ifdef __WIN__
+ {"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
+ NO_ARG, 0, 0, 0, 0, 0, 0},
+#endif
{"port", 'P', "Port number to use for connection.", (gptr*) &opt_mysql_port,
(gptr*) &opt_mysql_port, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0,
0},
{"protocol", OPT_MYSQL_PROTOCOL,
"The protocol of connection (tcp,socket,pipe,memory).",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+#ifdef HAVE_SMEM
+ {"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
+ "Base name of shared memory.", (gptr*) &shared_memory_base_name, (gptr*)
&shared_memory_base_name,
+ 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+#endif
{"socket", 'S', "Socket file to use for connection.",
(gptr*) &opt_mysql_unix_port, (gptr*) &opt_mysql_unix_port, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"user", 'u', "User for login if not current user.", (gptr*) &user,
(gptr*) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+#include <sslopt-longopts.h>
{"verbose", 'v', "Display more output about the process", (gptr*) &opt_verbose,
(gptr *) &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
@@ -78,6 +111,80 @@
#include <help_end.h>
+static LIST *extra_defaults = NULL;
+
+typedef struct _extra_default
+{
+ int id;
+ const char *name;
+ int n_len;
+ const char *value;
+ int v_len;
+} extra_default_rec_t, *extra_default_t;
+
+static inline
+void set_extra_default(int id, const struct my_option *opt)
+{
+ switch (id) {
+ case 'b': case 'd': /* these are ours */
+ case 'f': /* --force is ours */
+ case 'u': /* --user passed on cmdline */
+ case 'T': /* --debug-info is not accepted by mysqlcheck */
+ /* so, do nothing */
+ break;
+ default:
+ {
+ LIST *l;
+ extra_default_t d;
+
+ /* remove any earlier duplicates: they can
+ * refer to invalid memory addresses (stale ponters)
+ */
+ l = extra_defaults;
+ while (l)
+ {
+ LIST *n = l->next;
+
+ d = l->data;
+ if (d->id == id)
+ {
+ my_free((gptr)d, MYF(0));
+ extra_defaults = list_delete(extra_defaults, l);
+ my_free((gptr)l, MYF(0));
+ }
+ l = n;
+ }
+
+ d = (extra_default_t)my_malloc(sizeof(extra_default_rec_t),
+ MYF(MY_FAE|MY_ZEROFILL));
+
+ d->id = id;
+ d->name = opt->name;
+ d->n_len = strlen(opt->name);
+ if (opt->arg_type != NO_ARG)
+ switch (opt->var_type & GET_TYPE_MASK) {
+ case GET_BOOL:
+ if (*((int *)opt->value))
+ {
+ d->value = "true";
+ d->v_len = 4;
+ }
+ break;
+ case GET_STR:
+ case GET_STR_ALLOC:
+ d->value = *opt->value;
+ d->v_len = strlen(d->value);
+ break;
+ default:
+ my_printf_error(0, "Error: internal error at %s:%d", MYF(0),
+ __FILE__, __LINE__);
+ exit(1);
+ }
+ list_push(extra_defaults, d);
+ }
+ }
+}
+
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__ ((unused)),
char *argument)
@@ -109,8 +216,28 @@
tty_password= 0;
}
break;
+#include <sslopt-case.h>
+ case 'W':
+#ifdef __WIN__
+ my_free(opt_protocol, MYF(MY_ALLOW_ZERO_PTR));
+ opt_protocol = my_strdup("pipe", MYF(MY_FAE));
+#endif
+ break;
+ case OPT_MYSQL_PROTOCOL:
+ if (find_type(argument, &sql_protocol_typelib, 0) > 0)
+ {
+ my_free(opt_protocol, MYF(MY_ALLOW_ZERO_PTR));
+ opt_protocol = my_strdup(argument, MYF(MY_FAE));
+ }
+ else
+ {
+ fprintf(stderr, "Unknown option to protocol: %s\n", argument);
+ exit(1);
+ }
+ break;
default:;
- };
+ }
+ set_extra_default(opt->id, opt);
return 0;
}
@@ -134,7 +261,6 @@
return test_file_exists_res(dir, fname, path, &path_end);
}
-
static int create_check_file(const char *path)
{
File check_file= my_open(path, O_CREAT | O_WRONLY, MYF(MY_FAE | MY_WME));
@@ -150,19 +276,24 @@
return error;
}
-
+/* This must not be less than 512 */
+#define DEFAULTS_BUFSZ (FN_REFLEN + 64 + 1)
static int create_defaults_file(const char *path, const char *our_defaults_path)
{
+ int ret;
uint b_read;
File our_defaults_file, defaults_file;
- char buffer[512];
- char *buffer_end;
int failed_to_open_count= 0;
- int error;
+
+ DYNAMIC_STRING buf;
+ LIST *l;
+ extra_default_t d;
- /* check if the defaults file is needed at all */
- if (!opt_password)
- return 0;
+ if (init_dynamic_string(&buf, NULL, DEFAULTS_BUFSZ, FN_REFLEN))
+ {
+ ret = 1;
+ goto error;
+ }
retry_open:
defaults_file= my_open(path, O_BINARY | O_CREAT | O_WRONLY | O_EXCL,
@@ -170,67 +301,120 @@
if (defaults_file < 0)
{
- if (failed_to_open_count == 0)
+ if (failed_to_open_count > 0)
{
- remove(path);
- failed_to_open_count+= 1;
- goto retry_open;
+ ret = 1;
+ goto error;
}
else
- return 1;
+ {
+ my_delete(path, MYF(0));
+ ++failed_to_open_count;
+ goto retry_open;
+ }
}
- upgrade_defaults_created= 1;
if (our_defaults_path)
{
our_defaults_file= my_open(our_defaults_path, O_RDONLY,
MYF(MY_FAE | MY_WME));
if (our_defaults_file < 0)
- return 1;
+ {
+ ret = 1;
+ goto error;
+ }
do
{
- if (((b_read= my_read(our_defaults_file, buffer,
- sizeof(buffer), MYF(MY_WME))) == MY_FILE_ERROR) ||
- my_write(defaults_file, buffer, b_read, MYF(MY_FNABP | MY_WME)))
+ b_read= my_read(our_defaults_file, buf.str, 512, MYF(MY_WME));
+ if ((b_read == MY_FILE_ERROR)
+ || my_write(defaults_file, buf.str, b_read, MYF(MY_FNABP | MY_WME)))
{
- error= 1;
- goto close_return;
+ ret = 1;
+ my_close(our_defaults_file, MYF(MY_WME));
+ goto error;
}
- } while (b_read == sizeof(buffer));
+ } while (b_read == 512);
+ my_close(our_defaults_file, MYF(MY_WME));
}
- buffer_end= strnmov(buffer, "\n[client]", sizeof(buffer));
- if (opt_password)
- buffer_end= strxnmov(buffer_end, sizeof(buffer),
- "\npassword=", opt_password, NullS);
- error= my_write(defaults_file, buffer, (int) (buffer_end - buffer),
- MYF(MY_WME | MY_FNABP));
-close_return:
- return my_close(defaults_file, MYF(MY_WME)) || error;
+
+ dynstr_set(&buf, "\n[client]");
+ l = extra_defaults;
+ while (l)
+ {
+ int len;
+
+ d = l->data;
+ len = d->n_len + d->v_len + 1;
+ if (buf.length + len >= buf.max_length) /* just to avoid realloc() */
+ {
+ if (my_write(defaults_file, buf.str, buf.length, MYF(MY_FNABP | MY_WME)))
+ {
+ ret = 1;
+ goto error;
+ }
+ dynstr_set(&buf, NULL);
+ }
+ if (dynstr_append_mem(&buf, "\n", 1)
+ || dynstr_append_mem(&buf, d->name, d->n_len)
+ || (d->v_len && (dynstr_append_mem(&buf, "=", 1)
+ || dynstr_append_mem(&buf, d->value, d->v_len))))
+ {
+ ret = 1;
+ goto error;
+ }
+ my_delete((gptr)d, MYF(0));
+ l = l->next;
+ list_pop(extra_defaults); /* pop off the head, i.e. l */
+ }
+ if (my_write(defaults_file, buf.str, buf.length, MYF(MY_FNABP | MY_WME)))
+ {
+ ret = 1;
+ goto error;
+ }
+ /* everything's all right */
+ ret = 0;
+error:
+ dynstr_free(&buf);
+
+ if (defaults_file >= 0)
+ ret |= my_close(defaults_file, MYF(MY_WME));
+
+ if (ret)
+ my_delete(path, MYF(0));
+
+ return ret;
}
+#define SHELL_CMD_LEN (2*FN_REFLEN + 128 + 1)
int main(int argc, char **argv)
{
char bindir[FN_REFLEN];
char *bindir_end, *buf_end;
char datadir_buf[FN_REFLEN];
- char mysqlcheck_line[FN_REFLEN], *mysqlcheck_end;
+ char mysqlcheck_line[SHELL_CMD_LEN], *mysqlcheck_end;
char check_file_name[FN_REFLEN];
int check_file;
- char fix_priv_tables_cmd[FN_REFLEN], *fix_cmd_end;
+ char fix_priv_tables_cmd[SHELL_CMD_LEN], *fix_cmd_end;
char script_line[FN_REFLEN];
int error;
char *forced_defaults_file;
char *forced_extra_defaults;
char *defaults_group_suffix;
char upgrade_defaults_path[FN_REFLEN], *defaults_to_use= 0;
- char port_socket[100], *port_socket_end;
+ int upgrade_defaults_created = 0;
+ const struct my_option *opt;
MY_INIT(argv[0]);
#ifdef __NETWARE__
setscreenmode(SCR_AUTOCLOSE_ON_EXIT);
#endif
+ /* Check if we want to force the use a specific default file */
+ get_defaults_options(argc, argv,
+ &forced_defaults_file, &forced_extra_defaults,
+ &defaults_group_suffix);
+
load_defaults("my", load_default_groups, &argc, &argv);
if ((error= handle_options(&argc, &argv, my_long_options, get_one_option)))
@@ -239,22 +423,6 @@
if (tty_password)
opt_password= get_tty_password(NullS);
- /* Check if we want to force the use a specific default file */
- get_defaults_options(argc, argv,
- &forced_defaults_file, &forced_extra_defaults,
- &defaults_group_suffix);
-
- port_socket_end= port_socket;
- if (opt_mysql_port)
- port_socket_end= strxnmov(port_socket, sizeof(port_socket) - 1, " --port=",
- opt_mysql_port, NullS);
- if (opt_mysql_unix_port)
- port_socket_end= strxnmov(port_socket_end,
- sizeof(port_socket) -
- (int)(port_socket_end - port_socket) - 1,
- " --socket=", opt_mysql_unix_port, NullS);
- *port_socket_end= 0;
-
if (basedir)
{
bindir_end= strmake(bindir, basedir, sizeof(bindir)-1);
@@ -311,12 +479,17 @@
*strxnmov(upgrade_defaults_path, sizeof(upgrade_defaults_path)-1,
datadir, "/upgrade_defaults", NullS)= 0;
unpack_filename(upgrade_defaults_path, upgrade_defaults_path);
- if ((error=
- create_defaults_file(upgrade_defaults_path, forced_extra_defaults)))
- goto err_exit;
-
- defaults_to_use= upgrade_defaults_created ?
- upgrade_defaults_path : forced_extra_defaults;
+ if (extra_defaults)
+ {
+ error= create_defaults_file(upgrade_defaults_path, forced_extra_defaults);
+ if (error)
+ goto err_exit;
+
+ upgrade_defaults_created= 1;
+ defaults_to_use= upgrade_defaults_path;
+ }
+ else
+ defaults_to_use= forced_extra_defaults;
if (test_file_exists_res(datadir, "mysql_upgrade_info", check_file_name,
&buf_end) && !opt_force)
@@ -338,20 +511,21 @@
if (defaults_to_use)
{
mysqlcheck_end= strxnmov(mysqlcheck_end,
- sizeof(mysqlcheck_line) - (int) (mysqlcheck_end -
- mysqlcheck_line),
- " --defaults-extra-file=", defaults_to_use,NullS);
+ sizeof(mysqlcheck_line) -
+ (int) (mysqlcheck_end - mysqlcheck_line) - 1,
+ " --defaults-extra-file=", defaults_to_use,NullS);
}
mysqlcheck_end= strxnmov(mysqlcheck_end,
- sizeof(mysqlcheck_line) -
- (int) (mysqlcheck_end - mysqlcheck_line - 1),
- " --check-upgrade --all-databases --auto-repair --user=",
- user, port_socket, NullS);
+ sizeof(mysqlcheck_line) -
+ (int) (mysqlcheck_end - mysqlcheck_line) - 1,
+ " --check-upgrade --all-databases --auto-repair --user=",
+ user, NullS);
*mysqlcheck_end= 0;
if (opt_verbose)
printf("Running %s\n", mysqlcheck_line);
+
if ((error= system(mysqlcheck_line)))
{
printf("Error executing '%s'\n", mysqlcheck_line);
@@ -398,13 +572,14 @@
{
fix_cmd_end= strxnmov(fix_cmd_end,
sizeof(fix_priv_tables_cmd) -
- (int) (fix_cmd_end - fix_priv_tables_cmd - 1),
+ (int) (fix_cmd_end - fix_priv_tables_cmd) - 1,
" --defaults-extra-file=", defaults_to_use, NullS);
}
fix_cmd_end= strxnmov(fix_cmd_end,
- sizeof(fix_priv_tables_cmd) - (int) (fix_cmd_end -
- fix_priv_tables_cmd),
- " --user=", user, port_socket, " mysql < ", script_line, NullS);
+ sizeof(fix_priv_tables_cmd) -
+ (int) (fix_cmd_end - fix_priv_tables_cmd) - 1,
+ " --no-auto-rehash --batch"
+ " --user=", user, " mysql < ", script_line, NullS);
*fix_cmd_end= 0;
if ((error= system(fix_priv_tables_cmd)))
| Thread |
|---|
| • bk commit into 5.0 tree (ted:1.2339) BUG#20100 | Vladimir Shebordaev | 26 Oct |