Commit 4a67bd51 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

Fix server on windows, so it does not write to error log byte-by-byte


fprintf() on Windows, when used on unbuffered FILE*, writes bytewise.
This can make crash handler messages harder to read, if they are mixed up
with other error log output.

Fixed , on Windows, by using a small buffer for formatting, and fwrite
instead of fprintf, if buffer is large enough for message.
parent 62fd7b4c
......@@ -9215,6 +9215,25 @@ static void print_buffer_to_nt_eventlog(enum loglevel level, char *buff,
#ifndef EMBEDDED_LIBRARY
#ifndef _WIN32
#define fprintf_stderr(format, ...) fprintf(stderr, format, __VA_ARGS__)
#else
/*
On Windows, if FILE* is unbuffered, fprintf() writes output byte by byte.
This is suboptimal for printing to error log, we want full message at once.
*/
#define fprintf_stderr(format, ...) \
do \
{ \
char buf[256]; \
size_t len= snprintf(buf, sizeof(buf), format, __VA_ARGS__); \
if (len >= sizeof(buf)) \
fprintf(stderr, format, __VA_ARGS__); \
else \
fwrite(buf, len, 1, stderr); \
} while (0)
#endif
static void print_buffer_to_file(enum loglevel level, const char *buffer,
size_t length)
{
......@@ -9248,7 +9267,7 @@ static void print_buffer_to_file(enum loglevel level, const char *buffer,
localtime_r(&skr, &tm_tmp);
start=&tm_tmp;
fprintf(stderr, "%d-%02d-%02d %2d:%02d:%02d %lu [%s] %.*s%.*s\n",
fprintf_stderr( "%d-%02d-%02d %2d:%02d:%02d %lu [%s] %.*s%.*s\n",
start->tm_year + 1900,
start->tm_mon+1,
start->tm_mday,
......
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