Commit 4736e7d4 authored by unknown's avatar unknown

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
parent 767d880f
......@@ -14,6 +14,9 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifndef _my_getopt_h
#define _my_getopt_h
C_MODE_START
#define GET_NO_ARG 1
......@@ -50,14 +53,25 @@ 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 );
enum LOGLEVEL {
ERROR_LEVEL,
WARNING_LEVEL,
INFORMATION_LEVEL
};
typedef my_bool (* my_get_one_option) (int, const struct my_option *, char * );
typedef void (* my_error_reporter) (enum LOGLEVEL level, const char *format, ... );
extern int handle_options (int *argc, char ***argv,
const struct my_option *longopts, hoGetOneOption, hoErrorReporter );
const struct my_option *longopts, my_get_one_option,
my_error_reporter );
extern void my_print_help(const struct my_option *options);
extern void my_print_variables(const struct my_option *options);
ulonglong getopt_ull_limit_value(ulonglong num, const struct my_option *optp);
my_bool getopt_compare_strings(const char *s, const char *t, uint length);
C_MODE_END
#endif /* _my_getopt_h */
......@@ -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;
......
......@@ -1716,41 +1716,32 @@ static bool test_if_number(register const char *str,
} /* test_if_number */
void print_buffer_to_log( my_bool timestamp, const char *buffer )
void print_buffer_to_file( enum LOGLEVEL level, const char *buffer )
{
time_t skr;
struct tm tm_tmp;
struct tm *start;
DBUG_ENTER("sql_print_buffer_to_log");
DBUG_ENTER("startup_print_buffer_to_log");
#if !defined(__WIN__) && !defined(__NT__)
VOID(pthread_mutex_lock(&LOCK_error_log));
#endif
if (timestamp)
{
skr=time(NULL);
localtime_r(&skr, &tm_tmp);
start=&tm_tmp;
fprintf( stderr, "%02d%02d%02d %2d:%02d:%02d %s",
skr=time(NULL);
localtime_r(&skr, &tm_tmp);
start=&tm_tmp;
fprintf( stderr, "%02d%02d%02d %2d:%02d:%02d [%s] %s\n",
start->tm_year % 100,
start->tm_mon+1,
start->tm_mday,
start->tm_hour,
start->tm_min,
start->tm_sec,
level == ERROR_LEVEL ? "ERROR" : level == WARNING_LEVEL ? "WARNING" : "INFORMATION",
buffer );
}
else
fprintf( stderr, "%s", buffer );
fputc('\n', stderr);
fflush(stderr);
#if !defined(__WIN__) && !defined(__NT__)
VOID(pthread_mutex_unlock(&LOCK_error_log));
#endif
DBUG_VOID_RETURN;
}
......@@ -1819,28 +1810,82 @@ bool flush_error_log()
* @param ... values for the message
* @return void
*/
void print_msg_to_log( long event_type, my_bool timestamp, const char *format, ... )
void print_msg_to_log( LOGLEVEL level, const char *format, ... )
{
va_list args;
DBUG_ENTER("startup_print_msg_to_logo");
DBUG_ENTER("startup_print_msg_to_log");
va_start( args, format );
vprint_msg_to_log( event_type, timestamp, format, args );
vprint_msg_to_log( level, 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
#ifdef __NT__
void print_buffer_to_nt_eventlog( enum LOGLEVEL level, char *buff, int buffLen )
{
HANDLE event;
char *buffptr;
LPCSTR *buffmsgptr;
buffptr = buff;
if (strlen(buff) > (uint)(buffLen-4))
{
char *newBuff = new char[ strlen(buff) + 4 ];
strcpy( newBuff, buff );
buffptr = newBuff;
}
strcat( buffptr, "\r\n\r\n" );
buffmsgptr = (LPCSTR*)&buffptr;
setupWindowsEventSource();
if (event = RegisterEventSource(NULL,"MySQL"))
{
switch (level){
case ERROR_LEVEL:
ReportEvent(event, EVENTLOG_ERROR_TYPE, 0, MSG_DEFAULT, NULL, 1, 0, buffmsgptr, NULL);
break;
case WARNING_LEVEL:
ReportEvent(event, EVENTLOG_WARNING_TYPE, 0, MSG_DEFAULT, NULL, 1, 0, buffmsgptr, NULL);
break;
case INFORMATION_LEVEL:
ReportEvent(event, EVENTLOG_INFORMATION_TYPE, 0, MSG_DEFAULT, NULL, 1, 0, buffmsgptr, NULL);
break;
}
DeregisterEventSource(event);
}
// if we created a string buffer, then delete it
if ( buffptr != buff )
delete[] buffptr;
DBUG_VOID_RETURN;
}
#endif
/*
Prints a printf style message to the error log and, under NT, to the Windows event log.
SYNOPSIS
vprint_msg_to_log()
event_type Type of event to write (Error, Warning, or Info)
format Printf style format of message
args va_list list of arguments for the message
NOTE
IMPLEMENTATION
This function prints the message into a buffer and then sends that buffer to other
functions to write that message to other logging sources.
RETURN VALUES
void
*/
void vprint_msg_to_log(long event_type, my_bool timestamp, const char *format, va_list args)
void vprint_msg_to_log(enum LOGLEVEL level, const char *format, va_list args)
{
char buff[1024];
......@@ -1848,45 +1893,27 @@ void vprint_msg_to_log(long event_type, my_bool timestamp, const char *format, v
my_vsnprintf( buff, sizeof(buff)-5, format, args );
print_buffer_to_log( timestamp, buff );
print_buffer_to_file( level, 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);
}
print_buffer_to_nt_eventlog( level, buff, sizeof(buff) );
#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 );
print_msg_to_log( ERROR_LEVEL, format, args );
va_end( args );
DBUG_VOID_RETURN;
......@@ -1898,7 +1925,7 @@ void sql_print_warning( const char *format, ... )
va_list args;
va_start( args, format );
print_msg_to_log( MY_WARNING_TYPE, true, format, args );
print_msg_to_log( WARNING_LEVEL, format, args );
va_end( args );
DBUG_VOID_RETURN;
......@@ -1910,25 +1937,8 @@ void sql_print_information( const char *format, ... )
va_list args;
va_start( args, format );
print_msg_to_log( MY_INFORMATION_TYPE, true, format, args );
print_msg_to_log( INFORMATION_LEVEL, 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);
}
*/
......@@ -24,6 +24,7 @@
#include <thr_lock.h>
#include <my_base.h> /* Needed by field.h */
#include <my_bitmap.h>
#include <my_getopt.h>
#ifdef __EMX__
#undef write /* remove pthread.h macro definition for EMX */
......@@ -639,21 +640,10 @@ 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 vprint_msg_to_log( enum LOGLEVEL level, const char *format, va_list args );
void print_msg_to_log( enum LOGLEVEL level, const char *format, ... );
void sql_perror(const char *message);
/* __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, ...);
......
......@@ -5095,9 +5095,12 @@ 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 )
void option_error_reporter( enum LOGLEVEL level, const char *format, ... )
{
vprint_msg_to_log( MY_ERROR_TYPE, false, format, args );
va_list args;
va_start( args, format );
vprint_msg_to_log( level, format, args );
va_end( args );
}
static void get_options(int argc,char **argv)
......
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