List:Commits« Previous MessageNext Message »
From:Tatjana A Nuernberg Date:August 8 2007 3:35pm
Subject:bk commit into 5.0 tree (tnurnberg:1.2476) BUG#15327
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of tnurnberg. When tnurnberg 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, 2007-08-08 17:34:55+02:00, tnurnberg@stripped +16 -0
  Bug #15327: configure: --with-tcp-port option being partially ignored
  
  initialize default tcp port for client and server, like so:
  - if user configured --with-tcp-port, use that value as default
  - other assume "use a good default": search mysqld/tcp in
    /etc/services; if that doesn't exist, use factory default (3306)
  - environment variable MYSQL_TCP_PORT overrides this default
  - command-line option overrides all of the above

  client/client_priv.h@stripped, 2007-08-08 17:34:47+02:00, tnurnberg@stripped +11 -0
    Bug #15327: configure: --with-tcp-port option being partially ignored
    
    export mysql_client_port_init() and mysql_client_port_setup()

  client/mysql.cc@stripped, 2007-08-08 17:34:47+02:00, tnurnberg@stripped +192 -189
    Bug #15327: configure: --with-tcp-port option being partially ignored
    
    set up a sensible default value for TCP port before handling
    options so that "print variables" will show a value that's
    actually useful to the user

  client/mysql_upgrade.c@stripped, 2007-08-08 17:34:48+02:00, tnurnberg@stripped +1 -0
    Bug #15327: configure: --with-tcp-port option being partially ignored
    
    set up a sensible default value for TCP port before handling
    options so that "print variables" will show a value that's
    actually useful to the user

  client/mysqladmin.cc@stripped, 2007-08-08 17:34:48+02:00, tnurnberg@stripped +3 -0
    Bug #15327: configure: --with-tcp-port option being partially ignored
    
    set up a sensible default value for TCP port before handling
    options so that "print variables" will show a value that's
    actually useful to the user

  client/mysqlbinlog.cc@stripped, 2007-08-08 17:34:48+02:00, tnurnberg@stripped +3 -0
    Bug #15327: configure: --with-tcp-port option being partially ignored
    
    set up a sensible default value for TCP port before handling
    options so that "print variables" will show a value that's
    actually useful to the user

  client/mysqlcheck.c@stripped, 2007-08-08 17:34:48+02:00, tnurnberg@stripped +1 -0
    Bug #15327: configure: --with-tcp-port option being partially ignored
    
    set up a sensible default value for TCP port before handling
    options so that "print variables" will show a value that's
    actually useful to the user

  client/mysqldump.c@stripped, 2007-08-08 17:34:48+02:00, tnurnberg@stripped +1 -0
    Bug #15327: configure: --with-tcp-port option being partially ignored
    
    set up a sensible default value for TCP port before handling
    options so that "print variables" will show a value that's
    actually useful to the user

  client/mysqlimport.c@stripped, 2007-08-08 17:34:48+02:00, tnurnberg@stripped +1 -0
    Bug #15327: configure: --with-tcp-port option being partially ignored
    
    set up a sensible default value for TCP port before handling
    options so that "print variables" will show a value that's
    actually useful to the user

  client/mysqlshow.c@stripped, 2007-08-08 17:34:48+02:00, tnurnberg@stripped +103 -100
    Bug #15327: configure: --with-tcp-port option being partially ignored
    
    set up a sensible default value for TCP port before handling
    options so that "print variables" will show a value that's
    actually useful to the user

  client/mysqltest.c@stripped, 2007-08-08 17:34:48+02:00, tnurnberg@stripped +1 -0
    Bug #15327: configure: --with-tcp-port option being partially ignored
    
    set up a sensible default value for TCP port before handling
    options so that "print variables" will show a value that's
    actually useful to the user

  configure.in@stripped, 2007-08-08 17:34:47+02:00, tnurnberg@stripped +28 -1
    Bug #15327: configure: --with-tcp-port option being partially ignored
    
    If MYSQL_TCP_PORT defaulted in configure (factory default 3306
    at the time of this writing), set MYSQL_TCP_PORT to factory
    default, then clear factory default after. That way, we lose no
    information, and we can distinguish between "defaulted" and the
    pathological case "builder specifically configured a port that
    coincides with factory default." This can in theory happen if
    builder configures and builds several servers from a script
    (--with-tcp-port=3306, --with-tcp-port=3316, --with-tcp-port=3326).
    Not all that probably, but much preferable to having more "magic"
    happen in the server when we can solve this without any guesswork.

  include/my_getopt.h@stripped, 2007-08-08 17:34:49+02:00, tnurnberg@stripped +2 -0
    Bug #15327: configure: --with-tcp-port option being partially ignored
    
    export findopt() as my_getopt_find(); we need it in libmysql.c

  include/mysql_version.h.in@stripped, 2007-08-08 17:34:49+02:00, tnurnberg@stripped +1 -0
    Bug #15327: configure: --with-tcp-port option being partially ignored
    
    make factory default for TCP port available to C source

  libmysql/libmysql.c@stripped, 2007-08-08 17:34:49+02:00, tnurnberg@stripped +92 -25
    Bug #15327: configure: --with-tcp-port option being partially ignored
    
    add mysql_client_port_init() to default in a sensible sequence,
    and mysql_client_port_setup() to do same, and correct value in
    list of command line options/variables so "print variables" may
    print correct default values for TCP port

  mysys/my_getopt.c@stripped, 2007-08-08 17:34:49+02:00, tnurnberg@stripped +9 -11
    Bug #15327: configure: --with-tcp-port option being partially ignored
    
    export findopt() as my_getopt_find(); we need it in libmysql.c

  sql/mysqld.cc@stripped, 2007-08-08 17:34:49+02:00, tnurnberg@stripped +13 -0
    Bug #15327: configure: --with-tcp-port option being partially ignored
    
    initialize default tcp port for server, heeding --with-tcp-port
    build option

diff -Nrup a/client/client_priv.h b/client/client_priv.h
--- a/client/client_priv.h	2007-03-23 19:24:01 +01:00
+++ b/client/client_priv.h	2007-08-08 17:34:47 +02:00
@@ -53,3 +53,14 @@ enum options_client
   OPT_TZ_UTC, OPT_AUTO_CLOSE, OPT_SSL_VERIFY_SERVER_CERT,
   OPT_DEBUG_INFO, OPT_ERROR_LOG_FILE
 };
+
+/*
+  set up default client port from factory or ./configure'd default,
+  $MY_TCP_PORT etc. which can then be overridden with command-line
+  option.  mysql_client_port_init() just sets mysql_port(); most
+  clients will want to instead call mysql_client_port_setup() before
+  handling options as this also corrects the default value to the
+  above so that "print variables" will show a sensible value.
+*/
+int mysql_client_port_init(void);
+int mysql_client_port_setup(struct my_option *opt, const char *name);
diff -Nrup a/client/mysql.cc b/client/mysql.cc
--- a/client/mysql.cc	2007-04-23 16:21:59 +02:00
+++ b/client/mysql.cc	2007-08-08 17:34:47 +02:00
@@ -28,7 +28,9 @@
  *
  **/
 
+extern "C" {
 #include "client_priv.h"
+}
 #include <m_ctype.h>
 #include <stdarg.h>
 #include <my_dir.h>
@@ -305,6 +307,195 @@ static const char *load_default_groups[]
 static const char *server_default_groups[]=
 { "server", "embedded", "mysql_SERVER", 0 };
 
+static struct my_option my_long_options[] =
+{
+  {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
+   0, 0, 0, 0, 0},
+  {"help", 'I', "Synonym for -?", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
+   0, 0, 0, 0, 0},
+#ifdef __NETWARE__
+  {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
+   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+#endif
+  {"auto-rehash", OPT_AUTO_REHASH,
+   "Enable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time. Disable with --disable-auto-rehash.",
+   (gptr*) &opt_rehash, (gptr*) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
+   0, 0},
+  {"no-auto-rehash", 'A',
+   "No automatic rehashing. One has to use 'rehash' to get table and field completion. This gives a quicker start of mysql and disables rehashing on reconnect. WARNING: options deprecated; use --disable-auto-rehash instead.",
+   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"batch", 'B',
+   "Don't use history file. Disable interactive behavior. (Enables --silent)", 0, 0, 0, GET_NO_ARG, 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},
+  {"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},
+  {"compress", 'C', "Use compression in server/client protocol.",
+   (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
+   0, 0, 0},
+#ifdef DBUG_OFF
+  {"debug", '#', "This is a non-debug version. Catch this and exit",
+   0,0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
+#else
+  {"debug", '#', "Output debug log", (gptr*) &default_dbug_option,
+   (gptr*) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
+#endif
+  {"database", 'D', "Database to use.", (gptr*) &current_db,
+   (gptr*) &current_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+  {"delimiter", OPT_DELIMITER, "Delimiter to be used.", (gptr*) &delimiter_str,
+   (gptr*) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+  {"execute", 'e', "Execute command and quit. (Disables --force and history file)", 0,
+   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+  {"vertical", 'E', "Print the output of a query (rows) vertically.",
+   (gptr*) &vertical, (gptr*) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
+   0},
+  {"force", 'f', "Continue even if we get an sql error.",
+   (gptr*) &ignore_errors, (gptr*) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
+   0, 0, 0, 0},
+  {"named-commands", 'G',
+   "Enable named commands. Named commands mean this program's internal commands; see mysql> help . When enabled, the named commands can be used from any line of the query, otherwise only from the first line, before an enter. Disable with --disable-named-commands. This option is disabled by default.",
+   (gptr*) &named_cmds, (gptr*) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
+   0, 0},
+  {"no-named-commands", 'g',
+   "Named commands are disabled. Use \\* form only, or use named commands only in the beginning of a line ending with a semicolon (;) Since version 10.9 the client now starts with this option ENABLED by default! Disable with '-G'. Long format commands still work from the first line. WARNING: option deprecated; use --disable-named-commands instead.",
+   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"ignore-spaces", 'i', "Ignore space after function names.", 0, 0, 0,
+   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"local-infile", OPT_LOCAL_INFILE, "Enable/disable LOAD DATA LOCAL INFILE.",
+   (gptr*) &opt_local_infile,
+   (gptr*) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
+  {"no-beep", 'b', "Turn off beep on error.", (gptr*) &opt_nobeep,
+   (gptr*) &opt_nobeep, 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},
+  {"html", 'H', "Produce HTML output.", (gptr*) &opt_html, (gptr*) &opt_html,
+   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"xml", 'X', "Produce XML output", (gptr*) &opt_xml, (gptr*) &opt_xml, 0,
+   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"line-numbers", OPT_LINE_NUMBERS, "Write line numbers for errors.",
+   (gptr*) &line_numbers, (gptr*) &line_numbers, 0, GET_BOOL,
+   NO_ARG, 1, 0, 0, 0, 0, 0},  
+  {"skip-line-numbers", 'L', "Don't write line number for errors. WARNING: -L is deprecated, use long version of this option instead.", 0, 0, 0, GET_NO_ARG,
+   NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"unbuffered", 'n', "Flush buffer after each query.", (gptr*) &unbuffered,
+   (gptr*) &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"column-names", OPT_COLUMN_NAMES, "Write column names in results.",
+   (gptr*) &column_names, (gptr*) &column_names, 0, GET_BOOL,
+   NO_ARG, 1, 0, 0, 0, 0, 0},
+  {"skip-column-names", 'N',
+   "Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead.",
+   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"set-variable", 'O',
+   "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
+   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+  {"sigint-ignore", OPT_SIGINT_IGNORE, "Ignore SIGINT (CTRL-C)",
+   (gptr*) &opt_sigint_ignore,  (gptr*) &opt_sigint_ignore, 0, GET_BOOL,
+   NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"one-database", 'o',
+   "Only update the default database. This is useful for skipping updates to other database in the update log.",
+   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+#ifdef USE_POPEN
+  {"pager", OPT_PAGER,
+   "Pager to use to display results. If you don't supply an option the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode. Disable with --disable-pager. This option is disabled by default.",
+   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
+  {"no-pager", OPT_NOPAGER,
+   "Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead.",
+   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+#endif
+  {"password", 'p',
+   "Password to use when connecting to server. If password is not given it's asked from 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_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
+   0},
+  {"prompt", OPT_PROMPT, "Set the mysql prompt to this value.",
+   (gptr*) &current_prompt, (gptr*) &current_prompt, 0, GET_STR_ALLOC,
+   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},
+  {"quick", 'q',
+   "Don't cache result, print it row by row. This may slow down the server if the output is suspended. Doesn't use history file.",
+   (gptr*) &quick, (gptr*) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"raw", 'r', "Write fields without conversion. Used with --batch.",
+   (gptr*) &opt_raw_data, (gptr*) &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0,
+   0, 0, 0},
+  {"reconnect", OPT_RECONNECT, "Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default.", 
+   (gptr*) &opt_reconnect, (gptr*) &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
+  {"silent", 's', "Be more silent. Print results with a tab as separator, each row on new line.", 0, 0, 0, GET_NO_ARG, NO_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_ALLOC,
+   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+#include "sslopt-longopts.h"
+  {"table", 't', "Output in table format.", (gptr*) &output_tables,
+   (gptr*) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"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},
+  {"tee", OPT_TEE,
+   "Append everything into outfile. See interactive help (\\h) also. Does not work in batch mode. Disable with --disable-tee. This option is disabled by default.",
+   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+  {"no-tee", OPT_NOTEE, "Disable outfile. See interactive help (\\h) also. WARNING: option deprecated; use --disable-tee instead", 0, 0, 0, GET_NO_ARG,
+   NO_ARG, 0, 0, 0, 0, 0, 0},
+#ifndef DONT_ALLOW_USER_CHANGE
+  {"user", 'u', "User for login if not current user.", (gptr*) &current_user,
+   (gptr*) &current_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+#endif
+  {"safe-updates", 'U', "Only allow UPDATE and DELETE that uses keys.",
+   (gptr*) &safe_updates, (gptr*) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
+   0, 0, 0, 0},
+  {"i-am-a-dummy", 'U', "Synonym for option --safe-updates, -U.",
+   (gptr*) &safe_updates, (gptr*) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
+   0, 0, 0, 0},
+  {"verbose", 'v', "Write more. (-v -v -v gives the table output format).", 0,
+   0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"version", 'V', "Output version information and exit.", 0, 0, 0,
+   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"wait", 'w', "Wait and retry if connection is down.", 0, 0, 0, GET_NO_ARG,
+   NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"connect_timeout", OPT_CONNECT_TIMEOUT,
+   "Number of seconds before connection timeout.",
+   (gptr*) &opt_connect_timeout,
+   (gptr*) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 3600*12, 0,
+   0, 1},
+  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
+   "Max packet length to send to, or receive from server",
+   (gptr*) &opt_max_allowed_packet, (gptr*) &opt_max_allowed_packet, 0, GET_ULONG,
+   REQUIRED_ARG, 16 *1024L*1024L, 4096, (longlong) 2*1024L*1024L*1024L,
+   MALLOC_OVERHEAD, 1024, 0},
+  {"net_buffer_length", OPT_NET_BUFFER_LENGTH,
+   "Buffer for TCP/IP and socket communication",
+   (gptr*) &opt_net_buffer_length, (gptr*) &opt_net_buffer_length, 0, GET_ULONG,
+   REQUIRED_ARG, 16384, 1024, 512*1024*1024L, MALLOC_OVERHEAD, 1024, 0},
+  {"select_limit", OPT_SELECT_LIMIT,
+   "Automatic limit for SELECT when using --safe-updates",
+   (gptr*) &select_limit,
+   (gptr*) &select_limit, 0, GET_ULONG, REQUIRED_ARG, 1000L, 1, ~0L, 0, 1, 0},
+  {"max_join_size", OPT_MAX_JOIN_SIZE,
+   "Automatic limit for rows in a join when using --safe-updates",
+   (gptr*) &max_join_size,
+   (gptr*) &max_join_size, 0, GET_ULONG, REQUIRED_ARG, 1000000L, 1, ~0L, 0, 1,
+   0},
+  {"secure-auth", OPT_SECURE_AUTH, "Refuse client connecting to server if it"
+    " uses old (pre-4.1.1) protocol", (gptr*) &opt_secure_auth,
+    (gptr*) &opt_secure_auth, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"show-warnings", OPT_SHOW_WARNINGS, "Show warnings after every statement.",
+    (gptr*) &show_warnings, (gptr*) &show_warnings, 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}
+};
+
+
 #ifdef HAVE_READLINE
 /*
  HIST_ENTRY is defined for libedit, but not for the real readline
@@ -402,6 +593,7 @@ int main(int argc,char *argv[])
       close(stdout_fileno_copy);             /* Clean up dup(). */
   }
 
+  mysql_client_port_setup(my_long_options, "port");
   load_defaults("my",load_default_groups,&argc,&argv);
   defaults_argv=argv;
   if (get_options(argc, (char **) argv))
@@ -567,195 +759,6 @@ sig_handler mysql_end(int sig)
   my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
   exit(status.exit_status);
 }
-
-
-static struct my_option my_long_options[] =
-{
-  {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
-   0, 0, 0, 0, 0},
-  {"help", 'I', "Synonym for -?", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
-   0, 0, 0, 0, 0},
-#ifdef __NETWARE__
-  {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
-   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-#endif
-  {"auto-rehash", OPT_AUTO_REHASH,
-   "Enable automatic rehashing. One doesn't need to use 'rehash' to get table and field completion, but startup and reconnecting may take a longer time. Disable with --disable-auto-rehash.",
-   (gptr*) &opt_rehash, (gptr*) &opt_rehash, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0,
-   0, 0},
-  {"no-auto-rehash", 'A',
-   "No automatic rehashing. One has to use 'rehash' to get table and field completion. This gives a quicker start of mysql and disables rehashing on reconnect. WARNING: options deprecated; use --disable-auto-rehash instead.",
-   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"batch", 'B',
-   "Don't use history file. Disable interactive behavior. (Enables --silent)", 0, 0, 0, GET_NO_ARG, 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},
-  {"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},
-  {"compress", 'C', "Use compression in server/client protocol.",
-   (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
-   0, 0, 0},
-#ifdef DBUG_OFF
-  {"debug", '#', "This is a non-debug version. Catch this and exit",
-   0,0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
-#else
-  {"debug", '#', "Output debug log", (gptr*) &default_dbug_option,
-   (gptr*) &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
-#endif
-  {"database", 'D', "Database to use.", (gptr*) &current_db,
-   (gptr*) &current_db, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"delimiter", OPT_DELIMITER, "Delimiter to be used.", (gptr*) &delimiter_str,
-   (gptr*) &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"execute", 'e', "Execute command and quit. (Disables --force and history file)", 0,
-   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"vertical", 'E', "Print the output of a query (rows) vertically.",
-   (gptr*) &vertical, (gptr*) &vertical, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
-   0},
-  {"force", 'f', "Continue even if we get an sql error.",
-   (gptr*) &ignore_errors, (gptr*) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
-   0, 0, 0, 0},
-  {"named-commands", 'G',
-   "Enable named commands. Named commands mean this program's internal commands; see mysql> help . When enabled, the named commands can be used from any line of the query, otherwise only from the first line, before an enter. Disable with --disable-named-commands. This option is disabled by default.",
-   (gptr*) &named_cmds, (gptr*) &named_cmds, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
-   0, 0},
-  {"no-named-commands", 'g',
-   "Named commands are disabled. Use \\* form only, or use named commands only in the beginning of a line ending with a semicolon (;) Since version 10.9 the client now starts with this option ENABLED by default! Disable with '-G'. Long format commands still work from the first line. WARNING: option deprecated; use --disable-named-commands instead.",
-   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"ignore-spaces", 'i', "Ignore space after function names.", 0, 0, 0,
-   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"local-infile", OPT_LOCAL_INFILE, "Enable/disable LOAD DATA LOCAL INFILE.",
-   (gptr*) &opt_local_infile,
-   (gptr*) &opt_local_infile, 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0},
-  {"no-beep", 'b', "Turn off beep on error.", (gptr*) &opt_nobeep,
-   (gptr*) &opt_nobeep, 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},
-  {"html", 'H', "Produce HTML output.", (gptr*) &opt_html, (gptr*) &opt_html,
-   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"xml", 'X', "Produce XML output", (gptr*) &opt_xml, (gptr*) &opt_xml, 0,
-   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"line-numbers", OPT_LINE_NUMBERS, "Write line numbers for errors.",
-   (gptr*) &line_numbers, (gptr*) &line_numbers, 0, GET_BOOL,
-   NO_ARG, 1, 0, 0, 0, 0, 0},  
-  {"skip-line-numbers", 'L', "Don't write line number for errors. WARNING: -L is deprecated, use long version of this option instead.", 0, 0, 0, GET_NO_ARG,
-   NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"unbuffered", 'n', "Flush buffer after each query.", (gptr*) &unbuffered,
-   (gptr*) &unbuffered, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"column-names", OPT_COLUMN_NAMES, "Write column names in results.",
-   (gptr*) &column_names, (gptr*) &column_names, 0, GET_BOOL,
-   NO_ARG, 1, 0, 0, 0, 0, 0},
-  {"skip-column-names", 'N',
-   "Don't write column names in results. WARNING: -N is deprecated, use long version of this options instead.",
-   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"set-variable", 'O',
-   "Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
-   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"sigint-ignore", OPT_SIGINT_IGNORE, "Ignore SIGINT (CTRL-C)",
-   (gptr*) &opt_sigint_ignore,  (gptr*) &opt_sigint_ignore, 0, GET_BOOL,
-   NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"one-database", 'o',
-   "Only update the default database. This is useful for skipping updates to other database in the update log.",
-   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-#ifdef USE_POPEN
-  {"pager", OPT_PAGER,
-   "Pager to use to display results. If you don't supply an option the default pager is taken from your ENV variable PAGER. Valid pagers are less, more, cat [> filename], etc. See interactive help (\\h) also. This option does not work in batch mode. Disable with --disable-pager. This option is disabled by default.",
-   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
-  {"no-pager", OPT_NOPAGER,
-   "Disable pager and print to stdout. See interactive help (\\h) also. WARNING: option deprecated; use --disable-pager instead.",
-   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-#endif
-  {"password", 'p',
-   "Password to use when connecting to server. If password is not given it's asked from 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_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
-   0},
-  {"prompt", OPT_PROMPT, "Set the mysql prompt to this value.",
-   (gptr*) &current_prompt, (gptr*) &current_prompt, 0, GET_STR_ALLOC,
-   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},
-  {"quick", 'q',
-   "Don't cache result, print it row by row. This may slow down the server if the output is suspended. Doesn't use history file.",
-   (gptr*) &quick, (gptr*) &quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"raw", 'r', "Write fields without conversion. Used with --batch.",
-   (gptr*) &opt_raw_data, (gptr*) &opt_raw_data, 0, GET_BOOL, NO_ARG, 0, 0, 0,
-   0, 0, 0},
-  {"reconnect", OPT_RECONNECT, "Reconnect if the connection is lost. Disable with --disable-reconnect. This option is enabled by default.", 
-   (gptr*) &opt_reconnect, (gptr*) &opt_reconnect, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
-  {"silent", 's', "Be more silent. Print results with a tab as separator, each row on new line.", 0, 0, 0, GET_NO_ARG, NO_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_ALLOC,
-   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-#include "sslopt-longopts.h"
-  {"table", 't', "Output in table format.", (gptr*) &output_tables,
-   (gptr*) &output_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"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},
-  {"tee", OPT_TEE,
-   "Append everything into outfile. See interactive help (\\h) also. Does not work in batch mode. Disable with --disable-tee. This option is disabled by default.",
-   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-  {"no-tee", OPT_NOTEE, "Disable outfile. See interactive help (\\h) also. WARNING: option deprecated; use --disable-tee instead", 0, 0, 0, GET_NO_ARG,
-   NO_ARG, 0, 0, 0, 0, 0, 0},
-#ifndef DONT_ALLOW_USER_CHANGE
-  {"user", 'u', "User for login if not current user.", (gptr*) &current_user,
-   (gptr*) &current_user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-#endif
-  {"safe-updates", 'U', "Only allow UPDATE and DELETE that uses keys.",
-   (gptr*) &safe_updates, (gptr*) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
-   0, 0, 0, 0},
-  {"i-am-a-dummy", 'U', "Synonym for option --safe-updates, -U.",
-   (gptr*) &safe_updates, (gptr*) &safe_updates, 0, GET_BOOL, NO_ARG, 0, 0,
-   0, 0, 0, 0},
-  {"verbose", 'v', "Write more. (-v -v -v gives the table output format).", 0,
-   0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"version", 'V', "Output version information and exit.", 0, 0, 0,
-   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"wait", 'w', "Wait and retry if connection is down.", 0, 0, 0, GET_NO_ARG,
-   NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"connect_timeout", OPT_CONNECT_TIMEOUT,
-   "Number of seconds before connection timeout.",
-   (gptr*) &opt_connect_timeout,
-   (gptr*) &opt_connect_timeout, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 3600*12, 0,
-   0, 1},
-  {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET,
-   "Max packet length to send to, or receive from server",
-   (gptr*) &opt_max_allowed_packet, (gptr*) &opt_max_allowed_packet, 0, GET_ULONG,
-   REQUIRED_ARG, 16 *1024L*1024L, 4096, (longlong) 2*1024L*1024L*1024L,
-   MALLOC_OVERHEAD, 1024, 0},
-  {"net_buffer_length", OPT_NET_BUFFER_LENGTH,
-   "Buffer for TCP/IP and socket communication",
-   (gptr*) &opt_net_buffer_length, (gptr*) &opt_net_buffer_length, 0, GET_ULONG,
-   REQUIRED_ARG, 16384, 1024, 512*1024*1024L, MALLOC_OVERHEAD, 1024, 0},
-  {"select_limit", OPT_SELECT_LIMIT,
-   "Automatic limit for SELECT when using --safe-updates",
-   (gptr*) &select_limit,
-   (gptr*) &select_limit, 0, GET_ULONG, REQUIRED_ARG, 1000L, 1, ~0L, 0, 1, 0},
-  {"max_join_size", OPT_MAX_JOIN_SIZE,
-   "Automatic limit for rows in a join when using --safe-updates",
-   (gptr*) &max_join_size,
-   (gptr*) &max_join_size, 0, GET_ULONG, REQUIRED_ARG, 1000000L, 1, ~0L, 0, 1,
-   0},
-  {"secure-auth", OPT_SECURE_AUTH, "Refuse client connecting to server if it"
-    " uses old (pre-4.1.1) protocol", (gptr*) &opt_secure_auth,
-    (gptr*) &opt_secure_auth, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
-  {"show-warnings", OPT_SHOW_WARNINGS, "Show warnings after every statement.",
-    (gptr*) &show_warnings, (gptr*) &show_warnings, 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}
-};
 
 
 static void usage(int version)
diff -Nrup a/client/mysql_upgrade.c b/client/mysql_upgrade.c
--- a/client/mysql_upgrade.c	2007-04-23 13:27:54 +02:00
+++ b/client/mysql_upgrade.c	2007-08-08 17:34:48 +02:00
@@ -726,6 +726,7 @@ int main(int argc, char **argv)
   if (init_dynamic_string(&ds_args, "", 512, 256))
     die("Out of memory");
 
+  mysql_client_port_setup(my_long_options, "port");
   load_defaults("my", load_default_groups, &argc, &argv);
   defaults_argv= argv; /* Must be freed by 'free_defaults' */
 
diff -Nrup a/client/mysqladmin.cc b/client/mysqladmin.cc
--- a/client/mysqladmin.cc	2006-12-30 21:02:04 +01:00
+++ b/client/mysqladmin.cc	2007-08-08 17:34:48 +02:00
@@ -15,7 +15,9 @@
 
 /* maintaince of mysql databases */
 
+extern "C" {
 #include "client_priv.h"
+}
 #include <signal.h>
 #ifdef THREAD
 #include <my_pthread.h>				/* because of signal()	*/
@@ -308,6 +310,7 @@ int main(int argc,char *argv[])
 
   MY_INIT(argv[0]);
   mysql_init(&mysql);
+  mysql_client_port_setup(my_long_options, "port");
   load_defaults("my",load_default_groups,&argc,&argv);
   save_argv = argv;				/* Save for free_defaults */
   if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
diff -Nrup a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
--- a/client/mysqlbinlog.cc	2007-04-10 15:26:33 +02:00
+++ b/client/mysqlbinlog.cc	2007-08-08 17:34:48 +02:00
@@ -30,7 +30,9 @@
 
 #define MYSQL_CLIENT
 #undef MYSQL_SERVER
+extern "C" {
 #include "client_priv.h"
+}
 #include <my_time.h>
 /* That one is necessary for defines of OPTION_NO_FOREIGN_KEY_CHECKS etc */
 #include "mysql_priv.h" 
@@ -1440,6 +1442,7 @@ int main(int argc, char** argv)
 
   init_time(); // for time functions
 
+  mysql_client_port_setup(my_long_options, "port");
   parse_args(&argc, (char***)&argv);
   defaults_argv=argv;
 
diff -Nrup a/client/mysqlcheck.c b/client/mysqlcheck.c
--- a/client/mysqlcheck.c	2006-12-23 20:04:04 +01:00
+++ b/client/mysqlcheck.c	2007-08-08 17:34:48 +02:00
@@ -702,6 +702,7 @@ int main(int argc, char **argv)
   /*
   ** Check out the args
   */
+  mysql_client_port_setup(my_long_options, "port");
   if (get_options(&argc, &argv))
   {
     my_end(0);
diff -Nrup a/client/mysqldump.c b/client/mysqldump.c
--- a/client/mysqldump.c	2007-06-28 11:23:58 +02:00
+++ b/client/mysqldump.c	2007-08-08 17:34:48 +02:00
@@ -3838,6 +3838,7 @@ int main(int argc, char **argv)
   default_charset= (char *)mysql_universal_client_charset;
   bzero((char*) &ignore_table, sizeof(ignore_table));
 
+  mysql_client_port_setup(my_long_options, "port");
   exit_code= get_options(&argc, &argv);
   if (exit_code)
   {
diff -Nrup a/client/mysqlimport.c b/client/mysqlimport.c
--- a/client/mysqlimport.c	2006-12-30 21:02:04 +01:00
+++ b/client/mysqlimport.c	2007-08-08 17:34:48 +02:00
@@ -506,6 +506,7 @@ int main(int argc, char **argv)
   MYSQL *sock=0;
   MY_INIT(argv[0]);
 
+  mysql_client_port_setup(my_long_options, "port");
   load_defaults("my",load_default_groups,&argc,&argv);
   /* argv is changed in the program */
   argv_to_free= argv;
diff -Nrup a/client/mysqlshow.c b/client/mysqlshow.c
--- a/client/mysqlshow.c	2006-12-30 21:02:04 +01:00
+++ b/client/mysqlshow.c	2007-08-08 17:34:48 +02:00
@@ -54,106 +54,6 @@ static void print_res_row(MYSQL_RES *res
 static const char *load_default_groups[]= { "mysqlshow","client",0 };
 static my_string opt_mysql_unix_port=0;
 
-int main(int argc, char **argv)
-{
-  int error;
-  my_bool first_argument_uses_wildcards=0;
-  char *wild;
-  MYSQL mysql;
-  MY_INIT(argv[0]);
-  load_defaults("my",load_default_groups,&argc,&argv);
-  get_options(&argc,&argv);
-
-  wild=0;
-  if (argc)
-  {
-    char *pos= argv[argc-1], *to;
-    for (to= pos ; *pos ; pos++, to++)
-    {
-      switch (*pos) {
-      case '*':
-	*pos= '%';
-	first_argument_uses_wildcards= 1;
-	break;
-      case '?':
-	*pos= '_';
-	first_argument_uses_wildcards= 1;
-	break;
-      case '%':
-      case '_':
-	first_argument_uses_wildcards= 1;
-	break;
-      case '\\':
-	pos++;
-      default: break;
-      }
-      *to= *pos;
-    }    
-    *to= *pos; /* just to copy a '\0'  if '\\' was used */
-  }
-  if (first_argument_uses_wildcards)
-    wild= argv[--argc];
-  else if (argc == 3)			/* We only want one field */
-    wild= argv[--argc];
-
-  if (argc > 2)
-  {
-    fprintf(stderr,"%s: Too many arguments\n",my_progname);
-    exit(1);
-  }
-  mysql_init(&mysql);
-  if (opt_compress)
-    mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS);
-#ifdef HAVE_OPENSSL
-  if (opt_use_ssl)
-    mysql_ssl_set(&mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
-		  opt_ssl_capath, opt_ssl_cipher);
-  mysql_options(&mysql,MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
-                (char*)&opt_ssl_verify_server_cert);
-#endif
-  if (opt_protocol)
-    mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
-#ifdef HAVE_SMEM
-  if (shared_memory_base_name)
-    mysql_options(&mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
-#endif
-  mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset);
-
-  if (!(mysql_real_connect(&mysql,host,user,opt_password,
-			   (first_argument_uses_wildcards) ? "" : argv[0],opt_mysql_port,opt_mysql_unix_port,
-			   0)))
-  {
-    fprintf(stderr,"%s: %s\n",my_progname,mysql_error(&mysql));
-    exit(1);
-  }
-  mysql.reconnect= 1;
-
-  switch (argc)
-  {
-  case 0:  error=list_dbs(&mysql,wild); break;
-  case 1:
-    if (opt_status)
-      error=list_table_status(&mysql,argv[0],wild);
-    else
-      error=list_tables(&mysql,argv[0],wild);
-    break;
-  default:
-    if (opt_status && ! wild)
-      error=list_table_status(&mysql,argv[0],argv[1]);
-    else
-      error=list_fields(&mysql,argv[0],argv[1],wild);
-    break;
-  }
-  mysql_close(&mysql);			/* Close & free connection */
-  if (opt_password)
-    my_free(opt_password,MYF(0));
-#ifdef HAVE_SMEM
-  my_free(shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
-#endif
-  my_end(0);
-  exit(error ? 1 : 0);
-  return 0;				/* No compiler warnings */
-}
 
 static struct my_option my_long_options[] =
 {
@@ -884,4 +784,107 @@ static void print_res_row(MYSQL_RES *res
     printf(" %-*s|",length+1,cur[i] ? (char*) cur[i] : "");
   }
   putchar('\n');
+}
+
+
+int main(int argc, char **argv)
+{
+  int error;
+  my_bool first_argument_uses_wildcards=0;
+  char *wild;
+  MYSQL mysql;
+  MY_INIT(argv[0]);
+  mysql_client_port_setup(my_long_options, "port");
+  load_defaults("my",load_default_groups,&argc,&argv);
+  get_options(&argc,&argv);
+
+  wild=0;
+  if (argc)
+  {
+    char *pos= argv[argc-1], *to;
+    for (to= pos ; *pos ; pos++, to++)
+    {
+      switch (*pos) {
+      case '*':
+	*pos= '%';
+	first_argument_uses_wildcards= 1;
+	break;
+      case '?':
+	*pos= '_';
+	first_argument_uses_wildcards= 1;
+	break;
+      case '%':
+      case '_':
+	first_argument_uses_wildcards= 1;
+	break;
+      case '\\':
+	pos++;
+      default: break;
+      }
+      *to= *pos;
+    }    
+    *to= *pos; /* just to copy a '\0'  if '\\' was used */
+  }
+  if (first_argument_uses_wildcards)
+    wild= argv[--argc];
+  else if (argc == 3)			/* We only want one field */
+    wild= argv[--argc];
+
+  if (argc > 2)
+  {
+    fprintf(stderr,"%s: Too many arguments\n",my_progname);
+    exit(1);
+  }
+  mysql_init(&mysql);
+  if (opt_compress)
+    mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS);
+#ifdef HAVE_OPENSSL
+  if (opt_use_ssl)
+    mysql_ssl_set(&mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
+		  opt_ssl_capath, opt_ssl_cipher);
+  mysql_options(&mysql,MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
+                (char*)&opt_ssl_verify_server_cert);
+#endif
+  if (opt_protocol)
+    mysql_options(&mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
+#ifdef HAVE_SMEM
+  if (shared_memory_base_name)
+    mysql_options(&mysql,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
+#endif
+  mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, default_charset);
+
+  if (!(mysql_real_connect(&mysql,host,user,opt_password,
+			   (first_argument_uses_wildcards) ? "" : argv[0],opt_mysql_port,opt_mysql_unix_port,
+			   0)))
+  {
+    fprintf(stderr,"%s: %s\n",my_progname,mysql_error(&mysql));
+    exit(1);
+  }
+  mysql.reconnect= 1;
+
+  switch (argc)
+  {
+  case 0:  error=list_dbs(&mysql,wild); break;
+  case 1:
+    if (opt_status)
+      error=list_table_status(&mysql,argv[0],wild);
+    else
+      error=list_tables(&mysql,argv[0],wild);
+    break;
+  default:
+    if (opt_status && ! wild)
+      error=list_table_status(&mysql,argv[0],argv[1]);
+    else
+      error=list_fields(&mysql,argv[0],argv[1],wild);
+    break;
+  }
+  mysql_close(&mysql);			/* Close & free connection */
+  if (opt_password)
+    my_free(opt_password,MYF(0));
+#ifdef HAVE_SMEM
+  my_free(shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
+#endif
+  my_end(0);
+  exit(error ? 1 : 0);
+  return 0;				/* No compiler warnings */
 }
diff -Nrup a/client/mysqltest.c b/client/mysqltest.c
--- a/client/mysqltest.c	2007-07-13 07:55:02 +02:00
+++ b/client/mysqltest.c	2007-08-08 17:34:48 +02:00
@@ -4723,6 +4723,7 @@ get_one_option(int optid, const struct m
 
 int parse_args(int argc, char **argv)
 {
+  mysql_client_port_setup(my_long_options, "port");
   load_defaults("my",load_default_groups,&argc,&argv);
   default_argv= argv;
 
diff -Nrup a/configure.in b/configure.in
--- a/configure.in	2007-07-16 12:42:05 +02:00
+++ b/configure.in	2007-08-08 17:34:47 +02:00
@@ -710,7 +710,34 @@ AC_ARG_WITH(tcp-port,
     [  --with-tcp-port=port-number
                           Which port to use for MySQL services (default 3306)],
     [ MYSQL_TCP_PORT=$withval ],
-    [ MYSQL_TCP_PORT=$MYSQL_TCP_PORT_DEFAULT ]
+    [ MYSQL_TCP_PORT=$MYSQL_TCP_PORT_DEFAULT
+      # if we actually defaulted (as opposed to the pathological case of
+      # --with-tcp-port=<MYSQL_TCP_PORT_DEFAULT> which might in theory
+      # happen if whole batch of servers was built from a script), set
+      # the default to zero to indicate that; we don't lose information
+      # that way, because 0 obviously indicates that we can get the
+      # default value from MYSQL_TCP_PORT. this seems really evil, but
+      # testing for MYSQL_TCP_PORT==MYSQL_TCP_PORT_DEFAULT would make a
+      # a port of MYSQL_TCP_PORT_DEFAULT magic even if the builder did not
+      # intend it to mean "use the default, in fact, look up a good default
+      # from /etc/services if you can", but really, really meant 3306 when
+      # they passed in 3306. When they pass in a specific value, let them
+      # have it; don't second guess user and think we know better, this will
+      # just make people cross.  this makes the the logic work like this
+      # (which is complicated enough):
+      #
+      # - if a port was set during build, use that as a default.
+      #
+      # - otherwise, try to look up a port in /etc/services; if that fails,
+      #   use MYSQL_TCP_PORT_DEFAULT (at the time of this writing 3306)
+      #
+      # - allow the MYSQL_TCP_PORT environment variable to override that.
+      #
+      # - allow command-line parameters to override all of the above.
+      #
+      # the top-most MYSQL_TCP_PORT_DEFAULT is read from win/configure.js,
+      # so don't mess with that.
+      MYSQL_TCP_PORT_DEFAULT=0 ]
     )
 AC_SUBST(MYSQL_TCP_PORT)
 # We might want to document the assigned port in the manual.
diff -Nrup a/include/my_getopt.h b/include/my_getopt.h
--- a/include/my_getopt.h	2006-12-30 21:02:04 +01:00
+++ b/include/my_getopt.h	2007-08-08 17:34:49 +02:00
@@ -60,6 +60,8 @@ extern char *disabled_my_option;
 extern my_bool my_getopt_print_errors;
 extern my_error_reporter my_getopt_error_reporter;
 
+extern int my_getopt_find(const char *optpat, uint length,
+                          const struct my_option **opt_res, char **ffname);
 extern int handle_options (int *argc, char ***argv, 
 			   const struct my_option *longopts, my_get_one_option);
 extern void my_print_help(const struct my_option *options);
diff -Nrup a/include/mysql_version.h.in b/include/mysql_version.h.in
--- a/include/mysql_version.h.in	2004-05-25 01:32:12 +02:00
+++ b/include/mysql_version.h.in	2007-08-08 17:34:49 +02:00
@@ -15,6 +15,7 @@
 #define FRM_VER				@DOT_FRM_VERSION@
 #define MYSQL_VERSION_ID		@MYSQL_VERSION_ID@
 #define MYSQL_PORT			@MYSQL_TCP_PORT@
+#define MYSQL_PORT_DEFAULT		@MYSQL_TCP_PORT_DEFAULT@
 #define MYSQL_UNIX_ADDR			"@MYSQL_UNIX_ADDR@"
 #define MYSQL_CONFIG_NAME		"my"
 #define MYSQL_COMPILATION_COMMENT	"@COMPILATION_COMMENT@"
diff -Nrup a/libmysql/libmysql.c b/libmysql/libmysql.c
--- a/libmysql/libmysql.c	2007-07-06 08:34:06 +02:00
+++ b/libmysql/libmysql.c	2007-08-08 17:34:49 +02:00
@@ -19,6 +19,7 @@
 
 #include <my_global.h>
 #include <my_sys.h>
+#include <my_getopt.h>
 #include <my_time.h>
 #include <mysys_err.h>
 #include <m_string.h>
@@ -97,6 +98,96 @@ static my_bool org_my_init_done= 0;
 
 
 /*
+  Initialize the MySQL client port address
+
+  SYNOPSIS
+    mysql_client_port_init()
+
+  NOTES
+    Called by mysql_server_init() (which may be wrapped in mysql_init()).
+    If none of the above is called before handling command-line options,
+    mysql_client_port_init() may be called directly before handling the
+    command-line, so "print variables" will render correct values.
+    May be called repeatedly.
+
+  RETURN
+    0  ok
+*/
+
+int mysql_client_port_init(void)
+{
+  if (!mysql_port)
+  {
+    mysql_port = MYSQL_PORT;
+#ifndef MSDOS
+    {
+      struct servent *serv_ptr;
+      char *env;
+
+      /*
+        if builder specifically requested a default port, use that
+        (even if it coincides with our factory default).
+        only if they didn't do we check /etc/services (and, failing
+        on that, fall back to the factory default of 3306).
+        either default can be overridden by the environment variable
+        MYSQL_TCP_PORT, which in turn can be overridden with command
+        line options.
+      */
+
+#if MYSQL_PORT_DEFAULT == 0
+      if ((serv_ptr = getservbyname("mysql", "tcp")))
+        mysql_port = (uint) ntohs((ushort) serv_ptr->s_port);
+#endif
+      if ((env = getenv("MYSQL_TCP_PORT")))
+        mysql_port =(uint) atoi(env);
+    }
+#endif
+  }
+  if (!mysql_unix_port)
+  {
+    char *env;
+#ifdef __WIN__
+    mysql_unix_port = (char*) MYSQL_NAMEDPIPE;
+#else
+    mysql_unix_port = (char*) MYSQL_UNIX_ADDR;
+#endif
+    if ((env = getenv("MYSQL_UNIX_PORT")))
+      mysql_unix_port = env;
+  }
+  return 0;
+}
+
+
+/*
+  Initialize the MySQL client port address
+
+  SYNOPSIS
+    mysql_client_port_setup()
+    opt                 struct containing client's options
+    name                name of option that contains port ("port")
+
+  NOTES
+    Call before handling the command-line, so "print variables" will
+    render correct values.
+
+  RETURN
+   -1           Error
+   >=0          default port (usually > 0); can be overridden on command-line
+*/
+
+int mysql_client_port_setup(struct my_option *opt, const char *name)
+{
+  char *dummy;
+
+  mysql_client_port_init();
+  if (my_getopt_find(name, strlen(name),
+                     (const struct my_option **) &opt, &dummy)>0)
+    return opt->def_value= mysql_port;
+  return -1;
+}
+
+
+/*
   Initialize the MySQL client library
 
   SYNOPSIS
@@ -126,31 +217,7 @@ int STDCALL mysql_server_init(int argc _
     if (my_init())				/* Will init threads */
       return 1;
     init_client_errs();
-    if (!mysql_port)
-    {
-      mysql_port = MYSQL_PORT;
-#ifndef MSDOS
-      {
-	struct servent *serv_ptr;
-	char	*env;
-	if ((serv_ptr = getservbyname("mysql", "tcp")))
-	  mysql_port = (uint) ntohs((ushort) serv_ptr->s_port);
-	if ((env = getenv("MYSQL_TCP_PORT")))
-	  mysql_port =(uint) atoi(env);
-      }
-#endif
-    }
-    if (!mysql_unix_port)
-    {
-      char *env;
-#ifdef __WIN__
-      mysql_unix_port = (char*) MYSQL_NAMEDPIPE;
-#else
-      mysql_unix_port = (char*) MYSQL_UNIX_ADDR;
-#endif
-      if ((env = getenv("MYSQL_UNIX_PORT")))
-	mysql_unix_port = env;
-    }
+    mysql_client_port_init();
     mysql_debug(NullS);
 #if defined(SIGPIPE) && !defined(__WIN__) && !defined(__NETWARE__)
     (void) signal(SIGPIPE, SIG_IGN);
diff -Nrup a/mysys/my_getopt.c b/mysys/my_getopt.c
--- a/mysys/my_getopt.c	2007-02-22 15:59:54 +01:00
+++ b/mysys/my_getopt.c	2007-08-08 17:34:49 +02:00
@@ -23,9 +23,6 @@
 static void default_reporter(enum loglevel level, const char *format, ...);
 my_error_reporter my_getopt_error_reporter= &default_reporter;
 
-static int findopt(char *optpat, uint length,
-		   const struct my_option **opt_res,
-		   char **ffname);
 my_bool getopt_compare_strings(const char *s,
 			       const char *t,
 			       uint length);
@@ -196,7 +193,7 @@ int handle_options(int *argc, char ***ar
 	*/
         LINT_INIT(prev_found);
 	optp= longopts;
-	if (!(opt_found= findopt(opt_str, length, &optp, &prev_found)))
+	if (!(opt_found= my_getopt_find(opt_str, length, &optp, &prev_found)))
 	{
 	  /*
 	    Didn't find any matching option. Let's see if someone called
@@ -219,9 +216,10 @@ int handle_options(int *argc, char ***ar
 		opt_str+= (special_opt_prefix_lengths[i] + 1);
 		if (i == OPT_LOOSE)
 		  option_is_loose= 1;
-		if ((opt_found= findopt(opt_str, length -
-					(special_opt_prefix_lengths[i] + 1),
-					&optp, &prev_found)))
+		if ((opt_found= my_getopt_find(opt_str, length -
+                                               (special_opt_prefix_lengths[i]
+                                                + 1),
+                                               &optp, &prev_found)))
 		{
 		  if (opt_found > 1)
 		  {
@@ -610,7 +608,7 @@ static int setval(const struct my_option
   Find option
 
   SYNOPSIS
-    findopt()
+    my_getopt_find()
     optpat	Prefix of option to find (with - or _)
     length	Length of optpat
     opt_res	Options
@@ -628,9 +626,9 @@ static int setval(const struct my_option
         ffname points to first matching option
 */
 
-static int findopt(char *optpat, uint length,
-		   const struct my_option **opt_res,
-		   char **ffname)
+int my_getopt_find(const char *optpat, uint length,
+                   const struct my_option **opt_res,
+                   char **ffname)
 {
   uint count;
   struct my_option *opt= (struct my_option *) *opt_res;
diff -Nrup a/sql/mysqld.cc b/sql/mysqld.cc
--- a/sql/mysqld.cc	2007-07-05 12:34:10 +02:00
+++ b/sql/mysqld.cc	2007-08-08 17:34:49 +02:00
@@ -1300,8 +1300,21 @@ static void set_ports()
   {					// Get port if not from commandline
     struct  servent *serv_ptr;
     mysqld_port= MYSQL_PORT;
+
+    /*
+      if builder specifically requested a default port, use that
+      (even if it coincides with our factory default).
+      only if they didn't do we check /etc/services (and, failing
+      on that, fall back to the factory default of 3306).
+      either default can be overridden by the environment variable
+      MYSQL_TCP_PORT, which in turn can be overridden with command
+      line options.
+    */
+
+#if MYSQL_PORT_DEFAULT == 0
     if ((serv_ptr= getservbyname("mysql", "tcp")))
       mysqld_port= ntohs((u_short) serv_ptr->s_port); /* purecov: inspected */
+#endif
     if ((env = getenv("MYSQL_TCP_PORT")))
       mysqld_port= (uint) atoi(env);		/* purecov: inspected */
   }
Thread
bk commit into 5.0 tree (tnurnberg:1.2476) BUG#15327Tatjana A Nuernberg8 Aug
  • Re: bk commit into 5.0 tree (tnurnberg:1.2476) BUG#15327Sergei Golubchik9 Aug
Re: bk commit into 5.0 tree (tnurnberg:1.2476) BUG#15327Timothy Smith9 Aug
  • Re: bk commit into 5.0 tree (tnurnberg:1.2476) BUG#15327Sergei Golubchik10 Aug
Re: bk commit into 5.0 tree (tnurnberg:1.2476) BUG#15327Timothy Smith9 Aug