summaryrefslogtreecommitdiff
path: root/sql/log.cc
diff options
context:
space:
mode:
authorAlexander Nozdrin <alik@sun.com>2010-07-29 16:32:11 +0400
committerAlexander Nozdrin <alik@sun.com>2010-07-29 16:32:11 +0400
commit32f3ab7933240277e52f05e39e4d45f19f7ac3d7 (patch)
tree16a66be92ba2603896b1b010600df021911be256 /sql/log.cc
parentd85c6281802c8f6ef7187518f9f4357d96134b3e (diff)
parent6bd182e9f22e02f29e7f14e6dd8bf14eaeee084e (diff)
downloadmariadb-git-32f3ab7933240277e52f05e39e4d45f19f7ac3d7.tar.gz
Auto-merge from mysql-trunk-merge.
Diffstat (limited to 'sql/log.cc')
-rw-r--r--sql/log.cc73
1 files changed, 39 insertions, 34 deletions
diff --git a/sql/log.cc b/sql/log.cc
index 6eab16bc3a4..1e4682e4bc3 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -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, ...)