From: Date: October 21 2006 2:12pm Subject: bk commit into 5.0 tree (ted:1.2324) BUG#20100 List-Archive: http://lists.mysql.com/commits/14109 X-Bug: 20100 Message-Id: <200610211212.k9LCCsSG028928@ted.mysql.internal> 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-21 16:12:46+04:00, ted@stripped +1 -0 BUG#20100 mysql_upgrade modified to 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-21 16:12:37+04:00, ted@stripped +163 -38 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-21 16:12:54 +04:00 +++ 1.8/client/mysql_upgrade.c 2006-10-21 16:12:54 +04:00 @@ -16,6 +16,7 @@ #include "client_priv.h" #include +#include #ifdef __WIN__ const char *mysqlcheck_name= "mysqlcheck.exe"; @@ -25,8 +26,16 @@ 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 = -1; static char *user= (char*) "root", *basedir= 0, *datadir= 0, *opt_password= 0; +static char *default_charset = (char *)MYSQL_DEFAULT_CHARSET_NAME, + *current_host = 0; +#ifdef HAVE_SMEM +static char *shared_memory_base_name=0; +#endif +static char *opt_protocol=0; static my_bool upgrade_defaults_created= 0; static my_string opt_mysql_port, opt_mysql_unix_port= 0; static char *default_dbug_option= (char*) "d:t:O,/tmp/comp_err.trace"; @@ -50,23 +59,44 @@ #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}, + {"default-character-set", OPT_DEFAULT_CHARSET, + "Set the default character set.", (gptr*) &default_charset, + (gptr*) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"force", 'f', "Continue even if we get an sql-error.", (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*) &charsets_dir, + (gptr*) &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_ALLOC, 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_ALLOC, 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 {"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} @@ -109,6 +139,29 @@ tty_password= 0; } break; +#include + 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) + { + char *cp; + + my_free(opt_protocol, MYF(MY_ALLOW_ZERO_PTR)); + opt_protocol = my_strdup(argument, MYF(MY_FAE)); + for (cp = opt_protocol; cp && *cp; cp++) + *cp = my_tolower(&my_charset_latin1,*cp); + } + else + { + fprintf(stderr, "Unknown option to protocol: %s\n", argument); + exit(1); + } + break; default:; }; return 0; @@ -153,16 +206,12 @@ 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[FN_REFLEN+64]; char *buffer_end; int failed_to_open_count= 0; - int error; - - /* check if the defaults file is needed at all */ - if (!opt_password) - return 0; retry_open: defaults_file= my_open(path, O_BINARY | O_CREAT | O_WRONLY | O_EXCL, @@ -170,42 +219,131 @@ if (defaults_file < 0) { - if (failed_to_open_count == 0) + if (failed_to_open_count > 0) + { + ret = 1; + goto error; + } + else { remove(path); - failed_to_open_count+= 1; + ++failed_to_open_count; goto retry_open; } - else - return 1; } - 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, buffer, + sizeof(buffer), MYF(MY_WME)); + if ((b_read == MY_FILE_ERROR) + || my_write(defaults_file, buffer, 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)); + my_close(our_defaults_file, MYF(MY_WME)); + + upgrade_defaults_created = 1; } buffer_end= strnmov(buffer, "\n[client]", sizeof(buffer)); +/* All options other than path names should fit into a signle buffer */ if (opt_password) + { + upgrade_defaults_created= 1; 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; + "\npassword=", opt_password, NullS); + } + if (opt_protocol) + { + buffer_end= strxnmov(buffer_end, sizeof(buffer), + "\nprotocol=", opt_protocol, NullS); + upgrade_defaults_created = 1; + } + if (current_host) + { + buffer_end= strxnmov(buffer_end, sizeof(buffer), + "\nhost=", current_host, NullS); + upgrade_defaults_created = 1; + } + if (opt_mysql_port) + { + upgrade_defaults_created= 1; + buffer_end= strxnmov(buffer_end, sizeof(buffer), + "\nport=", opt_mysql_port, NullS); + } + if (opt_compress >= 0) + { + buffer_end= strxnmov(buffer_end, sizeof(buffer), + "\ncompress=", !opt_compress ? "false" : "true", NullS); + upgrade_defaults_created = 1; + } + buffer_end=strxnmov(buffer_end, sizeof(buffer), + "\ndefault-character-set=", default_charset); +#ifdef HAVE_OPENSSL + if (opt_use_ssl) + { + buffer_end= strxnmov(buffer_end, sizeof(buffer), + "\nssl=", "true", NullS); + } +#ifdef MYSQL_CLIENT + if (opt_ssl_verify_server_cert) + { + buffer_end= strxnmov(buffer_end, sizeof(buffer), + "\nssl-veify-server-cert=", "true", NullS); + upgrade_defaults_created = 1; + } +#endif +#endif + if (upgrade_defaults_created) + if (my_write(defaults_file, buffer, (int) (buffer_end - buffer), + MYF(MY_WME | MY_FNABP))) + { + ret = 1; + goto error; + } +/* Options specifying paths can take entire buffer each */ +#define __WRITE_OPT_BUFFER( opt, name ) \ + if (opt) \ + { \ + buffer_end= strxnmov(buffer, sizeof(buffer), \ + "\n"name"=", opt, NullS); \ + if (my_write(defaults_file, buffer, (int) (buffer_end - buffer), \ + MYF(MY_WME | MY_FNABP))) \ + { \ + ret = 1; \ + goto error; \ + } \ + } + __WRITE_OPT_BUFFER(opt_mysql_unix_port, "socket"); +#ifdef HAVE_SMEM + __WRITE_OPT_BUFFER(shared_memory_base_name, "shared-memory-base-name"); +#endif +#ifdef HAVE_OPENSSL + __WRITE_OPT_BUFFER(opt_ssl_ca, "ssl-ca"); + __WRITE_OPT_BUFFER(opt_ssl_capath, "ssl-capath"); + __WRITE_OPT_BUFFER(opt_ssl_cert, "ssl-cert"); + __WRITE_OPT_BUFFER(opt_ssl_cipher, "ssl-cipher"); + __WRITE_OPT_BUFFER(opt_ssl_key, "ssl-key"); +#endif +#undef __WRITE_OPT_BUFFER + + ret = 0; +error: + if (defaults_file >= 0) + ret |= my_close(defaults_file, MYF(MY_WME)); + return ret; } @@ -224,7 +362,6 @@ 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; MY_INIT(argv[0]); #ifdef __NETWARE__ @@ -243,18 +380,6 @@ 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); @@ -347,7 +472,7 @@ sizeof(mysqlcheck_line) - (int) (mysqlcheck_end - mysqlcheck_line - 1), " --check-upgrade --all-databases --auto-repair --user=", - user, port_socket, NullS); + user, NullS); *mysqlcheck_end= 0; if (opt_verbose) @@ -404,7 +529,7 @@ 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); + " --user=", user, " mysql -AB < ", script_line, NullS); *fix_cmd_end= 0; if ((error= system(fix_priv_tables_cmd)))