diff options
author | unknown <monty@mysql.com> | 2004-08-28 00:49:54 +0300 |
---|---|---|
committer | unknown <monty@mysql.com> | 2004-08-28 00:49:54 +0300 |
commit | d15fefa95f31481cf48eaa1108792945ebc96acb (patch) | |
tree | d8470cb550581be2d6ffbc160a5a1b2b1b17a399 /sql/log.cc | |
parent | 2fddfe2ff1650e6a3689ccd9b9c1a69c5dde31cf (diff) | |
download | mariadb-git-d15fefa95f31481cf48eaa1108792945ebc96acb.tar.gz |
Code style fixes.
Initialize LOG_error_log before get_options to not use an uninitalized mutex in case of an error from handle_options()
mysql-test/r/lowercase_table.result:
Changed foo database -> mysqltest
More test cases
mysql-test/t/lowercase_table.test:
Changed foo database -> mysqltest
More test cases
mysys/my_getopt.c:
Fix new code to use MySQL indentation style
sql/log.cc:
Change to use MySQL indentation style and naming conventions
Remove usage of strlen() and strcat()
sql/mysqld.cc:
Initialize LOG_error_log before get_options to not use an uninitalized mutex in case of an error from handle_options()
sql/sql_base.cc:
Added comment
sql/table.cc:
Added #if MYSQL_VERSION_ID < 40100 to ensure code is merged correctly
Diffstat (limited to 'sql/log.cc')
-rw-r--r-- | sql/log.cc | 171 |
1 files changed, 89 insertions, 82 deletions
diff --git a/sql/log.cc b/sql/log.cc index db7b80eb4f7..e9dd2e4a69b 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -43,37 +43,41 @@ static bool test_if_number(const char *str, #ifdef __NT__ static int eventSource = 0; -void setupWindowsEventSource() -{ - if (eventSource) return; - eventSource = 1; - HKEY hRegKey = NULL; - DWORD dwError = 0; - TCHAR szPath[ MAX_PATH ]; +void setup_windows_event_source() +{ + HKEY hRegKey= NULL; + DWORD dwError= 0; + TCHAR szPath[MAX_PATH]; + DWORD dwTypes; - // Create the event source registry key - dwError = RegCreateKey( HKEY_LOCAL_MACHINE, - "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\MySQL", - &hRegKey ); + if (eventSource) // Ensure that we are only called once + return; + eventSource= 1; - // Name of the PE module that contains the message resource - GetModuleFileName( NULL, szPath, MAX_PATH ); + // Create the event source registry key + dwError= RegCreateKey(HKEY_LOCAL_MACHINE, + "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\MySQL", + &hRegKey); - // Register EventMessageFile - dwError = RegSetValueEx( hRegKey, "EventMessageFile", 0, REG_EXPAND_SZ, - (PBYTE) szPath, strlen(szPath)+1 ); + /* 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 ); + /* Register supported event types */ + dwTypes= (EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | + EVENTLOG_INFORMATION_TYPE); + dwError= RegSetValueEx(hRegKey, "TypesSupported", 0, REG_DWORD, + (LPBYTE) &dwTypes, sizeof dwTypes); - RegCloseKey( hRegKey ); + RegCloseKey(hRegKey); } -#endif +#endif /* __NT__ */ /**************************************************************************** @@ -1732,33 +1736,33 @@ static bool test_if_number(register const char *str, } /* test_if_number */ -void print_buffer_to_file( enum loglevel level, 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("print_buffer_to_log"); + DBUG_ENTER("print_buffer_to_file"); + DBUG_PRINT("enter",("buffer: %s", buffer)); VOID(pthread_mutex_lock(&LOCK_error_log)); skr=time(NULL); localtime_r(&skr, &tm_tmp); start=&tm_tmp; - fprintf( stderr, "%02d%02d%02d %2d:%02d:%02d [%s] %s\n", + 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 ); + (level == ERROR_LEVEL ? "ERROR" : level == WARNING_LEVEL ? + "WARNING" : "INFORMATION"), + buffer); fflush(stderr); VOID(pthread_mutex_unlock(&LOCK_error_log)); - DBUG_VOID_RETURN; } @@ -1772,6 +1776,7 @@ void sql_perror(const char *message) #endif } + bool flush_error_log() { bool result=0; @@ -1820,122 +1825,124 @@ bool flush_error_log() #ifdef __NT__ -void print_buffer_to_nt_eventlog( enum loglevel level, char *buff, int buffLen ) +void print_buffer_to_nt_eventlog(enum loglevel level, char *buff, + uint length, int buffLen) { HANDLE event; char *buffptr; LPCSTR *buffmsgptr; + DBUG_ENTER("print_buffer_to_nt_eventlog"); - DBUG_ENTER( "print_buffer_to_nt_eventlog" ); - - buffptr = buff; - if (strlen(buff) > (uint)(buffLen-4)) + buffptr= buff; + if (length > (uint)(buffLen-4)) { - char *newBuff = new char[ strlen(buff) + 4 ]; - strcpy( newBuff, buff ); - buffptr = newBuff; + char *newBuff= new char[length + 4]; + strcpy(newBuff, buff); + buffptr= newBuff; } - strcat( buffptr, "\r\n\r\n" ); - buffmsgptr = (LPCSTR*)&buffptr; + strmov(buffptr+length, "\r\n\r\n"); + buffmsgptr= (LPCSTR*) &buffptr; // Keep windows happy - setupWindowsEventSource(); - if (event = RegisterEventSource(NULL,"MySQL")) + setup_windows_event_source(); + if ((event= RegisterEventSource(NULL,"MySQL"))) { - switch (level){ + switch (level) { case ERROR_LEVEL: - ReportEvent(event, EVENTLOG_ERROR_TYPE, 0, MSG_DEFAULT, NULL, 1, 0, buffmsgptr, NULL); + 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); + 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); + 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 ) + /* if we created a string buffer, then delete it */ + if (buffptr != buff) delete[] buffptr; - DBUG_VOID_RETURN; } -#endif +#endif /* __NT__ */ + /* - Prints a printf style message to the error log and, under NT, to the Windows event log. + 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 + 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. + 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(enum loglevel level, const char *format, va_list args) { char buff[1024]; - + uint length; DBUG_ENTER("vprint_msg_to_log"); - my_vsnprintf( buff, sizeof(buff)-5, format, args ); - - print_buffer_to_file( level, buff ); - -#ifndef DBUG_OFF - DBUG_PRINT("error",("%s",buff)); -#endif + length= my_vsnprintf(buff, sizeof(buff)-5, format, args); + print_buffer_to_file(level, buff); #ifdef __NT__ - print_buffer_to_nt_eventlog( level, buff, sizeof(buff) ); + print_buffer_to_nt_eventlog(level, buff, length, sizeof(buff)); #endif DBUG_VOID_RETURN; } -void sql_print_error( const char *format, ... ) +void sql_print_error(const char *format, ...) { - DBUG_ENTER( "sql_print_error" ); - va_list args; - va_start( args, format ); - vprint_msg_to_log( ERROR_LEVEL, format, args ); - va_end( args ); + DBUG_ENTER("sql_print_error"); + + va_start(args, format); + vprint_msg_to_log(ERROR_LEVEL, format, args); + va_end(args); DBUG_VOID_RETURN; } -void sql_print_warning( const char *format, ... ) -{ - DBUG_ENTER( "sql_print_warning" ); +void sql_print_warning(const char *format, ...) +{ va_list args; - va_start( args, format ); - vprint_msg_to_log( WARNING_LEVEL, format, args ); - va_end( args ); + DBUG_ENTER("sql_print_warning"); + + va_start(args, format); + vprint_msg_to_log(WARNING_LEVEL, format, args); + va_end(args); DBUG_VOID_RETURN; } -void sql_print_information( const char *format, ... ) -{ - DBUG_ENTER( "sql_print_information" ); +void sql_print_information(const char *format, ...) +{ va_list args; - va_start( args, format ); - vprint_msg_to_log( INFORMATION_LEVEL, format, args ); - va_end( args ); + DBUG_ENTER("sql_print_information"); + + va_start(args, format); + vprint_msg_to_log(INFORMATION_LEVEL, format, args); + va_end(args); DBUG_VOID_RETURN; } |