5071
extern "C" my_bool reopen_fstreams(const char *filename,
5072
FILE *outstream, FILE *errstream)
5078
DBUG_ASSERT(filename && errstream);
5080
// Services don't have stdout/stderr on Windows, so _fileno returns -1.
5081
err_fd= _fileno(errstream);
5084
if (!freopen(filename, "a+", errstream))
5087
setbuf(errstream, NULL);
5088
err_fd= _fileno(errstream);
5093
out_fd= _fileno(outstream);
5096
if (!freopen(filename, "a+", outstream))
5098
out_fd= _fileno(outstream);
5102
if ((osfh= CreateFile(filename, GENERIC_READ | GENERIC_WRITE,
5103
FILE_SHARE_READ | FILE_SHARE_WRITE |
5104
FILE_SHARE_DELETE, NULL,
5105
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,
5106
NULL)) == INVALID_HANDLE_VALUE)
5109
if ((handle_fd= _open_osfhandle((intptr_t)osfh,
5110
_O_APPEND | _O_TEXT)) == -1)
5116
if (_dup2(handle_fd, err_fd) < 0)
5122
if (outstream && _dup2(handle_fd, out_fd) < 0)
5132
extern "C" my_bool reopen_fstreams(const char *filename,
5133
FILE *outstream, FILE *errstream)
5135
if (outstream && !freopen(filename, "a+", outstream))
5138
if (errstream && !freopen(filename, "a+", errstream))
5147
Unfortunately, there seems to be no good way
5148
to restore the original streams upon failure.
5150
static bool redirect_std_streams(const char *file)
5152
if (reopen_fstreams(file, stdout, stderr))
5155
setbuf(stderr, NULL);
5053
5160
bool flush_error_log()
5056
5163
if (opt_error_log)
5058
char err_renamed[FN_REFLEN], *end;
5059
end= strmake(err_renamed,log_error_file,FN_REFLEN-5);
5060
strmov(end, "-old");
5061
5165
VOID(pthread_mutex_lock(&LOCK_error_log));
5063
char err_temp[FN_REFLEN+5];
5065
On Windows is necessary a temporary file for to rename
5066
the current error file.
5068
strxmov(err_temp, err_renamed,"-tmp",NullS);
5069
(void) my_delete(err_temp, MYF(0));
5070
if (freopen(err_temp,"a+",stdout))
5076
freopen(err_temp,"a+",stderr);
5077
setbuf(stderr, NULL);
5078
(void) my_delete(err_renamed, MYF(0));
5079
my_rename(log_error_file,err_renamed,MYF(0));
5080
if (freopen(log_error_file,"a+",stdout))
5082
freopen(log_error_file,"a+",stderr);
5083
setbuf(stderr, NULL);
5086
if ((fd = my_open(err_temp, O_RDONLY, MYF(0))) >= 0)
5088
while ((bytes= my_read(fd, buf, IO_SIZE, MYF(0))) &&
5089
bytes != MY_FILE_ERROR)
5090
my_fwrite(stderr, buf, bytes, MYF(0));
5091
my_close(fd, MYF(0));
5093
(void) my_delete(err_temp, MYF(0));
5098
my_rename(log_error_file,err_renamed,MYF(0));
5099
if (freopen(log_error_file,"a+",stdout))
5102
reopen= freopen(log_error_file,"a+",stderr);
5103
setbuf(stderr, NULL);
5166
if (redirect_std_streams(log_error_file))
5108
5168
VOID(pthread_mutex_unlock(&LOCK_error_log));
5113
5173
void MYSQL_BIN_LOG::signal_update()
5153
5213
#endif /* __NT__ */
5157
Prints a printf style message to the error log and, under NT, to the
5160
This function prints the message into a buffer and then sends that buffer
5161
to other functions to write that message to other logging sources.
5163
@param event_type Type of event to write (Error, Warning, or Info)
5164
@param format Printf style format of message
5165
@param args va_list list of arguments for the message
5168
The function always returns 0. The return value is present in the
5169
signature to be compatible with other logging routines, which could
5170
return an error (e.g. logging to the log tables)
5173
5216
#ifndef EMBEDDED_LIBRARY
5174
static void print_buffer_to_file(enum loglevel level, const char *buffer)
5217
static void print_buffer_to_file(enum loglevel level, const char *buffer,
5177
5221
struct tm tm_tmp;
5202
5246
DBUG_VOID_RETURN;
5250
Prints a printf style message to the error log and, under NT, to the
5253
This function prints the message into a buffer and then sends that buffer
5254
to other functions to write that message to other logging sources.
5256
@param level The level of the msg significance
5257
@param format Printf style format of message
5258
@param args va_list list of arguments for the message
5261
The function always returns 0. The return value is present in the
5262
signature to be compatible with other logging routines, which could
5263
return an error (e.g. logging to the log tables)
5206
5265
int vprint_msg_to_log(enum loglevel level, const char *format, va_list args)
5208
5267
char buff[1024];