summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <rburnett@build.mysql.com>2004-08-14 03:38:37 +0200
committerunknown <rburnett@build.mysql.com>2004-08-14 03:38:37 +0200
commit767d880f9c641746ed0087c4a2395e2a66d43374 (patch)
tree8bab2307b9948e0dc6a489230cd690abe672411d
parent5ee446d9d0337f7c35ad8cb2b90f0a6aeac20a3c (diff)
downloadmariadb-git-767d880f9c641746ed0087c4a2395e2a66d43374.tar.gz
mysql_priv.h:
Added declarations for print_msg_to_log and vprint_msg_to_log. sql_print_error are simple functions that wrap calls to print_msg_to_log. Define the different error types with MY_ERROR_TYPE, MY_WARNING_TYPE, and MY_INFORMATION_TYPE gen_lex_hash.cc: Added NULL error reporting parameter to handle_options log.cc: Add print_msg_to_log, print_buffer_to_log, and vprint_msg_to_log. Print_msg_to_log will write the message to the windows event log if on NT. We now have error, warning, and information versions of sql_print_xxxx. T his is a variation of a similar changeset WAX did. mysqld.cc: Added option_error_reporter callback function and pass that into handle_options mysql.cc: Added NULL as error reporter arg to the end of handle_options Many files: Added NULL error reporter parameter as the last paramter to handle_options my_getopt.c: Added second function pointer to server as an error reporting callback. Added local function report_option_error that will either write the error to stderr or to the error reporting callback. changed all calls in handle_options from fprintf(stderr, ... ) to report_option_error my_getopt.h: Changed declaration of handle_options to use typedefs for the two function pointers. added second function pointer to server as an error reporting callback mysqld.dsp: Added custom build step for compiling message file and added message resource file (output of mc) VC++Files/sql/mysqld.dsp: Added custom build step for compiling message file and added message resource file (output of mc) client/mysqladmin.c: Added NULL error reporter parameter as the last paramter to handle_options client/mysqlcheck.c: Added NULL error reporter parameter as the last paramter to handle_options client/mysqldump.c: Added NULL error reporter parameter as the last paramter to handle_options client/mysqlimport.c: Added NULL error reporter parameter as the last paramter to handle_options client/mysqlmanager-pwgen.c: Added NULL error reporter parameter as the last paramter to handle_options client/mysqlmanagerc.c: Added NULL error reporter parameter as the last paramter to handle_options client/mysqlbinlog.cc: Added NULL error reporter parameter as the last paramter to handle_options client/mysqlshow.c: Added NULL error reporter parameter as the last paramter to handle_options client/mysqltest.c: Added NULL error reporter parameter as the last paramter to handle_options extra/my_print_defaults.c: Added NULL error reporter parameter as the last paramter to handle_options extra/mysql_install.c: Added NULL error reporter parameter as the last paramter to handle_options extra/mysql_waitpid.c: Added NULL error reporter parameter as the last paramter to handle_options extra/perror.c: Added NULL error reporter parameter as the last paramter to handle_options extra/resolve_stack_dump.c: Added NULL error reporter parameter as the last paramter to handle_options extra/resolveip.c: Added NULL error reporter parameter as the last paramter to handle_options isam/isamchk.c: Added NULL error reporter parameter as the last paramter to handle_options isam/pack_isam.c: Added NULL error reporter parameter as the last paramter to handle_options myisam/mi_test1.c: Added NULL error reporter parameter as the last paramter to handle_options myisam/myisam_ftdump.c: Added NULL error reporter parameter as the last paramter to handle_options myisam/myisamchk.c: Added NULL error reporter parameter as the last paramter to handle_options myisam/myisampack.c: Added NULL error reporter parameter as the last paramter to handle_options include/my_getopt.h: Changed declaration of handle_options to use typedefs for the two function pointers. added second function pointer to server as an error reporting callback mysys/my_getopt.c: Added second function pointer to server as an error reporting callback. Added local function report_option_error that will either write the error to stderr or to the error reporting callback. changed all calls in handle_options from fprintf(stderr, ... ) to report_option_error tools/mysqlmanager.c: Added NULL error reporter parameter as the last paramter to handle_options client/mysql.cc: Added NULL as error reporter arg to the end of handle_options sql/mysqld.cc: Added option_error_reporter callback function and pass that into handle_options sql/log.cc: Add print_msg_to_log, print_buffer_to_log, and vprint_msg_to_log. Print_msg_to_log will write the message to the windows event log if on NT. We now have error, warning, and information versions of sql_print_xxxx. T his is a variation of a similar changeset WAX did. sql/gen_lex_hash.cc: Added NULL error reporting parameter to handle_options sql/mysql_priv.h: Added declarations for print_msg_to_log and vprint_msg_to_log. sql_print_error are simple functions that wrap calls to print_msg_to_log. Define the different error types with MY_ERROR_TYPE, MY_WARNING_TYPE, and MY_INFORMATION_TYPE BitKeeper/etc/logging_ok: Logging to logging@openlogging.org accepted
-rw-r--r--BitKeeper/etc/logging_ok1
-rw-r--r--VC++Files/sql/mysqld.dsp83
-rw-r--r--client/mysql.cc2
-rw-r--r--client/mysqladmin.c2
-rw-r--r--client/mysqlbinlog.cc2
-rw-r--r--client/mysqlcheck.c2
-rw-r--r--client/mysqldump.c2
-rw-r--r--client/mysqlimport.c2
-rw-r--r--client/mysqlmanager-pwgen.c2
-rw-r--r--client/mysqlmanagerc.c2
-rw-r--r--client/mysqlshow.c2
-rw-r--r--client/mysqltest.c2
-rw-r--r--extra/my_print_defaults.c2
-rw-r--r--extra/mysql_install.c2
-rw-r--r--extra/mysql_waitpid.c2
-rw-r--r--extra/perror.c2
-rw-r--r--extra/resolve_stack_dump.c2
-rw-r--r--extra/resolveip.c2
-rw-r--r--include/my_getopt.h8
-rw-r--r--isam/isamchk.c2
-rw-r--r--isam/pack_isam.c2
-rw-r--r--myisam/mi_test1.c2
-rw-r--r--myisam/myisam_ftdump.c2
-rw-r--r--myisam/myisamchk.c2
-rw-r--r--myisam/myisampack.c2
-rw-r--r--mysys/my_getopt.c48
-rw-r--r--sql/gen_lex_hash.cc2
-rw-r--r--sql/log.cc206
-rw-r--r--sql/mysql_priv.h22
-rw-r--r--sql/mysqld.cc7
-rw-r--r--tools/mysqlmanager.c2
31 files changed, 351 insertions, 72 deletions
diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok
index 3ffbead8d68..cdaa06ecb0e 100644
--- a/BitKeeper/etc/logging_ok
+++ b/BitKeeper/etc/logging_ok
@@ -108,6 +108,7 @@ ram@gw.mysql.r18.ru
ram@mysql.r18.ru
ram@ram.(none)
ranger@regul.home.lan
+rburnett@build.mysql.com
root@x3.internalnet
salle@geopard.(none)
salle@geopard.online.bg
diff --git a/VC++Files/sql/mysqld.dsp b/VC++Files/sql/mysqld.dsp
index 1332b74235f..3198c918a5e 100644
--- a/VC++Files/sql/mysqld.dsp
+++ b/VC++Files/sql/mysqld.dsp
@@ -900,6 +900,89 @@ SOURCE=.\log_event.cpp
# End Source File
# Begin Source File
+SOURCE=.\message.mc
+
+!IF "$(CFG)" == "mysqld - Win32 Release"
+
+!ELSEIF "$(CFG)" == "mysqld - Win32 Debug"
+
+!ELSEIF "$(CFG)" == "mysqld - Win32 nt"
+
+# Begin Custom Build - Compiling messages
+InputDir=.
+InputPath=.\message.mc
+InputName=message
+
+BuildCmds= \
+ mc.exe "$(InputDir)\$(InputName).mc"
+
+"$(InputDir)\$(InputName).rc" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"$(InputDir)\$(InputName).h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "mysqld - Win32 Max nt"
+# Begin Custom Build - Compiling messages
+InputDir=.
+InputPath=.\message.mc
+InputName=message
+
+BuildCmds= \
+ mc.exe "$(InputDir)\$(InputName).mc"
+
+"$(InputDir)\$(InputName).rc" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"$(InputDir)\$(InputName).h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+!ELSEIF "$(CFG)" == "mysqld - Win32 Max"
+
+!ELSEIF "$(CFG)" == "mysqld - Win32 classic"
+
+!ELSEIF "$(CFG)" == "mysqld - Win32 pro"
+
+!ELSEIF "$(CFG)" == "mysqld - Win32 classic nt"
+# Begin Custom Build - Compiling messages
+InputDir=.
+InputPath=.\message.mc
+InputName=message
+
+BuildCmds= \
+ mc.exe "$(InputDir)\$(InputName).mc"
+
+"$(InputDir)\$(InputName).rc" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"$(InputDir)\$(InputName).h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+!ELSEIF "$(CFG)" == "mysqld - Win32 pro nt"
+# Begin Custom Build - Compiling messages
+InputDir=.
+InputPath=.\message.mc
+InputName=message
+
+BuildCmds= \
+ mc.exe "$(InputDir)\$(InputName).mc"
+
+"$(InputDir)\$(InputName).rc" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+
+"$(InputDir)\$(InputName).h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ $(BuildCmds)
+# End Custom Build
+!ENDIF
+
+# End Source File
+# Begin Source File
+
+SOURCE=.\message.rc
+# End Source File
+# Begin Source File
+
SOURCE=.\mf_iocache.cpp
!IF "$(CFG)" == "mysqld - Win32 Release"
diff --git a/client/mysql.cc b/client/mysql.cc
index 66a99bbdf75..72ebfe9cf0c 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -758,7 +758,7 @@ static int get_options(int argc, char **argv)
opt_max_allowed_packet= *mysql_params->p_max_allowed_packet;
opt_net_buffer_length= *mysql_params->p_net_buffer_length;
- if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, 0)))
exit(ho_error);
*mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
diff --git a/client/mysqladmin.c b/client/mysqladmin.c
index 3bc11ec0fb0..e2843685d50 100644
--- a/client/mysqladmin.c
+++ b/client/mysqladmin.c
@@ -254,7 +254,7 @@ int main(int argc,char *argv[])
mysql_init(&mysql);
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)))
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, 0)))
{
free_defaults(save_argv);
exit(ho_error);
diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc
index 7c3d22c4900..93e0b98b1e5 100644
--- a/client/mysqlbinlog.cc
+++ b/client/mysqlbinlog.cc
@@ -559,7 +559,7 @@ static int parse_args(int *argc, char*** argv)
result_file = stdout;
load_defaults("my",load_default_groups,argc,argv);
- if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, NULL)))
exit(ho_error);
return 0;
diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c
index 1c5638f3c52..718b92da466 100644
--- a/client/mysqlcheck.c
+++ b/client/mysqlcheck.c
@@ -273,7 +273,7 @@ static int get_options(int *argc, char ***argv)
load_defaults("my", load_default_groups, argc, argv);
- if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, 0)))
exit(ho_error);
if (!what_to_do)
diff --git a/client/mysqldump.c b/client/mysqldump.c
index 6dad8182b87..c0ef07a7670 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -413,7 +413,7 @@ static int get_options(int *argc, char ***argv)
md_result_file= stdout;
load_defaults("my",load_default_groups,argc,argv);
- if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, 0)))
exit(ho_error);
*mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
diff --git a/client/mysqlimport.c b/client/mysqlimport.c
index ca53b74c119..751379591ff 100644
--- a/client/mysqlimport.c
+++ b/client/mysqlimport.c
@@ -206,7 +206,7 @@ static int get_options(int *argc, char ***argv)
{
int ho_error;
- if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, 0)))
exit(ho_error);
if (enclosed && opt_enclosed)
diff --git a/client/mysqlmanager-pwgen.c b/client/mysqlmanager-pwgen.c
index 57d91b52f49..dc845008ce0 100644
--- a/client/mysqlmanager-pwgen.c
+++ b/client/mysqlmanager-pwgen.c
@@ -95,7 +95,7 @@ int parse_args(int argc, char** argv)
{
int ho_error;
- if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, NULL)))
exit(ho_error);
return 0;
diff --git a/client/mysqlmanagerc.c b/client/mysqlmanagerc.c
index 0001a0266e6..78485427473 100644
--- a/client/mysqlmanagerc.c
+++ b/client/mysqlmanagerc.c
@@ -133,7 +133,7 @@ int parse_args(int argc, char **argv)
load_defaults("my",load_default_groups,&argc,&argv);
default_argv= argv;
- if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, NULL)))
exit(ho_error);
return 0;
diff --git a/client/mysqlshow.c b/client/mysqlshow.c
index 1a9aec02955..cabe55cd95e 100644
--- a/client/mysqlshow.c
+++ b/client/mysqlshow.c
@@ -261,7 +261,7 @@ get_options(int *argc,char ***argv)
{
int ho_error;
- if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, 0)))
exit(ho_error);
if (tty_password)
diff --git a/client/mysqltest.c b/client/mysqltest.c
index 2ec07692a4d..df54b60dc97 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -2062,7 +2062,7 @@ int parse_args(int argc, char **argv)
load_defaults("my",load_default_groups,&argc,&argv);
default_argv= argv;
- if ((handle_options(&argc, &argv, my_long_options, get_one_option)))
+ if ((handle_options(&argc, &argv, my_long_options, get_one_option, 0)))
exit(1);
if (argc > 1)
diff --git a/extra/my_print_defaults.c b/extra/my_print_defaults.c
index f8a7995432b..515e816f473 100644
--- a/extra/my_print_defaults.c
+++ b/extra/my_print_defaults.c
@@ -100,7 +100,7 @@ static int get_options(int *argc,char ***argv)
{
int ho_error;
- if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, NULL)))
exit(ho_error);
if (*argc < 1)
diff --git a/extra/mysql_install.c b/extra/mysql_install.c
index e2783f906b9..ab44e1a055b 100644
--- a/extra/mysql_install.c
+++ b/extra/mysql_install.c
@@ -218,7 +218,7 @@ static int parse_args(int argc, char **argv)
{
int ho_error;
- if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, NULL)))
exit(ho_error);
return 0;
diff --git a/extra/mysql_waitpid.c b/extra/mysql_waitpid.c
index bff1752ec21..9fcabfbb53e 100644
--- a/extra/mysql_waitpid.c
+++ b/extra/mysql_waitpid.c
@@ -66,7 +66,7 @@ int main(int argc, char *argv[])
progname= argv[0];
- if (handle_options(&argc, &argv, my_long_options, get_one_option))
+ if (handle_options(&argc, &argv, my_long_options, get_one_option, NULL))
exit(-1);
if (!argv[0] || !argv[1] || (pid= atoi(argv[0])) <= 0 ||
(t= atoi(argv[1])) <= 0)
diff --git a/extra/perror.c b/extra/perror.c
index b4aeaf00671..212b313ade4 100644
--- a/extra/perror.c
+++ b/extra/perror.c
@@ -145,7 +145,7 @@ static int get_options(int *argc,char ***argv)
{
int ho_error;
- if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, NULL)))
exit(ho_error);
if (!*argc && !print_all_codes)
diff --git a/extra/resolve_stack_dump.c b/extra/resolve_stack_dump.c
index c54f17a186e..8b72ab1d864 100644
--- a/extra/resolve_stack_dump.c
+++ b/extra/resolve_stack_dump.c
@@ -121,7 +121,7 @@ static int parse_args(int argc, char **argv)
{
int ho_error;
- if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, NULL)))
exit(ho_error);
/*
diff --git a/extra/resolveip.c b/extra/resolveip.c
index d3caa9e1d45..23ea34abc42 100644
--- a/extra/resolveip.c
+++ b/extra/resolveip.c
@@ -90,7 +90,7 @@ static int get_options(int *argc,char ***argv)
{
int ho_error;
- if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, NULL)))
exit(ho_error);
if (*argc == 0)
diff --git a/include/my_getopt.h b/include/my_getopt.h
index 11ecc66fac3..01b21951972 100644
--- a/include/my_getopt.h
+++ b/include/my_getopt.h
@@ -50,11 +50,11 @@ struct my_option
extern char *disabled_my_option;
extern my_bool my_getopt_print_errors;
+typedef my_bool (* hoGetOneOption) (int, const struct my_option *, char * );
+typedef void (* hoErrorReporter) (const char *format, va_list args );
+
extern int handle_options (int *argc, char ***argv,
- const struct my_option *longopts,
- my_bool (*get_one_option)(int,
- const struct my_option *,
- char *));
+ const struct my_option *longopts, hoGetOneOption, hoErrorReporter );
extern void my_print_help(const struct my_option *options);
extern void my_print_variables(const struct my_option *options);
diff --git a/isam/isamchk.c b/isam/isamchk.c
index daa9464eb4f..8603b436841 100644
--- a/isam/isamchk.c
+++ b/isam/isamchk.c
@@ -670,7 +670,7 @@ static void get_options(register int *argc, register char ***argv)
if (isatty(fileno(stdout)))
testflag|=T_WRITE_LOOP;
- if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, NULL)))
exit(ho_error);
if (*argc == 0)
diff --git a/isam/pack_isam.c b/isam/pack_isam.c
index b2e21afc743..59594ccc929 100644
--- a/isam/pack_isam.c
+++ b/isam/pack_isam.c
@@ -353,7 +353,7 @@ static void get_options(int *argc, char ***argv)
{
int ho_error;
- if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, NULL)))
exit(ho_error);
my_progname= argv[0][0];
diff --git a/myisam/mi_test1.c b/myisam/mi_test1.c
index 8ea97c8e489..88e6c5c89d3 100644
--- a/myisam/mi_test1.c
+++ b/myisam/mi_test1.c
@@ -643,7 +643,7 @@ static void get_options(int argc, char *argv[])
{
int ho_error;
- if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, NULL)))
exit(ho_error);
return;
diff --git a/myisam/myisam_ftdump.c b/myisam/myisam_ftdump.c
index 838f90feae5..35182bc8abb 100644
--- a/myisam/myisam_ftdump.c
+++ b/myisam/myisam_ftdump.c
@@ -66,7 +66,7 @@ int main(int argc,char *argv[])
struct { MI_INFO *info; } aio0, *aio=&aio0; /* for GWS_IN_USE */
MY_INIT(argv[0]);
- if (error=handle_options(&argc, &argv, my_long_options, get_one_option))
+ if (error=handle_options(&argc, &argv, my_long_options, get_one_option, NULL))
exit(error);
if (count || dump)
verbose=0;
diff --git a/myisam/myisamchk.c b/myisam/myisamchk.c
index 5377ecc18a5..e8e85345897 100644
--- a/myisam/myisamchk.c
+++ b/myisam/myisamchk.c
@@ -677,7 +677,7 @@ static void get_options(register int *argc,register char ***argv)
if (isatty(fileno(stdout)))
check_param.testflag|=T_WRITE_LOOP;
- if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, NULL)))
exit(ho_error);
/* If using repair, then update checksum if one uses --update-state */
diff --git a/myisam/myisampack.c b/myisam/myisampack.c
index 872fcb49faf..51f8ad1bb11 100644
--- a/myisam/myisampack.c
+++ b/myisam/myisampack.c
@@ -350,7 +350,7 @@ static void get_options(int *argc,char ***argv)
if (isatty(fileno(stdout)))
write_loop=1;
- if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option, NULL)))
exit(ho_error);
if (!*argc)
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index 694c4685667..7524bbf318d 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -56,6 +56,19 @@ char *disabled_my_option= (char*) "0";
my_bool my_getopt_print_errors= 1;
+void report_option_error( hoErrorReporter reporter, const char *format, ... )
+{
+ va_list args;
+ va_start( args, format );
+
+
+ if (reporter != NULL)
+ reporter( format, args );
+ else
+ vfprintf( stderr, format, args );
+
+ va_end( args );
+}
/*
function: handle_options
@@ -68,10 +81,7 @@ my_bool my_getopt_print_errors= 1;
*/
int handle_options(int *argc, char ***argv,
- const struct my_option *longopts,
- my_bool (*get_one_option)(int,
- const struct my_option *,
- char *))
+ const struct my_option *longopts, hoGetOneOption get_one_option, hoErrorReporter reporter )
{
uint opt_found, argvpos= 0, length, i;
my_bool end_of_options= 0, must_be_var, set_maximum_value, special_used,
@@ -109,7 +119,7 @@ int handle_options(int *argc, char ***argv,
if (!*++pos)
{
if (my_getopt_print_errors)
- fprintf(stderr, "%s: Option '-O' requires an argument\n",
+ report_option_error(reporter, "%s: Option '-O' requires an argument\n",
progname);
return EXIT_ARGUMENT_REQUIRED;
}
@@ -126,7 +136,7 @@ int handle_options(int *argc, char ***argv,
if (!*cur_arg)
{
if (my_getopt_print_errors)
- fprintf(stderr,
+ report_option_error(reporter,
"%s: Option '--set-variable' requires an argument\n",
progname);
return EXIT_ARGUMENT_REQUIRED;
@@ -140,7 +150,7 @@ int handle_options(int *argc, char ***argv,
if (!*++pos)
{
if (my_getopt_print_errors)
- fprintf(stderr,
+ report_option_error( reporter,
"%s: Option '--set-variable' requires an argument\n",
progname);
return EXIT_ARGUMENT_REQUIRED;
@@ -201,7 +211,7 @@ int handle_options(int *argc, char ***argv,
if (opt_found > 1)
{
if (my_getopt_print_errors)
- fprintf(stderr,
+ report_option_error( reporter,
"%s: ambiguous option '--%s-%s' (--%s-%s)\n",
progname, special_opt_prefix[i], cur_arg,
special_opt_prefix[i], prev_found);
@@ -236,7 +246,7 @@ int handle_options(int *argc, char ***argv,
if (must_be_var)
{
if (my_getopt_print_errors)
- fprintf(stderr,
+ report_option_error( reporter,
"%s: %s: unknown variable '%s'\n", progname,
option_is_loose ? "WARNING" : "ERROR", cur_arg);
if (!option_is_loose)
@@ -245,7 +255,7 @@ int handle_options(int *argc, char ***argv,
else
{
if (my_getopt_print_errors)
- fprintf(stderr,
+ report_option_error( reporter,
"%s: %s: unknown option '--%s'\n", progname,
option_is_loose ? "WARNING" : "ERROR", cur_arg);
if (!option_is_loose)
@@ -263,14 +273,14 @@ int handle_options(int *argc, char ***argv,
if (must_be_var)
{
if (my_getopt_print_errors)
- fprintf(stderr, "%s: variable prefix '%s' is not unique\n",
+ report_option_error( reporter, "%s: variable prefix '%s' is not unique\n",
progname, cur_arg);
return EXIT_VAR_PREFIX_NOT_UNIQUE;
}
else
{
if (my_getopt_print_errors)
- fprintf(stderr, "%s: ambiguous option '--%s' (%s, %s)\n",
+ report_option_error( reporter, "%s: ambiguous option '--%s' (%s, %s)\n",
progname, cur_arg, prev_found, optp->name);
return EXIT_AMBIGUOUS_OPTION;
}
@@ -278,7 +288,7 @@ int handle_options(int *argc, char ***argv,
if (must_be_var && optp->var_type == GET_NO_ARG)
{
if (my_getopt_print_errors)
- fprintf(stderr, "%s: option '%s' cannot take an argument\n",
+ report_option_error( reporter, "%s: option '%s' cannot take an argument\n",
progname, optp->name);
return EXIT_NO_ARGUMENT_ALLOWED;
}
@@ -287,7 +297,7 @@ int handle_options(int *argc, char ***argv,
if (optend && optp->var_type != GET_BOOL)
{
if (my_getopt_print_errors)
- fprintf(stderr, "%s: option '--%s' cannot take an argument\n",
+ report_option_error( reporter, "%s: option '--%s' cannot take an argument\n",
progname, optp->name);
return EXIT_NO_ARGUMENT_ALLOWED;
}
@@ -325,7 +335,7 @@ int handle_options(int *argc, char ***argv,
if (!*++pos)
{
if (my_getopt_print_errors)
- fprintf(stderr, "%s: option '--%s' requires an argument\n",
+ report_option_error( reporter, "%s: option '--%s' requires an argument\n",
progname, optp->name);
return EXIT_ARGUMENT_REQUIRED;
}
@@ -375,7 +385,7 @@ int handle_options(int *argc, char ***argv,
if (!pos[1])
{
if (my_getopt_print_errors)
- fprintf(stderr,
+ report_option_error( reporter,
"%s: option '-%c' requires an argument\n",
progname, optp->id);
return EXIT_ARGUMENT_REQUIRED;
@@ -387,7 +397,7 @@ int handle_options(int *argc, char ***argv,
}
if ((error= setval(optp, argument, set_maximum_value)))
{
- fprintf(stderr,
+ report_option_error( reporter,
"%s: Error while setting value '%s' to '%s'\n",
progname, argument, optp->name);
return error;
@@ -399,7 +409,7 @@ int handle_options(int *argc, char ***argv,
if (!opt_found)
{
if (my_getopt_print_errors)
- fprintf(stderr,
+ report_option_error( reporter,
"%s: unknown option '-%c'\n", progname, *optend);
return EXIT_UNKNOWN_OPTION;
}
@@ -409,7 +419,7 @@ int handle_options(int *argc, char ***argv,
}
if ((error= setval(optp, argument, set_maximum_value)))
{
- fprintf(stderr,
+ report_option_error( reporter,
"%s: Error while setting value '%s' to '%s'\n",
progname, argument, optp->name);
return error;
diff --git a/sql/gen_lex_hash.cc b/sql/gen_lex_hash.cc
index 1f604659272..72ab1184533 100644
--- a/sql/gen_lex_hash.cc
+++ b/sql/gen_lex_hash.cc
@@ -384,7 +384,7 @@ static int get_options(int argc, char **argv)
{
int ho_error;
- if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, 0)))
exit(ho_error);
if (argc >= 1)
diff --git a/sql/log.cc b/sql/log.cc
index e031656cc6e..3d76f9d5634 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -31,12 +31,51 @@
#include <m_ctype.h> // For test_if_number
#include <assert.h>
+#ifdef __NT__
+#include "message.h"
+#endif
+
MYSQL_LOG mysql_log,mysql_update_log,mysql_slow_log,mysql_bin_log;
extern I_List<i_string> binlog_do_db, binlog_ignore_db;
static bool test_if_number(const char *str,
long *res, bool allow_wildcards);
+#ifdef __NT__
+static int eventSource = 0;
+void setupWindowsEventSource()
+{
+ if (eventSource) return;
+
+ eventSource = 1;
+ HKEY hRegKey = NULL;
+ DWORD dwError = 0;
+ TCHAR szPath[ MAX_PATH ];
+
+ // Create the event source registry key
+ dwError = RegCreateKey( HKEY_LOCAL_MACHINE,
+ "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\MySQL",
+ &hRegKey );
+
+ // Name of the PE module that contains the message resource
+ GetModuleFileName( NULL, szPath, MAX_PATH );
+
+ // Register EventMessageFile
+ dwError = RegSetValueEx( hRegKey, "EventMessageFile", 0, REG_EXPAND_SZ,
+ (PBYTE) szPath, strlen(szPath)+1 );
+
+
+ // Register supported event types
+ DWORD dwTypes = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
+ dwError = RegSetValueEx( hRegKey, "TypesSupported", 0, REG_DWORD,
+ (LPBYTE) &dwTypes, sizeof dwTypes );
+
+ RegCloseKey( hRegKey );
+}
+
+#endif
+
+
/****************************************************************************
** Find a uniq filename for 'filename.#'.
** Set # to a number as low as possible
@@ -1677,41 +1716,42 @@ static bool test_if_number(register const char *str,
} /* test_if_number */
-void sql_print_error(const char *format,...)
+void print_buffer_to_log( my_bool timestamp, const char *buffer )
{
- va_list args;
time_t skr;
struct tm tm_tmp;
struct tm *start;
- va_start(args,format);
- DBUG_ENTER("sql_print_error");
+ DBUG_ENTER("sql_print_buffer_to_log");
+
+#if !defined(__WIN__) && !defined(__NT__)
VOID(pthread_mutex_lock(&LOCK_error_log));
-#ifndef DBUG_OFF
- {
- char buff[1024];
- my_vsnprintf(buff,sizeof(buff)-1,format,args);
- DBUG_PRINT("error",("%s",buff));
- va_end(args);
- va_start(args,format);
- }
#endif
- skr=time(NULL);
- localtime_r(&skr,&tm_tmp);
- start=&tm_tmp;
- fprintf(stderr,"%02d%02d%02d %2d:%02d:%02d ",
- start->tm_year % 100,
- start->tm_mon+1,
+
+ if (timestamp)
+ {
+ skr=time(NULL);
+ localtime_r(&skr, &tm_tmp);
+ start=&tm_tmp;
+ fprintf( stderr, "%02d%02d%02d %2d:%02d:%02d %s",
+ start->tm_year % 100,
+ start->tm_mon+1,
start->tm_mday,
start->tm_hour,
start->tm_min,
- start->tm_sec);
- (void) vfprintf(stderr,format,args);
- (void) fputc('\n',stderr);
+ start->tm_sec,
+ buffer );
+ }
+ else
+ fprintf( stderr, "%s", buffer );
+
+ fputc('\n', stderr);
fflush(stderr);
- va_end(args);
+#if !defined(__WIN__) && !defined(__NT__)
VOID(pthread_mutex_unlock(&LOCK_error_log));
+#endif
+
DBUG_VOID_RETURN;
}
@@ -1770,3 +1810,125 @@ bool flush_error_log()
}
return result;
}
+
+/**
+ * prints a printf style message to the error log and, under NT, to the Windows event log.
+ * @param event_type type of even to log.
+ * @param timestamp true to add a timestamp to the entry, false otherwise.
+ * @param format The printf style format of the message
+ * @param ... values for the message
+ * @return void
+*/
+void print_msg_to_log( long event_type, my_bool timestamp, const char *format, ... )
+{
+ va_list args;
+
+ DBUG_ENTER("startup_print_msg_to_logo");
+
+ va_start( args, format );
+ vprint_msg_to_log( event_type, timestamp, format, args );
+ va_end( args );
+
+ DBUG_VOID_RETURN;
+}
+
+/**
+ * prints a printf style message to the error log and, under NT, to the Windows event log.
+ * @param event_type type of even to log.
+ * @param timestamp true to add a timestamp to the entry, false otherwise.
+ * @param format The printf style format of the message
+ * @param args va_list prepped arument list
+ * @return void
+*/
+void vprint_msg_to_log(long event_type, my_bool timestamp, const char *format, va_list args)
+{
+ char buff[1024];
+
+ DBUG_ENTER("startup_vprint_msg_to_log");
+
+ my_vsnprintf( buff, sizeof(buff)-5, format, args );
+
+ print_buffer_to_log( timestamp, buff );
+
+#ifndef DBUG_OFF
+ DBUG_PRINT("error",("%s",buff));
+#endif
+
+#ifdef __NT__
+ HANDLE event;
+ LPSTR buffptr;
+
+ strcat( buff, "\r\n\r\n" );
+ buffptr = (LPSTR)&buff;
+ setupWindowsEventSource();
+ if (event = RegisterEventSource(NULL,"MySQL"))
+ {
+ switch (event_type){
+ case MY_ERROR_TYPE:
+ ReportEvent(event, (WORD)event_type, 0, MSG_DEFAULT, NULL, 1, 0, (LPCSTR*)&buffptr, NULL);
+ break;
+ case MY_WARNING_TYPE:
+ ReportEvent(event, (WORD)event_type, 0, MSG_DEFAULT, NULL, 1, 0, (LPCSTR*)&buffptr, NULL);
+ break;
+ case MY_INFORMATION_TYPE:
+ ReportEvent(event, (WORD)event_type, 0, MSG_DEFAULT, NULL, 1, 0, (LPCSTR*)&buffptr, NULL);
+ break;
+ }
+ DeregisterEventSource(event);
+ }
+#endif
+ DBUG_VOID_RETURN;
+}
+
+void sql_print_error( const char *format, ... )
+{
+ DBUG_ENTER( "startup_sql_print_error" );
+
+ va_list args;
+ va_start( args, format );
+ print_msg_to_log( MY_ERROR_TYPE, true, format, args );
+ va_end( args );
+
+ DBUG_VOID_RETURN;
+}
+
+void sql_print_warning( const char *format, ... )
+{
+ DBUG_ENTER( "startup_sql_print_warning" );
+
+ va_list args;
+ va_start( args, format );
+ print_msg_to_log( MY_WARNING_TYPE, true, format, args );
+ va_end( args );
+
+ DBUG_VOID_RETURN;
+}
+
+void sql_print_information( const char *format, ... )
+{
+ DBUG_ENTER( "startup_sql_print_information" );
+
+ va_list args;
+ va_start( args, format );
+ print_msg_to_log( MY_INFORMATION_TYPE, true, format, args );
+ va_end( args );
+
+ DBUG_VOID_RETURN;
+}
+
+/*void sql_init_fprintf(const char *format,...)
+{
+ va_list args;
+ char buff[255];
+ buff[0]= 0;
+ va_start(args,format);
+ my_vsnprintf(buff,sizeof(buff)-1,format,args);
+#ifdef __NT__
+ sql_nt_print_error(MY_ERROR_TYPE,buff);
+#else
+ sql_win_print_error(buff);
+#endif
+ va_end(args);
+}
+*/
+
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 2e893ead407..1bc6544b72e 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -639,9 +639,27 @@ void key_unpack(String *to,TABLE *form,uint index);
bool check_if_key_used(TABLE *table, uint idx, List<Item> &fields);
void init_errmessage(void);
+void vprint_msg_to_log( long errType, my_bool timestamp, const char *format, va_list args );
+void print_msg_to_log( long errType, my_bool timestamp, const char *format, ... );
void sql_perror(const char *message);
-void sql_print_error(const char *format,...)
- __attribute__ ((format (printf, 1, 2)));
+ /* __attribute__ ((format (printf, 1, 2)));
+*/
+
+#define MY_ERROR_TYPE 0x0001
+#define MY_WARNING_TYPE 0x0002
+#define MY_INFORMATION_TYPE 0x0004
+
+/*void sql_init_perror(const char *message);*/
+/*void sql_fprintf(const char *format,...)
+ __attribute__ ((format (printf, 1, 2)));*/
+
+/*#define sql_fprintf(format, args...) fprintf (stderr, format, ##args) */
+void sql_print_error( const char *format, ... );
+void sql_print_warning( const char *format, ...);
+void sql_print_information( const char *format, ...);
+
+
+
bool fn_format_relative_to_data_home(my_string to, const char *name,
const char *dir, const char *extension);
bool open_log(MYSQL_LOG *log, const char *hostname,
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 3f7c187ccdd..9191759b2d2 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -5095,11 +5095,16 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
}
/* Initiates DEBUG - but no debugging here ! */
+void option_error_reporter( const char *format, va_list args )
+{
+ vprint_msg_to_log( MY_ERROR_TYPE, false, format, args );
+}
+
static void get_options(int argc,char **argv)
{
int ho_error;
- if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, option_error_reporter )))
exit(ho_error);
#if defined(HAVE_BROKEN_REALPATH)
diff --git a/tools/mysqlmanager.c b/tools/mysqlmanager.c
index ade6da895c6..12b5519ae9c 100644
--- a/tools/mysqlmanager.c
+++ b/tools/mysqlmanager.c
@@ -1333,7 +1333,7 @@ static int parse_args(int argc, char **argv)
{
int ho_error;
- if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
+ if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option, NULL)))
exit(ho_error);
return 0;