List:Commits« Previous MessageNext Message »
From:Vladimir Shebordaev Date:October 23 2006 6:13am
Subject:bk commit into 5.0 tree (ted:1.2324) BUG#20100
View as plain text  
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-23 08:13:50+04:00, ted@stripped +1 -0
  BUG#20100 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-23 08:13:48+04:00, ted@stripped +192 -48
    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-23 08:13:55 +04:00
+++ 1.8/client/mysql_upgrade.c	2006-10-23 08:13:55 +04:00
@@ -16,6 +16,7 @@
 
 #include "client_priv.h"
 #include <my_dir.h>
+#include <sslopt-vars.h>
 
 #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 = 0;
 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,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*) &default_charset,
+   (gptr*) &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*) &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*) &current_host,
+   (gptr*) &current_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 <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}
@@ -109,6 +140,29 @@
       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)
+    {
+      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 +207,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 +220,147 @@
 
   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 the path names should fit into a single 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;
+  {
+    buffer_end= strxnmov(buffer_end, sizeof(buffer) 
+		    - (int)(buffer_end - buffer),
+                    "\npassword=", opt_password, NullS);
+    upgrade_defaults_created= 1;
+  }
+  if (opt_protocol) 
+  {
+    buffer_end= strxnmov(buffer_end, sizeof(buffer) 
+		    - (int)(buffer_end - buffer),
+		    "\nprotocol=", opt_protocol, NullS);
+    upgrade_defaults_created = 1;
+  }
+  if (current_host)
+  {
+    buffer_end= strxnmov(buffer_end, sizeof(buffer) 
+		    - (int)(buffer_end - buffer),
+		    "\nhost=", current_host, NullS);
+    upgrade_defaults_created = 1;
+  }
+  if (opt_mysql_port)
+  {
+    buffer_end= strxnmov(buffer_end, sizeof(buffer) 
+		    - (int)(buffer_end - buffer),
+                    "\nport=", opt_mysql_port, NullS);
+    upgrade_defaults_created= 1;
+  }
+  if (opt_compress)
+  {
+    buffer_end= strnmov(buffer_end, "\ncompress=true", 
+		    sizeof(buffer) - (int)(buffer_end - buffer)); 
+    upgrade_defaults_created = 1;
+  }
+  buffer_end=strxnmov(buffer_end, sizeof(buffer) 
+		    - (int)(buffer_end - buffer),
+		    "\ndefault-character-set=", default_charset, NullS);
+#ifdef HAVE_OPENSSL
+  if (opt_use_ssl)
+  {
+    buffer_end= strnmov(buffer_end, "\nssl=true", 
+		    sizeof(buffer) - (int)(buffer_end - buffer));
+    upgrade_defaults_created = 1;
+  }	 
+#ifdef MYSQL_CLIENT
+  if (opt_ssl_verify_server_cert)
+  {
+    buffer_end= strnmov(buffer_end, "\nssl-verify-server-cert=true", 
+		    sizeof(buffer) - (int)(buffer_end - buffer)); 
+    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;
+    }
+/* Each path name option can take at least FN_REFLEN bytes */ 
+#define MYSQL_UPGRADE_WRITE_OPT_BUFFER( opt, name ) \
+  if (opt) \
+  { \
+    buffer_end= strxnmov(upgrade_defaults_created ? buffer : buffer_end, \
+		    upgrade_defaults_created ? sizeof(buffer) \
+		    : sizeof(buffer) - (int)(buffer_end - buffer), \
+		    "\n"name"=", opt, NullS); \
+    if (my_write(defaults_file, buffer, (int) (buffer_end - buffer), \
+                  MYF(MY_WME | MY_FNABP))) \
+    { \
+       ret = 1; \
+       goto error; \
+    } \
+    upgrade_defaults_created = 1; \
+  }
+  MYSQL_UPGRADE_WRITE_OPT_BUFFER(opt_mysql_unix_port, "socket");
+#ifdef HAVE_SMEM
+  MYSQL_UPGRADE_WRITE_OPT_BUFFER(shared_memory_base_name, "shared-memory-base-name");
+#endif
+#ifdef HAVE_OPENSSL
+  MYSQL_UPGRADE_WRITE_OPT_BUFFER(opt_ssl_ca, "ssl-ca");
+  MYSQL_UPGRADE_WRITE_OPT_BUFFER(opt_ssl_capath, "ssl-capath");
+  MYSQL_UPGRADE_WRITE_OPT_BUFFER(opt_ssl_cert, "ssl-cert");
+  MYSQL_UPGRADE_WRITE_OPT_BUFFER(opt_ssl_cipher, "ssl-cipher");
+  MYSQL_UPGRADE_WRITE_OPT_BUFFER(opt_ssl_key, "ssl-key");
+#endif
+#undef MYSQL_UPGRADE_WRITE_OPT_BUFFER
+
+  ret = 0;
+error:
+  if (defaults_file >= 0)
+    ret |= my_close(defaults_file, MYF(MY_WME));
+  
+  if (ret) 
+    upgrade_defaults_created = 0;
+  
+  if (!upgrade_defaults_created)
+    remove(path);
+ 
+  return ret;
 }
 
 
@@ -224,7 +379,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 +397,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);
@@ -331,23 +473,24 @@
     {
       if (opt_verbose)
         puts("mysql_upgrade already done for this version");
-      goto fix_priv_tables;
+      if (!opt_force)
+      	goto fix_priv_tables;
     }
   }
 
   if (defaults_to_use)
   {
     mysqlcheck_end= strxnmov(mysqlcheck_end,
-                             sizeof(mysqlcheck_line) - (int) (mysqlcheck_end -
-                                                              mysqlcheck_line),
+                             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),
+                             (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)
@@ -394,17 +537,18 @@
     goto err_exit;
   }
 
+  fix_cmd_end= strxnmov(fix_cmd_end,
+           sizeof(fix_priv_tables_cmd) - (int) (fix_cmd_end -
+                                                fix_priv_tables_cmd) - 1,
+           " -AB --user=", user, " mysql < ", script_line, NullS);
+  
   if (defaults_to_use)
   {
     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);
   *fix_cmd_end= 0;
 
   if ((error= system(fix_priv_tables_cmd)))
Thread
bk commit into 5.0 tree (ted:1.2324) BUG#20100Vladimir Shebordaev23 Oct