summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/mysqlbinlog.cc200
-rw-r--r--client/mysqlmanager-pwgen.c74
-rw-r--r--client/mysqlmanagerc.c126
-rw-r--r--client/mysqltest.c344
-rw-r--r--client/thread_test.c168
5 files changed, 421 insertions, 491 deletions
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
index 2591897b8de..a213f328cb5 100644
--- a/client/mysqlbinlog.cc
+++ b/client/mysqlbinlog.cc
@@ -19,6 +19,7 @@
#include "client_priv.h"
#include <time.h>
#include "log_event.h"
+#include <my_getopt.h>
#define PROBE_HEADER_LEN (4+EVENT_LEN_OFFSET+4)
@@ -38,26 +39,6 @@ static FILE *result_file;
static const char* default_dbug_option = "d:t:o,/tmp/mysqlbinlog.trace";
#endif
-static struct option long_options[] =
-{
-#ifndef DBUG_OFF
- {"debug", optional_argument, 0, '#'},
-#endif
- {"database", required_argument, 0, 'd'},
- {"help", no_argument, 0, '?'},
- {"host", required_argument, 0, 'h'},
- {"offset", required_argument, 0, 'o'},
- {"password", required_argument, 0, 'p'},
- {"port", required_argument, 0, 'P'},
- {"position", required_argument, 0, 'j'},
- {"result-file", required_argument, 0, 'r'},
- {"short-form", no_argument, 0, 's'},
- {"table", required_argument, 0, 't'},
- {"user", required_argument, 0, 'u'},
- {"version", no_argument, 0, 'V'},
- {0,0,0,0}
-};
-
void sql_print_error(const char *format,...);
static bool one_database = 0;
@@ -82,6 +63,44 @@ static void dump_remote_table(NET* net, const char* db, const char* table);
static void die(const char* fmt, ...);
static MYSQL* safe_connect();
+static struct my_option my_long_options[] =
+{
+#ifndef DBUG_OFF
+ {"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', "List entries for just this database (local log only)",
+ (gptr*) &database, (gptr*) &database, 0, GET_STR_ALLOC, REQUIRED_ARG,
+ 0, 0, 0, 0, 0, 0},
+ {"help", '?', "Display this help and exit",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"host", 'h', "Get the binlog from server", (gptr*) &host, (gptr*) &host,
+ 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"offset", 'o', "Skip the first N entries", (gptr*) &offset, (gptr*) &offset,
+ 0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"password", 'p', "Password to connect to remote server",
+ 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"port", 'P', "Use port to connect to the remote server",
+ (gptr*) &port, (gptr*) &port, 0, GET_INT, REQUIRED_ARG, MYSQL_PORT, 0, 0,
+ 0, 0, 0},
+ {"position", 'j', "Start reading the binlog at position N",
+ (gptr*) &position, (gptr*) &position, 0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0,
+ 0, 0},
+ {"result-file", 'r', "Direct output to a given file", 0, 0, 0, GET_STR,
+ REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"short-form", 's', "Just show the queries, no extra info",
+ (gptr*) &short_form, (gptr*) &short_form, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
+ 0, 0},
+ {"table", 't', "Get raw table dump using COM_TABLE_DUMB", (gptr*) &table,
+ (gptr*) &table, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"user", 'u', "Connect to the remote server as username",
+ (gptr*) &user, (gptr*) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0,
+ 0, 0},
+ {"version", 'V', "Print version and exit.", 0, 0, 0, GET_NO_ARG, 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}
+};
+
void sql_print_error(const char *format,...)
{
@@ -106,7 +125,7 @@ static void die(const char* fmt, ...)
static void print_version()
{
- printf("%s Ver 1.9 for %s at %s\n",my_progname,SYSTEM_TYPE, MACHINE_TYPE);
+ printf("%s Ver 2.0 for %s at %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE);
}
@@ -120,26 +139,10 @@ and you are welcome to modify and redistribute it under the GPL license\n");
printf("\
Dumps a MySQL binary log in a format usable for viewing or for pipeing to\n\
the mysql command line client\n\n");
- printf("Usage: %s [options] log-files\n",my_progname);
- puts("Options:");
-#ifndef DBUG_OFF
- printf("-#, --debug[=...] Output debug log. (%s)\n",
- default_dbug_option);
-#endif
- printf("\
--?, --help Display this help and exit\n\
--s, --short-form Just show the queries, no extra info\n\
--o, --offset=N Skip the first N entries\n\
--d, --database=database List entries for just this database (local log only)\n\
--h, --host=server Get the binlog from server\n\
--P, --port=port Use port to connect to the remote server\n\
--u, --user=username Connect to the remote server as username\n\
--p, --password=password Password to connect to remote server\n\
--r, --result-file=file Direct output to a given file\n\
--j, --position=N Start reading the binlog at position N\n\
--t, --table=name Get raw table dump using COM_TABLE_DUMB\n\
--V, --version Print version and exit.\n\
-");
+ printf("Usage: %s [options] log-files\n", my_progname);
+ my_print_help(my_long_options);
+ putchar('\n');
+ my_print_variables(my_long_options);
}
static void dump_remote_file(NET* net, const char* fname)
@@ -172,82 +175,61 @@ static void dump_remote_file(NET* net, const char* fname)
fflush(result_file);
}
-static int parse_args(int *argc, char*** argv)
-{
- int c, opt_index = 0;
- result_file = stdout;
- while((c = getopt_long(*argc, *argv, "so:#::d:h:j:u:p:P:r:t:?V", long_options,
- &opt_index)) != EOF)
+static my_bool
+get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
+ char *argument)
+{
+ switch(optid)
{
- switch(c)
- {
#ifndef DBUG_OFF
- case '#':
- DBUG_PUSH(optarg ? optarg : default_dbug_option);
- break;
+ case '#':
+ DBUG_PUSH(argument ? argument : default_dbug_option);
+ break;
#endif
- case 'd':
- one_database = 1;
- database = my_strdup(optarg, MYF(0));
- break;
-
- case 's':
- short_form = 1;
- break;
-
- case 'o':
- offset = strtoull(optarg,(char**) 0, 10);
- break;
-
- case 'j':
- position = strtoull(optarg,(char**) 0, 10);
- break;
-
- case 'h':
- use_remote = 1;
- host = my_strdup(optarg, MYF(0));
- break;
-
- case 'P':
- use_remote = 1;
- port = atoi(optarg);
- break;
-
- case 'p':
- use_remote = 1;
- pass = my_strdup(optarg, MYF(0));
- break;
-
- case 'r':
- if (!(result_file = my_fopen(optarg, O_WRONLY | O_BINARY, MYF(MY_WME))))
- exit(1);
- break;
-
- case 'u':
- use_remote = 1;
- user = my_strdup(optarg, MYF(0));
- break;
-
- case 't':
- table = my_strdup(optarg, MYF(0));
- break;
+ case 'd':
+ one_database = 1;
+ break;
+ case 'h':
+ use_remote = 1;
+ break;
+ case 'P':
+ use_remote = 1;
+ break;
+ case 'p':
+ use_remote = 1;
+ pass = my_strdup(argument, MYF(0));
+ break;
+ case 'r':
+ if (!(result_file = my_fopen(argument, O_WRONLY | O_BINARY, MYF(MY_WME))))
+ exit(1);
+ break;
+ case 'u':
+ use_remote = 1;
+ break;
+ case 'V':
+ print_version();
+ exit(0);
+ case '?':
+ default:
+ usage();
+ exit(0);
+ }
+ return 0;
+}
- case 'V':
- print_version();
- exit(0);
- case '?':
- default:
- usage();
- exit(0);
+static int parse_args(int *argc, char*** argv)
+{
+ int ho_error;
- }
+ result_file = stdout;
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ {
+ printf("%s: handle_options() failed with error %d\n", my_progname,
+ ho_error);
+ exit(1);
}
-
- (*argc)-=optind;
- (*argv)+=optind;
-
return 0;
}
diff --git a/client/mysqlmanager-pwgen.c b/client/mysqlmanager-pwgen.c
index 97eb31eb9c8..db8436c876c 100644
--- a/client/mysqlmanager-pwgen.c
+++ b/client/mysqlmanager-pwgen.c
@@ -14,7 +14,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-#define MANAGER_PWGEN_VERSION "1.0"
+#define MANAGER_PWGEN_VERSION "1.1"
#include <my_global.h>
#include <m_ctype.h>
@@ -22,18 +22,23 @@
#include <m_string.h>
#include <mysql_version.h>
#include <errno.h>
-#include <getopt.h>
+#include <my_getopt.h>
#include <md5.h>
const char* outfile=0,*user="root";
-struct option long_options[] =
+static struct my_option my_long_options[] =
{
- {"output-file",required_argument,0,'o'},
- {"user",required_argument,0,'u'},
- {"help",no_argument,0,'?'},
- {"version",no_argument,0,'V'},
- {0,0,0,0}
+ {"output-file", 'o', "Write the output to the file with the given name",
+ (gptr*) &outfile, (gptr*) &outfile, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0,
+ 0, 0},
+ {"user", 'u', "Put given user in the password file", (gptr*) &user,
+ (gptr*) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"help", '?', "Display this message and exit", 0, 0, 0, GET_NO_ARG, NO_ARG,
+ 0, 0, 0, 0, 0, 0},
+ {"version", 'V', "Display version info", 0, 0, 0, GET_NO_ARG, 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 die(const char* fmt, ...)
@@ -66,36 +71,39 @@ void usage()
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
printf("Generates a password file to be used by mysqltest.\n\n");
printf("Usage: %s [OPTIONS]\n", my_progname);
- printf("-?,--help Display this message and exit\n\
--V,--version Display version info\n\
--u,--user= Put given user in the password file\n\
--o,--output-file= Write the output to the file with the given name\n");
+ my_print_help(my_long_options);
+ putchar('\n');
+ my_print_variables(my_long_options);
}
+static my_bool
+get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
+ char *argument __attribute__((unused)))
+{
+ switch (optid) {
+ case '?':
+ usage();
+ exit(0);
+ case 'V':
+ print_version();
+ exit(0);
+ default:
+ usage();
+ exit(1);
+ }
+ return 0;
+}
+
+
int parse_args(int argc, char** argv)
{
- int c,option_index=0;
- while ((c=getopt_long(argc,argv,"?Vu:o:",long_options,&option_index))
- != EOF)
+ int ho_error;
+
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
{
- switch (c)
- {
- case 'o':
- outfile=optarg;
- break;
- case 'u':
- user=optarg;
- break;
- case '?':
- usage();
- exit(0);
- case 'V':
- print_version();
- exit(0);
- default:
- usage();
- exit(1);
- }
+ printf("%s: handle_options() failed with error %d\n", my_progname,
+ ho_error);
+ exit(1);
}
return 0;
}
diff --git a/client/mysqlmanagerc.c b/client/mysqlmanagerc.c
index a01f6c25f34..4acd33cf18a 100644
--- a/client/mysqlmanagerc.c
+++ b/client/mysqlmanagerc.c
@@ -14,7 +14,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-#define MANAGER_CLIENT_VERSION "1.1"
+#define MANAGER_CLIENT_VERSION "1.2"
#include <my_global.h>
#include <mysql.h>
@@ -22,7 +22,7 @@
#include <mysqld_error.h>
#include <my_sys.h>
#include <m_string.h>
-#include <getopt.h>
+#include <my_getopt.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -35,23 +35,31 @@ static void die(const char* fmt, ...);
const char* user="root",*host="localhost";
char* pass=0;
-int quiet=0;
+my_bool quiet=0;
uint port=MYSQL_MANAGER_PORT;
static const char *load_default_groups[]= { "mysqlmanagerc",0 };
char** default_argv;
MYSQL_MANAGER *manager;
FILE* fp, *fp_out;
-struct option long_options[] =
+static struct my_option my_long_options[] =
{
- {"host",required_argument,0,'h'},
- {"user",required_argument,0,'u'},
- {"password",optional_argument,0,'p',},
- {"port",required_argument,0,'P'},
- {"help",no_argument,0,'?'},
- {"version",no_argument,0,'V'},
- {"quiet",no_argument,0,'q'},
- {0,0,0,0}
+ {"host", 'h', "Connect to host.", (gptr*) &host, (gptr*) &host, 0,
+ GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"user", 'u', "User for login.", (gptr*) &user, (gptr*) &user, 0,
+ GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"password", 'p', "Password to use when connecting to server.",
+ 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
+ {"port", 'P', "Port number to use for connection.", (gptr*) &port,
+ (gptr*) &port, 0, GET_UINT, REQUIRED_ARG, MYSQL_MANAGER_PORT, 0, 0, 0, 0,
+ 0},
+ {"help", '?', "Display this help and exit.", 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},
+ {"quiet", 'q', "Suppress all normal output.", (gptr*) &quiet, (gptr*) &quiet,
+ 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 die(const char* fmt, ...)
@@ -84,65 +92,53 @@ void usage()
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
printf("Command-line client for MySQL manager daemon.\n\n");
printf("Usage: %s [OPTIONS] < command_file\n", my_progname);
- printf("\n\
- -?, --help Display this help and exit.\n");
- printf("\
- -h, --host=... Connect to host.\n\
- -u, --user=... User for login.\n\
- -p[password], --password[=...]\n\
- Password to use when connecting to server.\n\
- -P, --port=... Port number to use for connection.\n\
- -q, --quiet, --silent Suppress all normal output.\n\
- -V, --version Output version information and exit.\n\
- --no-defaults Don't read default options from any options file.\n\n");
+ my_print_help(my_long_options);
+ printf(" --no-defaults Don't read default options from any options file.\n\n");
+ my_print_variables(my_long_options);
}
-int parse_args(int argc, char **argv)
+
+
+static my_bool
+get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
+ char *argument)
{
- int c, option_index = 0;
my_bool tty_password=0;
+
+ switch (optid) {
+ case 'p':
+ if (argument)
+ {
+ my_free(pass, MYF(MY_ALLOW_ZERO_PTR));
+ pass= my_strdup(argument, MYF(MY_FAE));
+ while (*argument) *argument++= 'x'; /* Destroy argument */
+ }
+ else
+ tty_password=1;
+ break;
+ case 'V':
+ print_version();
+ exit(0);
+ case '?':
+ usage();
+ exit(0);
+ }
+ return 0;
+}
+
+
+int parse_args(int argc, char **argv)
+{
+ int ho_error;
load_defaults("my",load_default_groups,&argc,&argv);
default_argv= argv;
-
- while ((c = getopt_long(argc, argv, "h:p::u:P:?Vq",
- long_options, &option_index)) != EOF)
- {
- switch (c)
- {
- case 'h':
- host=optarg;
- break;
- case 'u':
- user=optarg;
- break;
- case 'p':
- if (optarg)
- {
- my_free(pass,MYF(MY_ALLOW_ZERO_PTR));
- pass=my_strdup(optarg,MYF(MY_FAE));
- while (*optarg) *optarg++= 'x'; /* Destroy argument */
- }
- else
- tty_password=1;
- break;
- case 'P':
- port=atoi(optarg);
- break;
- case 'q':
- quiet=1;
- break;
- case 'V':
- print_version();
- exit(0);
- case '?':
- usage();
- exit(0);
- default:
- usage();
- exit(1);
- }
- }
- return 0;
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
+ {
+ printf("%s: handle_options() failed with error %d\n", my_progname,
+ ho_error);
+ exit(1);
+ }
+ return 0;
}
int main(int argc, char** argv)
{
diff --git a/client/mysqltest.c b/client/mysqltest.c
index a161b9352d4..7c20d9bca7b 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -22,6 +22,7 @@
* Sasha Pachev <sasha@mysql.com>
* Matt Wagner <matt@mysql.com>
* Monty
+ * Jani
**/
/**********************************************************************
@@ -41,7 +42,7 @@
**********************************************************************/
-#define MTEST_VERSION "1.14"
+#define MTEST_VERSION "1.20"
#include <my_global.h>
#include <mysql_embed.h>
@@ -55,7 +56,7 @@
#include <hash.h>
#include <stdio.h>
#include <stdlib.h>
-#include <getopt.h>
+#include <my_getopt.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -95,10 +96,12 @@
enum {OPT_MANAGER_USER=256,OPT_MANAGER_HOST,OPT_MANAGER_PASSWD,
OPT_MANAGER_PORT,OPT_MANAGER_WAIT_TIMEOUT};
-static int record = 0, verbose = 0, silent = 0, opt_sleep=0;
+static int record = 0, opt_sleep=0;
static char *db = 0, *pass=0;
const char* user = 0, *host = 0, *unix_sock = 0, *opt_basedir="./";
-static int port = 0, opt_big_test=0, opt_compress=0;
+static int port = 0;
+static my_bool opt_big_test= 0, opt_compress= 0, silent= 0, verbose = 0,
+ tty_password= 0;
static uint start_lineno, *lineno;
const char* manager_user="root",*manager_host=0;
char *manager_pass=0;
@@ -1785,36 +1788,74 @@ int read_query(struct st_query** q_ptr)
return 0;
}
-struct option long_options[] =
-{
- {"debug", optional_argument, 0, '#'},
- {"database", required_argument, 0, 'D'},
- {"basedir", required_argument, 0, 'b'},
- {"big-test", no_argument, 0, 'B'},
- {"compress", no_argument, 0, 'C'},
- {"help", no_argument, 0, '?'},
- {"host", required_argument, 0, 'h'},
- {"manager-user",required_argument, 0, OPT_MANAGER_USER},
- {"manager-host",required_argument, 0, OPT_MANAGER_HOST},
- {"manager-password",required_argument,0,OPT_MANAGER_PASSWD},
- {"manager-port",required_argument,0,OPT_MANAGER_PORT},
- {"manager-wait-timeout",required_argument,0,OPT_MANAGER_WAIT_TIMEOUT},
- {"password", optional_argument, 0, 'p'},
- {"port", required_argument, 0, 'P'},
- {"quiet", no_argument, 0, 's'},
- {"record", no_argument, 0, 'r'},
- {"result-file", required_argument, 0, 'R'},
- {"server-arg", required_argument, 0, 'A'},
- {"server-file", required_argument, 0, 'F'},
- {"silent", no_argument, 0, 's'},
- {"sleep", required_argument, 0, 'T'},
- {"socket", required_argument, 0, 'S'},
- {"test-file", required_argument, 0, 'x'},
- {"tmpdir", required_argument, 0, 't'},
- {"user", required_argument, 0, 'u'},
- {"verbose", no_argument, 0, 'v'},
- {"version", no_argument, 0, 'V'},
- {0, 0, 0, 0}
+
+static struct my_option my_long_options[] =
+{
+#ifndef DBUG_OFF
+ {"debug", '#', "Output debug log. Often this is 'd:t:o,filename'",
+ 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
+#endif
+ {"database", 'D', "Database to use.", (gptr*) &db, (gptr*) &db, 0,
+ GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"basedir", 'b', "Basedir for tests", (gptr*) &opt_basedir,
+ (gptr*) &opt_basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"big-test", 'B', "Define BIG_TEST to 1", (gptr*) &opt_big_test,
+ (gptr*) &opt_big_test, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"compress", 'C', "Use the compressed server/client protocol",
+ (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
+ 0, 0, 0},
+ {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
+ 0, 0, 0, 0, 0, 0},
+ {"host", 'h', "Connect to host.", (gptr*) &host, (gptr*) &host, 0,
+ GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"manager-user", OPT_MANAGER_USER, "Undocumented: Used for debugging",
+ (gptr*) &manager_user, (gptr*) &manager_user, 0, GET_STR, REQUIRED_ARG, 0,
+ 0, 0, 0, 0, 0},
+ {"manager-host", OPT_MANAGER_HOST, "Undocumented: Used for debugging",
+ (gptr*) &manager_host, (gptr*) &manager_host, 0, GET_STR, REQUIRED_ARG,
+ 0, 0, 0, 0, 0, 0},
+ {"manager-password", OPT_MANAGER_PASSWD, "Undocumented: Used for debugging",
+ 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"manager-port", OPT_MANAGER_PORT, "Undocumented: Used for debugging",
+ (gptr*) &manager_port, (gptr*) &manager_port, 0, GET_INT, REQUIRED_ARG,
+ MYSQL_MANAGER_PORT, 0, 0, 0, 0, 0},
+ {"manager-wait-timeout", OPT_MANAGER_WAIT_TIMEOUT,
+ "Undocumented: Used for debugging", (gptr*) &manager_wait_timeout,
+ (gptr*) &manager_wait_timeout, 0, GET_INT, REQUIRED_ARG, 3, 0, 0, 0, 0, 0},
+ {"password", 'p', "Password to use when connecting to server.",
+ 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
+ {"port", 'P', "Port number to use for connection.", (gptr*) &port,
+ (gptr*) &port, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"quiet", 's', "Suppress all normal output.", (gptr*) &silent,
+ (gptr*) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"record", 'r', "Record output of test_file into result file.",
+ 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"result-file", 'R', "Read/Store result from/in this file.",
+ (gptr*) &result_file, (gptr*) &result_file, 0, GET_STR, REQUIRED_ARG,
+ 0, 0, 0, 0, 0, 0},
+ {"server-arg", 'A', "Send enbedded server this as a paramenter",
+ 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"server-file", 'F', "Read embedded server arguments from file",
+ 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"silent", 's', "Suppress all normal output. Synonym for --quiet.",
+ (gptr*) &silent, (gptr*) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"sleep", 'T', "Sleep always this many seconds on sleep commands",
+ (gptr*) &opt_sleep, (gptr*) &opt_sleep, 0, GET_INT, REQUIRED_ARG, 0, 0, 0,
+ 0, 0, 0},
+ {"socket", 'S', "Socket file to use for connection.",
+ (gptr*) &unix_sock, (gptr*) &unix_sock, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
+ 0, 0, 0},
+ {"test-file", 'x', "Read test from/in this file (default stdin).",
+ 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"tmpdir", 't', "Temporary directory where sockets are put",
+ 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"user", 'u', "User for login.", (gptr*) &user, (gptr*) &user, 0, GET_STR,
+ REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"verbose", 'v', "Write more.", (gptr*) &verbose, (gptr*) &verbose, 0,
+ GET_BOOL, 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},
+ { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
@@ -1827,170 +1868,101 @@ static void print_version(void)
void usage()
{
print_version();
- printf("MySQL AB, by Sasha, Matt & Monty\n");
+ printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
printf("Runs a test against the mysql server and compares output with a results file.\n\n");
printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname);
- printf("\n\
- -?, --help Display this help and exit.\n");
-#ifndef DBUG_OFF
- puts("\
- -#, --debug=[...] Output debug log. Often this is 'd:t:o,filename`");
-#endif
- printf("\
- -h, --host=... Connect to host.\n\
- -u, --user=... User for login.\n\
- -p[password], --password[=...]\n\
- Password to use when connecting to server.\n\
- -b, --basedir=... Basedir for tests\n\
- -B, --big-test Define BIG_TEST to 1\n\
- -C, --compress Use the compressed server/client protocol\n\
- -D, --database=... Database to use.\n\
- -P, --port=... Port number to use for connection.\n\
- --server-arg=... Send enbedded server this as a paramenter\n\
- --server-file=... Read embedded server arguments from file\n\
- -s, --silent, --quiet Suppress all normal output.\n\
- -S, --socket=... Socket file to use for connection.\n\
- -t, --tmpdir=... Temporary directory where sockets are put\n\
- -T, --sleep=# Sleep always this many seconds on sleep commands\n\
- -r, --record Record output of test_file into result file.\n\
- -R, --result-file=... Read/Store result from/in this file.\n\
- -x, --test-file=... Read test from/in this file (default stdin).\n\
- -v, --verbose Write more.\n\
- -V, --version Output version information and exit.\n\
- --no-defaults Don't read default options from any options file.\n\n");
+ my_print_help(my_long_options);
+ printf(" --no-defaults Don't read default options from any options file.\n\n");
+ my_print_variables(my_long_options);
}
+
+static my_bool
+get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
+ char *argument)
+{
+ switch(optid) {
+ case '#':
+ DBUG_PUSH(argument ? argument : "d:t:S:i:O,/tmp/mysqltest.trace");
+ break;
+ case 'r':
+ record = 1;
+ break;
+ case (int)OPT_MANAGER_PASSWD:
+ my_free(manager_pass,MYF(MY_ALLOW_ZERO_PTR));
+ manager_pass=my_strdup(argument, MYF(MY_FAE));
+ while (*argument) *argument++= 'x'; /* Destroy argument */
+ break;
+ case 'x':
+ {
+ char buff[FN_REFLEN];
+ if (!test_if_hard_path(argument))
+ {
+ strxmov(buff, opt_basedir, argument, NullS);
+ argument= buff;
+ }
+ fn_format(buff, argument, "", "", 4);
+ if (!(*++cur_file = my_fopen(buff, O_RDONLY, MYF(MY_WME))))
+ die("Could not open %s: errno = %d", argument, errno);
+ break;
+ }
+ case 'p':
+ if (argument)
+ {
+ my_free(pass, MYF(MY_ALLOW_ZERO_PTR));
+ pass= my_strdup(argument, MYF(MY_FAE));
+ while (*argument) *argument++= 'x'; /* Destroy argument */
+ }
+ else
+ tty_password= 1;
+ break;
+ case 't':
+ strnmov(TMPDIR, argument, sizeof(TMPDIR));
+ break;
+ case 'A':
+ if (!embedded_server_arg_count)
+ {
+ embedded_server_arg_count=1;
+ embedded_server_args[0]= (char*) "";
+ }
+ embedded_server_args[embedded_server_arg_count++]=
+ my_strdup(argument, MYF(MY_FAE));
+ if (embedded_server_arg_count == MAX_SERVER_ARGS ||
+ !embedded_server_args[embedded_server_arg_count-1])
+ {
+ die("Can't use server argument");
+ }
+ break;
+ case 'F':
+ if (read_server_arguments(argument))
+ die(NullS);
+ break;
+ case 'V':
+ print_version();
+ exit(0);
+ case '?':
+ usage();
+ exit(1);
+ }
+ return 0;
+}
+
+
int parse_args(int argc, char **argv)
{
- int c, option_index = 0;
- my_bool tty_password=0;
+ int ho_error;
load_defaults("my",load_default_groups,&argc,&argv);
default_argv= argv;
- while ((c = getopt_long(argc, argv, "A:h:p::u:b:BCF:P:D:S:R:x:t:T:#:?rvVs",
- long_options, &option_index)) != EOF)
- {
- switch(c) {
- case '#':
- DBUG_PUSH(optarg ? optarg : "d:t:S:i:O,/tmp/mysqltest.trace");
- break;
- case 'v':
- verbose = 1;
- break;
- case 'r':
- record = 1;
- break;
- case (int)OPT_MANAGER_WAIT_TIMEOUT:
- manager_wait_timeout=atoi(optarg);
- break;
- case (int)OPT_MANAGER_PORT:
- manager_port=atoi(optarg);
- break;
- case (int)OPT_MANAGER_HOST:
- manager_host=optarg;
- break;
- case (int)OPT_MANAGER_USER:
- manager_user=optarg;
- break;
- case (int)OPT_MANAGER_PASSWD:
- my_free(manager_pass,MYF(MY_ALLOW_ZERO_PTR));
- manager_pass=my_strdup(optarg,MYF(MY_FAE));
- while (*optarg) *optarg++= 'x'; /* Destroy argument */
- break;
- case 'u':
- user = optarg;
- break;
- case 'R':
- result_file = optarg;
- break;
- case 'x':
- {
- char buff[FN_REFLEN];
- if (!test_if_hard_path(optarg))
- {
- strxmov(buff, opt_basedir, optarg, NullS);
- optarg=buff;
- }
- fn_format(buff,optarg,"","",4);
- if (!(*++cur_file = my_fopen(buff, O_RDONLY, MYF(MY_WME))))
- die("Could not open %s: errno = %d", optarg, errno);
- break;
- }
- case 'p':
- if (optarg)
- {
- my_free(pass,MYF(MY_ALLOW_ZERO_PTR));
- pass=my_strdup(optarg,MYF(MY_FAE));
- while (*optarg) *optarg++= 'x'; /* Destroy argument */
- }
- else
- tty_password=1;
- break;
- case 'b':
- opt_basedir= optarg;
- break;
- case 'B':
- opt_big_test=1;
- break;
- case 'C':
- opt_compress=1;
- break;
- case 'P':
- port = atoi(optarg);
- break;
- case 'S':
- unix_sock = optarg;
- break;
- case 'D':
- db = optarg;
- break;
- case 'h':
- host = optarg;
- break;
- case 's':
- silent = 1;
- break;
- case 't':
- strnmov(TMPDIR,optarg,sizeof(TMPDIR));
- break;
- case 'T':
- opt_sleep=atoi(optarg);
- break;
- case 'A':
- if (!embedded_server_arg_count)
- {
- embedded_server_arg_count=1;
- embedded_server_args[0]= (char*) "";
- }
- embedded_server_args[embedded_server_arg_count++]=
- my_strdup(optarg,MYF(MY_FAE));
- if (embedded_server_arg_count == MAX_SERVER_ARGS ||
- !embedded_server_args[embedded_server_arg_count-1])
- {
- die("Can't use server argument");
- }
- break;
- case 'F':
- if (read_server_arguments(optarg))
- die(NullS);
- break;
- case 'V':
- print_version();
- exit(0);
- case '?':
- usage();
- exit(1); /* Unknown option */
- default:
- fprintf(stderr,"Unknown option '%c'\n",c);
- usage();
- exit(1);
- }
- }
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
+ {
+ printf("%s: handle_options() failed with error %d\n", my_progname,
+ ho_error);
+ exit(1);
+ }
- argc-=optind;
- argv+=optind;
if (argc > 1)
{
usage();
diff --git a/client/thread_test.c b/client/thread_test.c
index f7e2a6fd32a..10183ca5150 100644
--- a/client/thread_test.c
+++ b/client/thread_test.c
@@ -28,9 +28,9 @@ int main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
#include <my_sys.h>
#include <my_pthread.h>
#include "mysql.h"
-#include <getopt.h>
+#include <my_getopt.h>
-static my_bool version,verbose;
+static my_bool version, verbose, tty_password= 0;
static uint thread_count,number_of_tests=1000,number_of_threads=2;
static pthread_cond_t COND_thread_count;
static pthread_mutex_t LOCK_thread_count;
@@ -84,23 +84,39 @@ end:
}
-static struct option long_options[] =
+static struct my_option my_long_options[] =
{
- {"help", no_argument, 0, '?'},
- {"database", required_argument, 0, 'D'},
- {"host", required_argument, 0, 'h'},
- {"password", optional_argument, 0, 'p'},
- {"user", required_argument, 0, 'u'},
- {"version", no_argument, 0, 'V'},
- {"verbose", no_argument, 0, 'v'},
- {"query", required_argument, 0, 'Q'},
- {"port", required_argument, 0, 'P'},
- {"socket", required_argument, 0, 'S'},
- {"test-count",required_argument, 0, 'c'},
- {"thread-count",required_argument, 0, 't'},
- {0, 0, 0, 0}
+ {"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
+ 0, 0, 0, 0, 0},
+ {"database", 'D', "Database to use", (gptr*) &database, (gptr*) &database,
+ 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"host", 'h', "Connect to host", (gptr*) &host, (gptr*) &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 asked from the tty.",
+ 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
+ {"user", 'u', "User for login if not current user", (gptr*) &user,
+ (gptr*) &user, 0, GET_STR_ALLOC, REQUIRED_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},
+ {"verbose", 'v', "Write some progress indicators", (gptr*) &verbose,
+ (gptr*) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"query", 'Q', "Query to execute in each threads", (gptr*) &query,
+ (gptr*) &query, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"port", 'P', "Port number to use for connection", (gptr*) &tcp_port,
+ (gptr*) &tcp_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"socket", 'S', "Socket file to use for connection", (gptr*) &unix_socket,
+ (gptr*) &unix_socket, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"test-count", 'c', "Run test count times (default %d)",
+ (gptr*) &number_of_tests, (gptr*) &number_of_tests, 0, GET_UINT,
+ REQUIRED_ARG, 1000, 0, 0, 0, 0, 0},
+ {"thread-count", 't', "Number of threads to start",
+ (gptr*) &number_of_threads, (gptr*) &number_of_threads, 0, GET_UINT,
+ REQUIRED_ARG, 2, 0, 0, 0, 0, 0},
+ { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
+
static const char *load_default_groups[]= { "client",0 };
static void usage()
@@ -110,103 +126,59 @@ static void usage()
return;
puts("This software comes with ABSOLUTELY NO WARRANTY.\n");
printf("Usage: %s [OPTIONS] [database]\n", my_progname);
- printf("\n\
- -?, --help Display this help and exit\n\
- -c #, --test-count=# Run test count times (default %d)\n",number_of_tests);
- printf("\
- -D, --database=.. Database to use\n\
- -h, --host=... Connect to host\n\
- -p[password], --password[=...]\n\
- Password to use when connecting to server\n\
- If password is not given it's asked from the tty.\n");
- printf("\n\
- -P --port=... Port number to use for connection\n\
- -Q, --query=... Query to execute in each threads\n\
- -S --socket=... Socket file to use for connection\n");
- printf("\
- -t --thread-count=# Number of threads to start (default: %d) \n\
- -u, --user=# User for login if not current user\n\
- -v, --verbose Write some progress indicators\n\
- -V, --version Output version information and exit\n",
- number_of_threads);
+ my_print_help(my_long_options);
print_defaults("my",load_default_groups);
-
+ my_print_variables(my_long_options);
printf("\nExample usage:\n\n\
%s -Q 'select * from mysql.user' -c %d -t %d\n",
my_progname, number_of_tests, number_of_threads);
}
+static my_bool
+get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
+ char *argument)
+{
+ switch (optid) {
+ case 'p':
+ if (argument)
+ {
+ my_free(password, MYF(MY_ALLOW_ZERO_PTR));
+ password= my_strdup(argument, MYF(MY_FAE));
+ while (*argument) *argument++= 'x'; /* Destroy argument */
+ }
+ else
+ tty_password= 1;
+ break;
+ case 'V':
+ version= 1;
+ usage();
+ exit(0);
+ break;
+ case '?':
+ case 'I': /* Info */
+ usage();
+ exit(1);
+ break;
+ }
+ return 0;
+}
+
+
static void get_options(int argc, char **argv)
{
- int c,option_index=0,error=0;
- bool tty_password=0;
+ int ho_error;
+
load_defaults("my",load_default_groups,&argc,&argv);
- while ((c=getopt_long(argc,argv, "c:D:h:p::VQ:P:S:t:?I",
- long_options, &option_index)) != EOF)
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
{
- switch (c) {
- case 'c':
- number_of_tests=atoi(optarg);
- break;
- case 'D':
- my_free(database,MYF(MY_ALLOW_ZERO_PTR));
- database=my_strdup(optarg,MYF(MY_WME));
- break;
- case 'h':
- host = optarg;
- break;
- case 'Q': /* Allow old 'q' option */
- query= optarg;
- break;
- case 'p':
- if (optarg)
- {
- my_free(password,MYF(MY_ALLOW_ZERO_PTR));
- password=my_strdup(optarg,MYF(MY_FAE));
- while (*optarg) *optarg++= 'x'; /* Destroy argument */
- }
- else
- tty_password=1;
- break;
- case 'u':
- my_free(user,MYF(MY_ALLOW_ZERO_PTR));
- user= my_strdup(optarg,MYF(0));
- break;
- case 'P':
- tcp_port= (unsigned int) atoi(optarg);
- break;
- case 'S':
- my_free(unix_socket,MYF(MY_ALLOW_ZERO_PTR));
- unix_socket= my_strdup(optarg,MYF(0));
- break;
- case 't':
- number_of_threads=atoi(optarg);
- break;
- case 'v':
- verbose=1;
- break;
- case 'V':
- version=1;
- usage();
- exit(0);
- break;
- default:
- fprintf(stderr,"Illegal option character '%c'\n",opterr);
- /* Fall through */
- case '?':
- case 'I': /* Info */
- error++;
- break;
- }
- }
- if (error || argc != optind)
- {
- usage();
+ printf("%s: handle_options() failed with error %d\n", my_progname,
+ ho_error);
exit(1);
}
+
free_defaults(argv);
if (tty_password)
password=get_tty_password(NullS);