mirror of
https://github.com/postgres/postgres.git
synced 2025-05-02 11:44:50 +03:00
Use STDOUT/STDERR_FILENO in most of syslogger.
This fixes problems on windows when logging collector is used in a service, failing with: FATAL: could not redirect stderr: Bad file descriptor This is triggered by 76e38b37a5. The problem is that STDOUT/STDERR_FILENO aren't defined on windows, which lead us to use _fileno(stdout) etc, but that doesn't work if stdout/stderr are closed. Author: Andres Freund <andres@anarazel.de> Reported-By: Sandeep Thakkar <sandeep.thakkar@enterprisedb.com> Message-Id: 20220520164558.ozb7lm6unakqzezi@alap3.anarazel.de (on pgsql-packagers) Backpatch: 15-, where 76e38b37a5 came in
This commit is contained in:
parent
92f478657c
commit
c91a216ef7
@ -205,12 +205,12 @@ SysLoggerMain(int argc, char *argv[])
|
|||||||
* if they fail then presumably the file descriptors are closed and
|
* if they fail then presumably the file descriptors are closed and
|
||||||
* any writes will go into the bitbucket anyway.
|
* any writes will go into the bitbucket anyway.
|
||||||
*/
|
*/
|
||||||
close(fileno(stdout));
|
close(STDOUT_FILENO);
|
||||||
close(fileno(stderr));
|
close(STDERR_FILENO);
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
{
|
{
|
||||||
(void) dup2(fd, fileno(stdout));
|
(void) dup2(fd, STDOUT_FILENO);
|
||||||
(void) dup2(fd, fileno(stderr));
|
(void) dup2(fd, STDERR_FILENO);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,7 +222,7 @@ SysLoggerMain(int argc, char *argv[])
|
|||||||
*/
|
*/
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
else
|
else
|
||||||
_setmode(_fileno(stderr), _O_TEXT);
|
_setmode(STDERR_FILENO, _O_TEXT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -716,12 +716,12 @@ SysLogger_Start(void)
|
|||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
if (dup2(syslogPipe[1], fileno(stdout)) < 0)
|
if (dup2(syslogPipe[1], STDOUT_FILENO) < 0)
|
||||||
ereport(FATAL,
|
ereport(FATAL,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not redirect stdout: %m")));
|
errmsg("could not redirect stdout: %m")));
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
if (dup2(syslogPipe[1], fileno(stderr)) < 0)
|
if (dup2(syslogPipe[1], STDERR_FILENO) < 0)
|
||||||
ereport(FATAL,
|
ereport(FATAL,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not redirect stderr: %m")));
|
errmsg("could not redirect stderr: %m")));
|
||||||
@ -738,12 +738,12 @@ SysLogger_Start(void)
|
|||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
fd = _open_osfhandle((intptr_t) syslogPipe[1],
|
fd = _open_osfhandle((intptr_t) syslogPipe[1],
|
||||||
_O_APPEND | _O_BINARY);
|
_O_APPEND | _O_BINARY);
|
||||||
if (dup2(fd, _fileno(stderr)) < 0)
|
if (dup2(fd, STDERR_FILENO) < 0)
|
||||||
ereport(FATAL,
|
ereport(FATAL,
|
||||||
(errcode_for_file_access(),
|
(errcode_for_file_access(),
|
||||||
errmsg("could not redirect stderr: %m")));
|
errmsg("could not redirect stderr: %m")));
|
||||||
close(fd);
|
close(fd);
|
||||||
_setmode(_fileno(stderr), _O_BINARY);
|
_setmode(STDERR_FILENO, _O_BINARY);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now we are done with the write end of the pipe.
|
* Now we are done with the write end of the pipe.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user