summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2022-07-18 17:06:34 -0700
committerAndres Freund <andres@anarazel.de>2022-07-18 17:22:11 -0700
commit950e64fa46b164df87b5eb7c6e15213ab9880f87 (patch)
tree784bae3f72aae3a321b1e59e9a7337edc90e603c
parentc290e79cf07f5784fd68e726177503a6805c28d6 (diff)
downloadpostgresql-950e64fa46b164df87b5eb7c6e15213ab9880f87.tar.gz
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
-rw-r--r--src/backend/postmaster/syslogger.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index 25e2131e31..d6d02e3c63 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -205,12 +205,12 @@ SysLoggerMain(int argc, char *argv[])
* if they fail then presumably the file descriptors are closed and
* any writes will go into the bitbucket anyway.
*/
- close(fileno(stdout));
- close(fileno(stderr));
+ close(STDOUT_FILENO);
+ close(STDERR_FILENO);
if (fd != -1)
{
- (void) dup2(fd, fileno(stdout));
- (void) dup2(fd, fileno(stderr));
+ (void) dup2(fd, STDOUT_FILENO);
+ (void) dup2(fd, STDERR_FILENO);
close(fd);
}
}
@@ -222,7 +222,7 @@ SysLoggerMain(int argc, char *argv[])
*/
#ifdef WIN32
else
- _setmode(_fileno(stderr), _O_TEXT);
+ _setmode(STDERR_FILENO, _O_TEXT);
#endif
/*
@@ -716,12 +716,12 @@ SysLogger_Start(void)
#ifndef WIN32
fflush(stdout);
- if (dup2(syslogPipe[1], fileno(stdout)) < 0)
+ if (dup2(syslogPipe[1], STDOUT_FILENO) < 0)
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not redirect stdout: %m")));
fflush(stderr);
- if (dup2(syslogPipe[1], fileno(stderr)) < 0)
+ if (dup2(syslogPipe[1], STDERR_FILENO) < 0)
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not redirect stderr: %m")));
@@ -738,12 +738,12 @@ SysLogger_Start(void)
fflush(stderr);
fd = _open_osfhandle((intptr_t) syslogPipe[1],
_O_APPEND | _O_BINARY);
- if (dup2(fd, _fileno(stderr)) < 0)
+ if (dup2(fd, STDERR_FILENO) < 0)
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not redirect stderr: %m")));
close(fd);
- _setmode(_fileno(stderr), _O_BINARY);
+ _setmode(STDERR_FILENO, _O_BINARY);
/*
* Now we are done with the write end of the pipe.