Commit c2205c75 authored by jani@hynda.(none)'s avatar jani@hynda.(none)

Changed mysqlbinlog, mysqlmanager-pwgen, mysqlmanagerc, mysqltest,

thread_test and isamchk to use my_getopt.

Fixed a bug in my_getopt.
parent cca212ff
...@@ -61,3 +61,4 @@ tonu@x3.internalnet ...@@ -61,3 +61,4 @@ tonu@x3.internalnet
venu@work.mysql.com venu@work.mysql.com
zak@balfor.local zak@balfor.local
zak@linux.local zak@linux.local
jani@hynda.(none)
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "client_priv.h" #include "client_priv.h"
#include <time.h> #include <time.h>
#include "log_event.h" #include "log_event.h"
#include <my_getopt.h>
#define PROBE_HEADER_LEN (4+EVENT_LEN_OFFSET+4) #define PROBE_HEADER_LEN (4+EVENT_LEN_OFFSET+4)
...@@ -38,26 +39,6 @@ static FILE *result_file; ...@@ -38,26 +39,6 @@ static FILE *result_file;
static const char* default_dbug_option = "d:t:o,/tmp/mysqlbinlog.trace"; static const char* default_dbug_option = "d:t:o,/tmp/mysqlbinlog.trace";
#endif #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,...); void sql_print_error(const char *format,...);
static bool one_database = 0; static bool one_database = 0;
...@@ -82,6 +63,44 @@ static void dump_remote_table(NET* net, const char* db, const char* table); ...@@ -82,6 +63,44 @@ static void dump_remote_table(NET* net, const char* db, const char* table);
static void die(const char* fmt, ...); static void die(const char* fmt, ...);
static MYSQL* safe_connect(); 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,...) void sql_print_error(const char *format,...)
{ {
...@@ -106,7 +125,7 @@ static void die(const char* fmt, ...) ...@@ -106,7 +125,7 @@ static void die(const char* fmt, ...)
static void print_version() 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"); ...@@ -120,26 +139,10 @@ and you are welcome to modify and redistribute it under the GPL license\n");
printf("\ printf("\
Dumps a MySQL binary log in a format usable for viewing or for pipeing to\n\ Dumps a MySQL binary log in a format usable for viewing or for pipeing to\n\
the mysql command line client\n\n"); the mysql command line client\n\n");
printf("Usage: %s [options] log-files\n",my_progname); printf("Usage: %s [options] log-files\n", my_progname);
puts("Options:"); my_print_help(my_long_options);
#ifndef DBUG_OFF putchar('\n');
printf("-#, --debug[=...] Output debug log. (%s)\n", my_print_variables(my_long_options);
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\
");
} }
static void dump_remote_file(NET* net, const char* fname) static void dump_remote_file(NET* net, const char* fname)
...@@ -172,82 +175,61 @@ 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); fflush(result_file);
} }
static int parse_args(int *argc, char*** argv)
{
int c, opt_index = 0;
result_file = stdout; static my_bool
while((c = getopt_long(*argc, *argv, "so:#::d:h:j:u:p:P:r:t:?V", long_options, get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
&opt_index)) != EOF) char *argument)
{
switch(optid)
{ {
switch(c)
{
#ifndef DBUG_OFF #ifndef DBUG_OFF
case '#': case '#':
DBUG_PUSH(optarg ? optarg : default_dbug_option); DBUG_PUSH(argument ? argument : default_dbug_option);
break; break;
#endif #endif
case 'd': case 'd':
one_database = 1; one_database = 1;
database = my_strdup(optarg, MYF(0)); break;
break; case 'h':
use_remote = 1;
case 's': break;
short_form = 1; case 'P':
break; use_remote = 1;
break;
case 'o': case 'p':
offset = strtoull(optarg,(char**) 0, 10); use_remote = 1;
break; pass = my_strdup(argument, MYF(0));
break;
case 'j': case 'r':
position = strtoull(optarg,(char**) 0, 10); if (!(result_file = my_fopen(argument, O_WRONLY | O_BINARY, MYF(MY_WME))))
break; exit(1);
break;
case 'h': case 'u':
use_remote = 1; use_remote = 1;
host = my_strdup(optarg, MYF(0)); break;
break; case 'V':
print_version();
case 'P': exit(0);
use_remote = 1; case '?':
port = atoi(optarg); default:
break; usage();
exit(0);
case 'p': }
use_remote = 1; return 0;
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 'V':
print_version();
exit(0);
case '?': static int parse_args(int *argc, char*** argv)
default: {
usage(); int ho_error;
exit(0);
} 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; return 0;
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 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 <my_global.h>
#include <m_ctype.h> #include <m_ctype.h>
...@@ -22,18 +22,23 @@ ...@@ -22,18 +22,23 @@
#include <m_string.h> #include <m_string.h>
#include <mysql_version.h> #include <mysql_version.h>
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <my_getopt.h>
#include <md5.h> #include <md5.h>
const char* outfile=0,*user="root"; const char* outfile=0,*user="root";
struct option long_options[] = static struct my_option my_long_options[] =
{ {
{"output-file",required_argument,0,'o'}, {"output-file", 'o', "Write the output to the file with the given name",
{"user",required_argument,0,'u'}, (gptr*) &outfile, (gptr*) &outfile, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0,
{"help",no_argument,0,'?'}, 0, 0},
{"version",no_argument,0,'V'}, {"user", 'u', "Put given user in the password file", (gptr*) &user,
{0,0,0,0} (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, ...) static void die(const char* fmt, ...)
...@@ -66,36 +71,39 @@ void usage() ...@@ -66,36 +71,39 @@ void usage()
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n"); printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
printf("Generates a password file to be used by mysqltest.\n\n"); printf("Generates a password file to be used by mysqltest.\n\n");
printf("Usage: %s [OPTIONS]\n", my_progname); printf("Usage: %s [OPTIONS]\n", my_progname);
printf("-?,--help Display this message and exit\n\ my_print_help(my_long_options);
-V,--version Display version info\n\ putchar('\n');
-u,--user= Put given user in the password file\n\ my_print_variables(my_long_options);
-o,--output-file= Write the output to the file with the given name\n");
} }
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 parse_args(int argc, char** argv)
{ {
int c,option_index=0; int ho_error;
while ((c=getopt_long(argc,argv,"?Vu:o:",long_options,&option_index))
!= EOF) if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
{ {
switch (c) printf("%s: handle_options() failed with error %d\n", my_progname,
{ ho_error);
case 'o': exit(1);
outfile=optarg;
break;
case 'u':
user=optarg;
break;
case '?':
usage();
exit(0);
case 'V':
print_version();
exit(0);
default:
usage();
exit(1);
}
} }
return 0; return 0;
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 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 <my_global.h>
#include <mysql.h> #include <mysql.h>
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include <mysqld_error.h> #include <mysqld_error.h>
#include <my_sys.h> #include <my_sys.h>
#include <m_string.h> #include <m_string.h>
#include <getopt.h> #include <my_getopt.h>
#include <stdarg.h> #include <stdarg.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
...@@ -35,23 +35,31 @@ static void die(const char* fmt, ...); ...@@ -35,23 +35,31 @@ static void die(const char* fmt, ...);
const char* user="root",*host="localhost"; const char* user="root",*host="localhost";
char* pass=0; char* pass=0;
int quiet=0; my_bool quiet=0;
uint port=MYSQL_MANAGER_PORT; uint port=MYSQL_MANAGER_PORT;
static const char *load_default_groups[]= { "mysqlmanagerc",0 }; static const char *load_default_groups[]= { "mysqlmanagerc",0 };
char** default_argv; char** default_argv;
MYSQL_MANAGER *manager; MYSQL_MANAGER *manager;
FILE* fp, *fp_out; FILE* fp, *fp_out;
struct option long_options[] = static struct my_option my_long_options[] =
{ {
{"host",required_argument,0,'h'}, {"host", 'h', "Connect to host.", (gptr*) &host, (gptr*) &host, 0,
{"user",required_argument,0,'u'}, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"password",optional_argument,0,'p',}, {"user", 'u', "User for login.", (gptr*) &user, (gptr*) &user, 0,
{"port",required_argument,0,'P'}, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"help",no_argument,0,'?'}, {"password", 'p', "Password to use when connecting to server.",
{"version",no_argument,0,'V'}, 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"quiet",no_argument,0,'q'}, {"port", 'P', "Port number to use for connection.", (gptr*) &port,
{0,0,0,0} (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, ...) static void die(const char* fmt, ...)
...@@ -84,65 +92,53 @@ void usage() ...@@ -84,65 +92,53 @@ void usage()
printf("This software comes with ABSOLUTELY NO WARRANTY\n\n"); printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
printf("Command-line client for MySQL manager daemon.\n\n"); printf("Command-line client for MySQL manager daemon.\n\n");
printf("Usage: %s [OPTIONS] < command_file\n", my_progname); printf("Usage: %s [OPTIONS] < command_file\n", my_progname);
printf("\n\ my_print_help(my_long_options);
-?, --help Display this help and exit.\n"); printf(" --no-defaults Don't read default options from any options file.\n\n");
printf("\ my_print_variables(my_long_options);
-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");
} }
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; 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); load_defaults("my",load_default_groups,&argc,&argv);
default_argv= argv; default_argv= argv;
if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
while ((c = getopt_long(argc, argv, "h:p::u:P:?Vq", {
long_options, &option_index)) != EOF) printf("%s: handle_options() failed with error %d\n", my_progname,
{ ho_error);
switch (c) exit(1);
{ }
case 'h': return 0;
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;
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
......
This diff is collapsed.
...@@ -28,9 +28,9 @@ int main(int argc __attribute__((unused)), char **argv __attribute__((unused))) ...@@ -28,9 +28,9 @@ int main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
#include <my_sys.h> #include <my_sys.h>
#include <my_pthread.h> #include <my_pthread.h>
#include "mysql.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 uint thread_count,number_of_tests=1000,number_of_threads=2;
static pthread_cond_t COND_thread_count; static pthread_cond_t COND_thread_count;
static pthread_mutex_t LOCK_thread_count; static pthread_mutex_t LOCK_thread_count;
...@@ -84,23 +84,39 @@ end: ...@@ -84,23 +84,39 @@ end:
} }
static struct option long_options[] = static struct my_option my_long_options[] =
{ {
{"help", no_argument, 0, '?'}, {"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
{"database", required_argument, 0, 'D'}, 0, 0, 0, 0, 0},
{"host", required_argument, 0, 'h'}, {"database", 'D', "Database to use", (gptr*) &database, (gptr*) &database,
{"password", optional_argument, 0, 'p'}, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"user", required_argument, 0, 'u'}, {"host", 'h', "Connect to host", (gptr*) &host, (gptr*) &host, 0, GET_STR,
{"version", no_argument, 0, 'V'}, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"verbose", no_argument, 0, 'v'}, {"password", 'p',
{"query", required_argument, 0, 'Q'}, "Password to use when connecting to server. If password is not given it's asked from the tty.",
{"port", required_argument, 0, 'P'}, 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"socket", required_argument, 0, 'S'}, {"user", 'u', "User for login if not current user", (gptr*) &user,
{"test-count",required_argument, 0, 'c'}, (gptr*) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"thread-count",required_argument, 0, 't'}, {"version", 'V', "Output version information and exit",
{0, 0, 0, 0} 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 const char *load_default_groups[]= { "client",0 };
static void usage() static void usage()
...@@ -110,103 +126,59 @@ static void usage() ...@@ -110,103 +126,59 @@ static void usage()
return; return;
puts("This software comes with ABSOLUTELY NO WARRANTY.\n"); puts("This software comes with ABSOLUTELY NO WARRANTY.\n");
printf("Usage: %s [OPTIONS] [database]\n", my_progname); 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); print_defaults("my",load_default_groups);
my_print_variables(my_long_options);
printf("\nExample usage:\n\n\ printf("\nExample usage:\n\n\
%s -Q 'select * from mysql.user' -c %d -t %d\n", %s -Q 'select * from mysql.user' -c %d -t %d\n",
my_progname, number_of_tests, number_of_threads); 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) static void get_options(int argc, char **argv)
{ {
int c,option_index=0,error=0; int ho_error;
bool tty_password=0;
load_defaults("my",load_default_groups,&argc,&argv); load_defaults("my",load_default_groups,&argc,&argv);
while ((c=getopt_long(argc,argv, "c:D:h:p::VQ:P:S:t:?I", if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
long_options, &option_index)) != EOF)
{ {
switch (c) { printf("%s: handle_options() failed with error %d\n", my_progname,
case 'c': ho_error);
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();
exit(1); exit(1);
} }
free_defaults(argv); free_defaults(argv);
if (tty_password) if (tty_password)
password=get_tty_password(NullS); password=get_tty_password(NullS);
......
This diff is collapsed.
...@@ -593,6 +593,9 @@ static void init_variables(const struct my_option *options) ...@@ -593,6 +593,9 @@ static void init_variables(const struct my_option *options)
else if (options->var_type == GET_UINT) else if (options->var_type == GET_UINT)
*((uint*) options->u_max_value)= *((uint*) options->value)= *((uint*) options->u_max_value)= *((uint*) options->value)=
(uint) options->def_value; (uint) options->def_value;
else if (options->var_type == GET_BOOL)
*((my_bool*) options->u_max_value)= *((my_bool*) options->value)=
(my_bool) options->def_value;
else if (options->var_type == GET_LONG) else if (options->var_type == GET_LONG)
*((long*) options->u_max_value)= *((long*) options->value)= *((long*) options->u_max_value)= *((long*) options->value)=
(long) options->def_value; (long) options->def_value;
...@@ -653,7 +656,7 @@ void my_print_help(const struct my_option *options) ...@@ -653,7 +656,7 @@ void my_print_help(const struct my_option *options)
optp->arg_type == OPT_ARG ? "]" : ""); optp->arg_type == OPT_ARG ? "]" : "");
col+= (optp->arg_type == OPT_ARG) ? 5 : 3; col+= (optp->arg_type == OPT_ARG) ? 5 : 3;
} }
if (col > name_space) if (col > name_space && optp->comment && *optp->comment)
{ {
putchar('\n'); putchar('\n');
col= 0; col= 0;
...@@ -697,7 +700,7 @@ void my_print_variables(const struct my_option *options) ...@@ -697,7 +700,7 @@ void my_print_variables(const struct my_option *options)
printf("--------------------------------- -------------\n"); printf("--------------------------------- -------------\n");
for (optp= options; optp->id; optp++) for (optp= options; optp->id; optp++)
{ {
if (optp->value && optp->var_type != GET_BOOL) if (optp->value)
{ {
printf("%s", optp->name); printf("%s", optp->name);
length= strlen(optp->name); length= strlen(optp->name);
...@@ -710,6 +713,13 @@ void my_print_variables(const struct my_option *options) ...@@ -710,6 +713,13 @@ void my_print_variables(const struct my_option *options)
else else
printf("(No default value)\n"); printf("(No default value)\n");
} }
else if (optp->var_type == GET_BOOL)
{
if (!optp->def_value && !*((my_bool*) optp->value))
printf("(No default value)\n");
else
printf("%d\n", *((my_bool*) optp->value));
}
else if (optp->var_type == GET_INT) else if (optp->var_type == GET_INT)
{ {
if (!optp->def_value && !*((int*) optp->value)) if (!optp->def_value && !*((int*) optp->value))
......
...@@ -617,7 +617,7 @@ extern pthread_cond_t COND_refresh,COND_thread_count; ...@@ -617,7 +617,7 @@ extern pthread_cond_t COND_refresh,COND_thread_count;
extern pthread_attr_t connection_attrib; extern pthread_attr_t connection_attrib;
extern bool opt_endinfo, using_udf_functions, locked_in_memory, extern bool opt_endinfo, using_udf_functions, locked_in_memory,
opt_using_transactions, use_temp_pool, mysql_embedded; opt_using_transactions, use_temp_pool, mysql_embedded;
extern bool opt_local_infile; extern my_bool opt_local_infile;
extern char f_fyllchar; extern char f_fyllchar;
extern ulong ha_read_count, ha_write_count, ha_delete_count, ha_update_count, extern ulong ha_read_count, ha_write_count, ha_delete_count, ha_update_count,
ha_read_key_count, ha_read_next_count, ha_read_prev_count, ha_read_key_count, ha_read_next_count, ha_read_prev_count,
......
...@@ -334,7 +334,7 @@ ulong bytes_sent = 0L, bytes_received = 0L; ...@@ -334,7 +334,7 @@ ulong bytes_sent = 0L, bytes_received = 0L;
bool opt_endinfo,using_udf_functions,low_priority_updates, locked_in_memory; bool opt_endinfo,using_udf_functions,low_priority_updates, locked_in_memory;
bool opt_using_transactions, using_update_log, opt_warnings=0; bool opt_using_transactions, using_update_log, opt_warnings=0;
bool opt_local_infile=1; my_bool opt_local_infile=1;
bool volatile abort_loop,select_thread_in_use,grant_option; bool volatile abort_loop,select_thread_in_use,grant_option;
bool volatile ready_to_exit,shutdown_in_progress; bool volatile ready_to_exit,shutdown_in_progress;
ulong refresh_version=1L,flush_version=1L; /* Increments on each reload */ ulong refresh_version=1L,flush_version=1L; /* Increments on each reload */
...@@ -2974,7 +2974,7 @@ static struct my_option my_long_options[] = ...@@ -2974,7 +2974,7 @@ static struct my_option my_long_options[] =
{"local-infile", OPT_LOCAL_INFILE, {"local-infile", OPT_LOCAL_INFILE,
"Enable/disable LOAD DATA LOCAL INFILE (takes values 1|0)", "Enable/disable LOAD DATA LOCAL INFILE (takes values 1|0)",
(gptr*) &opt_local_infile, (gptr*) &opt_local_infile, 0, GET_BOOL, OPT_ARG, (gptr*) &opt_local_infile, (gptr*) &opt_local_infile, 0, GET_BOOL, OPT_ARG,
0, 0, 0, 0, 0, 0}, 1, 0, 0, 0, 0, 0},
{"log-bin", OPT_BIN_LOG, {"log-bin", OPT_BIN_LOG,
"Log queries in new binary format (for replication)", "Log queries in new binary format (for replication)",
(gptr*) &opt_bin_logname, (gptr*) &opt_bin_logname, 0, GET_STR_ALLOC, (gptr*) &opt_bin_logname, (gptr*) &opt_bin_logname, 0, GET_STR_ALLOC,
...@@ -3987,9 +3987,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), ...@@ -3987,9 +3987,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case 'o': case 'o':
protocol_version=PROTOCOL_VERSION-1; protocol_version=PROTOCOL_VERSION-1;
break; break;
case OPT_LOCAL_INFILE:
opt_local_infile= test(!argument || atoi(argument) != 0);
break;
case OPT_SLAVE_SKIP_ERRORS: case OPT_SLAVE_SKIP_ERRORS:
init_slave_skip_errors(argument); init_slave_skip_errors(argument);
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment