Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc91a216

Browse files
committed
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 descriptorThis is triggered by76e38b3. The problem is that STDOUT/STDERR_FILENOaren't defined on windows, which lead us to use _fileno(stdout) etc, but thatdoesn'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-, where76e38b3 came in
1 parent92f4786 commitc91a216

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

‎src/backend/postmaster/syslogger.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ SysLoggerMain(int argc, char *argv[])
205205
* if they fail then presumably the file descriptors are closed and
206206
* any writes will go into the bitbucket anyway.
207207
*/
208-
close(fileno(stdout));
209-
close(fileno(stderr));
208+
close(STDOUT_FILENO);
209+
close(STDERR_FILENO);
210210
if (fd!=-1)
211211
{
212-
(void)dup2(fd,fileno(stdout));
213-
(void)dup2(fd,fileno(stderr));
212+
(void)dup2(fd,STDOUT_FILENO);
213+
(void)dup2(fd,STDERR_FILENO);
214214
close(fd);
215215
}
216216
}
@@ -222,7 +222,7 @@ SysLoggerMain(int argc, char *argv[])
222222
*/
223223
#ifdefWIN32
224224
else
225-
_setmode(_fileno(stderr),_O_TEXT);
225+
_setmode(STDERR_FILENO,_O_TEXT);
226226
#endif
227227

228228
/*
@@ -716,12 +716,12 @@ SysLogger_Start(void)
716716

717717
#ifndefWIN32
718718
fflush(stdout);
719-
if (dup2(syslogPipe[1],fileno(stdout))<0)
719+
if (dup2(syslogPipe[1],STDOUT_FILENO)<0)
720720
ereport(FATAL,
721721
(errcode_for_file_access(),
722722
errmsg("could not redirect stdout: %m")));
723723
fflush(stderr);
724-
if (dup2(syslogPipe[1],fileno(stderr))<0)
724+
if (dup2(syslogPipe[1],STDERR_FILENO)<0)
725725
ereport(FATAL,
726726
(errcode_for_file_access(),
727727
errmsg("could not redirect stderr: %m")));
@@ -738,12 +738,12 @@ SysLogger_Start(void)
738738
fflush(stderr);
739739
fd=_open_osfhandle((intptr_t)syslogPipe[1],
740740
_O_APPEND |_O_BINARY);
741-
if (dup2(fd,_fileno(stderr))<0)
741+
if (dup2(fd,STDERR_FILENO)<0)
742742
ereport(FATAL,
743743
(errcode_for_file_access(),
744744
errmsg("could not redirect stderr: %m")));
745745
close(fd);
746-
_setmode(_fileno(stderr),_O_BINARY);
746+
_setmode(STDERR_FILENO,_O_BINARY);
747747

748748
/*
749749
* Now we are done with the write end of the pipe.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp