Commit 9516e824 authored by Dmitry Shulga's avatar Dmitry Shulga

Fixed bug#56821 - failure to start the MySQL Service.

sql/log.cc:
  reopen_fstreams modified: fixed error in processing of
  stdout/stderr when run mysqld as Windows service.
parent b288324a
...@@ -5072,10 +5072,32 @@ extern "C" my_bool reopen_fstreams(const char *filename, ...@@ -5072,10 +5072,32 @@ extern "C" my_bool reopen_fstreams(const char *filename,
FILE *outstream, FILE *errstream) FILE *outstream, FILE *errstream)
{ {
int handle_fd; int handle_fd;
int stream_fd; int err_fd, out_fd;
HANDLE osfh; HANDLE osfh;
DBUG_ASSERT(filename && (outstream || errstream)); DBUG_ASSERT(filename && errstream);
// Services don't have stdout/stderr on Windows, so _fileno returns -1.
err_fd= _fileno(errstream);
if (err_fd < 0)
{
if (!freopen(filename, "a+", errstream))
return TRUE;
setbuf(errstream, NULL);
err_fd= _fileno(errstream);
}
if (outstream)
{
out_fd= _fileno(outstream);
if (out_fd < 0)
{
if (!freopen(filename, "a+", outstream))
return TRUE;
out_fd= _fileno(outstream);
}
}
if ((osfh= CreateFile(filename, GENERIC_READ | GENERIC_WRITE, if ((osfh= CreateFile(filename, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_WRITE |
...@@ -5091,24 +5113,16 @@ extern "C" my_bool reopen_fstreams(const char *filename, ...@@ -5091,24 +5113,16 @@ extern "C" my_bool reopen_fstreams(const char *filename,
return TRUE; return TRUE;
} }
if (outstream) if (_dup2(handle_fd, err_fd) < 0)
{ {
stream_fd= _fileno(outstream); CloseHandle(osfh);
if (_dup2(handle_fd, stream_fd) < 0) return TRUE;
{
CloseHandle(osfh);
return TRUE;
}
} }
if (errstream) if (outstream && _dup2(handle_fd, out_fd) < 0)
{ {
stream_fd= _fileno(errstream); CloseHandle(osfh);
if (_dup2(handle_fd, stream_fd) < 0) return TRUE;
{
CloseHandle(osfh);
return TRUE;
}
} }
_close(handle_fd); _close(handle_fd);
......
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