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

Commit90b418f

Browse files
committed
Fix pg_current_logfile() to not emit a carriage return on Windows.
Due to not having our signals straight about CRLF vs. LF linetermination, the output of pg_current_logfile() included a trailing\r on Windows. To fix, force the file descriptor it uses into textmode.While here, move a couple of local variable declarations to makethe function's logic clearer.In v12 and v13, also back-patch the test added by1c4e88e so thatthis function has some test coverage. However, the 004_logrotate.pltest script doesn't exist before v12, and it didn't seem worth addingto older branches just for this.Per report from Thomas Kellerer. Back-patch to v10 where thisfunction was added.Discussion:https://postgr.es/m/412ae8da-76bb-640f-039a-f3513499e53d@gmx.net
1 parent0895257 commit90b418f

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

‎src/backend/utils/adt/misc.c‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include<sys/file.h>
1818
#include<signal.h>
1919
#include<dirent.h>
20+
#include<fcntl.h>
2021
#include<math.h>
2122
#include<unistd.h>
2223

@@ -930,9 +931,6 @@ pg_current_logfile(PG_FUNCTION_ARGS)
930931
FILE*fd;
931932
charlbuffer[MAXPGPATH];
932933
char*logfmt;
933-
char*log_filepath;
934-
char*log_format=lbuffer;
935-
char*nlpos;
936934

937935
/* The log format parameter is optional */
938936
if (PG_NARGS()==0||PG_ARGISNULL(0))
@@ -959,16 +957,23 @@ pg_current_logfile(PG_FUNCTION_ARGS)
959957
PG_RETURN_NULL();
960958
}
961959

960+
#ifdefWIN32
961+
/* syslogger.c writes CRLF line endings on Windows */
962+
_setmode(_fileno(fd),_O_TEXT);
963+
#endif
964+
962965
/*
963966
* Read the file to gather current log filename(s) registered by the
964967
* syslogger.
965968
*/
966969
while (fgets(lbuffer,sizeof(lbuffer),fd)!=NULL)
967970
{
968-
/*
969-
* Extract log format and log file path from the line; lbuffer ==
970-
* log_format, they share storage.
971-
*/
971+
char*log_format;
972+
char*log_filepath;
973+
char*nlpos;
974+
975+
/* Extract log format and log file path from the line. */
976+
log_format=lbuffer;
972977
log_filepath=strchr(lbuffer,' ');
973978
if (log_filepath==NULL)
974979
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp