Merge of mysql-5.1-bugteam into mysql-trunk-merge.

This commit is contained in:
Davi Arnaut 2010-07-20 16:30:10 -03:00
commit 182599dd13
34 changed files with 147 additions and 172 deletions

View file

@ -5447,6 +5447,22 @@ void sql_perror(const char *message)
}
/*
Unfortunately, there seems to be no good way
to restore the original streams upon failure.
*/
static bool redirect_std_streams(const char *file)
{
if (freopen(file, "a+", stdout) && freopen(file, "a+", stderr))
{
setbuf(stderr, NULL);
return FALSE;
}
return TRUE;
}
bool flush_error_log()
{
bool result=0;
@ -5474,11 +5490,7 @@ bool flush_error_log()
setbuf(stderr, NULL);
my_delete(err_renamed, MYF(0));
my_rename(log_error_file, err_renamed, MYF(0));
if (freopen(log_error_file,"a+",stdout))
{
freopen(log_error_file,"a+",stderr);
setbuf(stderr, NULL);
}
redirect_std_streams(log_error_file);
if ((fd= my_open(err_temp, O_RDONLY, MYF(0))) >= 0)
{
@ -5493,13 +5505,7 @@ bool flush_error_log()
result= 1;
#else
my_rename(log_error_file, err_renamed, MYF(0));
if (freopen(log_error_file,"a+",stdout))
{
FILE *reopen;
reopen= freopen(log_error_file,"a+",stderr);
setbuf(stderr, NULL);
}
else
if (redirect_std_streams(log_error_file))
result= 1;
#endif
mysql_mutex_unlock(&LOCK_error_log);
@ -5551,25 +5557,9 @@ static void print_buffer_to_nt_eventlog(enum loglevel level, char *buff,
#endif /* _WIN32 */
/**
Prints a printf style message to the error log and, under NT, to the
Windows event log.
This function prints the message into a buffer and then sends that buffer
to other functions to write that message to other logging sources.
@param event_type Type of event to write (Error, Warning, or Info)
@param format Printf style format of message
@param args va_list list of arguments for the message
@returns
The function always returns 0. The return value is present in the
signature to be compatible with other logging routines, which could
return an error (e.g. logging to the log tables)
*/
#ifndef EMBEDDED_LIBRARY
static void print_buffer_to_file(enum loglevel level, const char *buffer)
static void print_buffer_to_file(enum loglevel level, const char *buffer,
size_t length)
{
time_t skr;
struct tm tm_tmp;
@ -5583,7 +5573,7 @@ static void print_buffer_to_file(enum loglevel level, const char *buffer)
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,
@ -5592,7 +5582,7 @@ static void print_buffer_to_file(enum loglevel level, const char *buffer)
start->tm_sec,
(level == ERROR_LEVEL ? "ERROR" : level == WARNING_LEVEL ?
"Warning" : "Note"),
buffer);
(int) length, buffer);
fflush(stderr);
@ -5600,7 +5590,22 @@ static void print_buffer_to_file(enum loglevel level, const char *buffer)
DBUG_VOID_RETURN;
}
/**
Prints a printf style message to the error log and, under NT, to the
Windows event log.
This function prints the message into a buffer and then sends that buffer
to other functions to write that message to other logging sources.
@param level The level of the msg significance
@param format Printf style format of message
@param args va_list list of arguments for the message
@returns
The function always returns 0. The return value is present in the
signature to be compatible with other logging routines, which could
return an error (e.g. logging to the log tables)
*/
int vprint_msg_to_log(enum loglevel level, const char *format, va_list args)
{
char buff[1024];
@ -5608,7 +5613,7 @@ int vprint_msg_to_log(enum loglevel level, const char *format, va_list args)
DBUG_ENTER("vprint_msg_to_log");
length= my_vsnprintf(buff, sizeof(buff), format, args);
print_buffer_to_file(level, buff);
print_buffer_to_file(level, buff, length);
#ifdef _WIN32
print_buffer_to_nt_eventlog(level, buff, length, sizeof(buff));
@ -5616,7 +5621,7 @@ int vprint_msg_to_log(enum loglevel level, const char *format, va_list args)
DBUG_RETURN(0);
}
#endif /*EMBEDDED_LIBRARY*/
#endif /* EMBEDDED_LIBRARY */
void sql_print_error(const char *format, ...)