From 767d880f9c641746ed0087c4a2395e2a66d43374 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 14 Aug 2004 03:38:37 +0200 Subject: 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 --- mysys/my_getopt.c | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'mysys/my_getopt.c') 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; -- cgit v1.2.1 From 4736e7d4bdcde029923518826db33da6a38a6c01 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 18 Aug 2004 22:31:01 +0200 Subject: BUG# 4466 - Nothing in .err when mysql service ends because of malformed my.ini options mysqld.cc: Changed option_error_reporter to match new function header that includes LOGLEVEL enum mysql_priv.h: Removed the MY_ERROR style bitmask. Changed function headers to use new LOGLEVEL enum log.cc: Changed print_buffer_to_log to print_buffer_to_file. Remove the timestamp bool and now all log entries written to stderr are timestamped. Removed some unused commented code. changed to use the new LOGLEVEL enum. my_getopt.c: Changed functions to use the new LOGLEVEL enum and changed the included error reporter to be default_reporter. This reporter is used in handle_options if a reporter is not given my_getopt.h: changed typedefs to use better naming convention. Moved error bitmask into the LOGLEVEL enum and included it here. include/my_getopt.h: changed typedefs to use better naming convention. Moved error bitmask into the LOGLEVEL enum and included it here. mysys/my_getopt.c: Changed functions to use the new LOGLEVEL enum and changed the included error reporter to be default_reporter. This reporter is used in handle_options if a reporter is not given sql/log.cc: Changed print_buffer_to_log to print_buffer_to_file. Remove the timestamp bool and now all log entries written to stderr are timestamped. Removed some unused commented code. changed to use the new LOGLEVEL enum. sql/mysql_priv.h: Removed the MY_ERROR style bitmask. Changed function headers to use new LOGLEVEL enum sql/mysqld.cc: Changed option_error_reporter to match new function header that includes LOGLEVEL enum --- mysys/my_getopt.c | 56 +++++++++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 33 deletions(-) (limited to 'mysys/my_getopt.c') diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 7524bbf318d..4bb9a79e299 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -56,17 +56,11 @@ char *disabled_my_option= (char*) "0"; my_bool my_getopt_print_errors= 1; -void report_option_error( hoErrorReporter reporter, const char *format, ... ) +void default_reporter( enum LOGLEVEL level, const char *format, ... ) { va_list args; va_start( args, format ); - - - if (reporter != NULL) - reporter( format, args ); - else - vfprintf( stderr, format, args ); - + vfprintf( stderr, format, args ); va_end( args ); } @@ -81,7 +75,8 @@ void report_option_error( hoErrorReporter reporter, const char *format, ... ) */ int handle_options(int *argc, char ***argv, - const struct my_option *longopts, hoGetOneOption get_one_option, hoErrorReporter reporter ) + const struct my_option *longopts, my_get_one_option get_one_option, + my_error_reporter reporter ) { uint opt_found, argvpos= 0, length, i; my_bool end_of_options= 0, must_be_var, set_maximum_value, special_used, @@ -95,6 +90,8 @@ int handle_options(int *argc, char ***argv, (*argv)++; /* --- || ---- */ init_variables(longopts); + if (! reporter) reporter = &default_reporter; + for (pos= *argv, pos_end=pos+ *argc; pos != pos_end ; pos++) { char *cur_arg= *pos; @@ -119,8 +116,7 @@ int handle_options(int *argc, char ***argv, if (!*++pos) { if (my_getopt_print_errors) - report_option_error(reporter, "%s: Option '-O' requires an argument\n", - progname); + reporter( ERROR_LEVEL, "%s: Option '-O' requires an argument\n", progname ); return EXIT_ARGUMENT_REQUIRED; } cur_arg= *pos; @@ -136,9 +132,7 @@ int handle_options(int *argc, char ***argv, if (!*cur_arg) { if (my_getopt_print_errors) - report_option_error(reporter, - "%s: Option '--set-variable' requires an argument\n", - progname); + reporter( ERROR_LEVEL, "%s: Option '--set-variable' requires an argument\n", progname ); return EXIT_ARGUMENT_REQUIRED; } } @@ -150,9 +144,7 @@ int handle_options(int *argc, char ***argv, if (!*++pos) { if (my_getopt_print_errors) - report_option_error( reporter, - "%s: Option '--set-variable' requires an argument\n", - progname); + reporter( ERROR_LEVEL, "%s: Option '--set-variable' requires an argument\n", progname ); return EXIT_ARGUMENT_REQUIRED; } cur_arg= *pos; @@ -211,7 +203,7 @@ int handle_options(int *argc, char ***argv, if (opt_found > 1) { if (my_getopt_print_errors) - report_option_error( reporter, + reporter( ERROR_LEVEL, "%s: ambiguous option '--%s-%s' (--%s-%s)\n", progname, special_opt_prefix[i], cur_arg, special_opt_prefix[i], prev_found); @@ -246,18 +238,16 @@ int handle_options(int *argc, char ***argv, if (must_be_var) { if (my_getopt_print_errors) - report_option_error( reporter, - "%s: %s: unknown variable '%s'\n", progname, - option_is_loose ? "WARNING" : "ERROR", cur_arg); + reporter( option_is_loose ? WARNING_LEVEL : ERROR_LEVEL, + "%s: unknown variable '%s'\n", progname, cur_arg ); if (!option_is_loose) return EXIT_UNKNOWN_VARIABLE; } else { if (my_getopt_print_errors) - report_option_error( reporter, - "%s: %s: unknown option '--%s'\n", progname, - option_is_loose ? "WARNING" : "ERROR", cur_arg); + reporter( option_is_loose ? WARNING_LEVEL : ERROR_LEVEL, + "%s: unknown option '--%s'\n", progname, cur_arg ); if (!option_is_loose) return EXIT_UNKNOWN_OPTION; } @@ -273,14 +263,14 @@ int handle_options(int *argc, char ***argv, if (must_be_var) { if (my_getopt_print_errors) - report_option_error( reporter, "%s: variable prefix '%s' is not unique\n", + reporter( ERROR_LEVEL, "%s: variable prefix '%s' is not unique\n", progname, cur_arg); return EXIT_VAR_PREFIX_NOT_UNIQUE; } else { if (my_getopt_print_errors) - report_option_error( reporter, "%s: ambiguous option '--%s' (%s, %s)\n", + reporter( ERROR_LEVEL, "%s: ambiguous option '--%s' (%s, %s)\n", progname, cur_arg, prev_found, optp->name); return EXIT_AMBIGUOUS_OPTION; } @@ -288,7 +278,7 @@ int handle_options(int *argc, char ***argv, if (must_be_var && optp->var_type == GET_NO_ARG) { if (my_getopt_print_errors) - report_option_error( reporter, "%s: option '%s' cannot take an argument\n", + reporter( ERROR_LEVEL, "%s: option '%s' cannot take an argument\n", progname, optp->name); return EXIT_NO_ARGUMENT_ALLOWED; } @@ -297,7 +287,7 @@ int handle_options(int *argc, char ***argv, if (optend && optp->var_type != GET_BOOL) { if (my_getopt_print_errors) - report_option_error( reporter, "%s: option '--%s' cannot take an argument\n", + reporter( ERROR_LEVEL, "%s: option '--%s' cannot take an argument\n", progname, optp->name); return EXIT_NO_ARGUMENT_ALLOWED; } @@ -335,7 +325,7 @@ int handle_options(int *argc, char ***argv, if (!*++pos) { if (my_getopt_print_errors) - report_option_error( reporter, "%s: option '--%s' requires an argument\n", + reporter( ERROR_LEVEL, "%s: option '--%s' requires an argument\n", progname, optp->name); return EXIT_ARGUMENT_REQUIRED; } @@ -385,7 +375,7 @@ int handle_options(int *argc, char ***argv, if (!pos[1]) { if (my_getopt_print_errors) - report_option_error( reporter, + reporter( ERROR_LEVEL, "%s: option '-%c' requires an argument\n", progname, optp->id); return EXIT_ARGUMENT_REQUIRED; @@ -397,7 +387,7 @@ int handle_options(int *argc, char ***argv, } if ((error= setval(optp, argument, set_maximum_value))) { - report_option_error( reporter, + reporter( ERROR_LEVEL, "%s: Error while setting value '%s' to '%s'\n", progname, argument, optp->name); return error; @@ -409,7 +399,7 @@ int handle_options(int *argc, char ***argv, if (!opt_found) { if (my_getopt_print_errors) - report_option_error( reporter, + reporter( ERROR_LEVEL, "%s: unknown option '-%c'\n", progname, *optend); return EXIT_UNKNOWN_OPTION; } @@ -419,7 +409,7 @@ int handle_options(int *argc, char ***argv, } if ((error= setval(optp, argument, set_maximum_value))) { - report_option_error( reporter, + reporter( ERROR_LEVEL, "%s: Error while setting value '%s' to '%s'\n", progname, argument, optp->name); return error; -- cgit v1.2.1 From 87bce8540c7c38cb88ce8743b8efcb0a51f53bfe Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 19 Aug 2004 17:56:32 +0200 Subject: Bug #4466 Nothing in .err when mysql service ends because of malformed my.ini options mysqld.cc: Changed LOGLEVEL enum to loglevel mysql_priv.h, log.cc: Changed LOGLEVEL to loglevel. Removed startup_ from some of the DBUG_ENTER macros. Removed the print_msg_to_log function as it was unused. my_getopt.c, my_getopt.h: Renamed LOGLEVEL to loglevel to match coding standards include/my_getopt.h: Renamed LOGLEVEL to loglevel to match coding standards mysys/my_getopt.c: Renamed LOGLEVEL to loglevel to match coding standards sql/log.cc: Changed LOGLEVEL to loglevel. Removed startup_ from some of the DBUG_ENTER macros. Removed the print_msg_to_log function as it was unused. sql/mysql_priv.h: Changed LOGLEVEL to loglevel. Removed startup_ from some of the DBUG_ENTER macros. Removed the print_msg_to_log function as it was unused. sql/mysqld.cc: Changed LOGLEVEL enum to loglevel --- mysys/my_getopt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mysys/my_getopt.c') diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 4bb9a79e299..91671fcff5b 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -56,7 +56,7 @@ char *disabled_my_option= (char*) "0"; my_bool my_getopt_print_errors= 1; -void default_reporter( enum LOGLEVEL level, const char *format, ... ) +void default_reporter( enum loglevel level, const char *format, ... ) { va_list args; va_start( args, format ); -- cgit v1.2.1 From f2ef3d162eaf16bac68b7bc602be83cc7acf4f74 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 19 Aug 2004 20:26:00 +0200 Subject: Bug #4466 Nothing in .err when mysql service ends because of malformed my.ini options my_getopt.c: Moved the inclusion of my_getopt.h down below the inclusion of my_sys.h so that enum loglevel definition would be available my_sys.h, my_getopt.h: moved definition of enum loglevel from my_getopt.h to my_sys.h include/my_getopt.h: moved definition of enum loglevel from my_getopt.h to my_sys.h include/my_sys.h: moved definition of enum loglevel from my_getopt.h to my_sys.h mysys/my_getopt.c: Moved the inclusion of my_getopt.h down below the inclusion of my_sys.h so that enum loglevel definition would be available --- mysys/my_getopt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mysys/my_getopt.c') diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 91671fcff5b..c471a30eb35 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -17,10 +17,10 @@ #include #include #include -#include #include #include #include +#include static int findopt(char *optpat, uint length, const struct my_option **opt_res, -- cgit v1.2.1