aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/utils/adt/misc.c19
-rw-r--r--src/bin/pg_ctl/t/004_logrotate.pl6
2 files changed, 17 insertions, 8 deletions
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index 235f3c7b360..1f081cc6318 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -16,6 +16,7 @@
#include <sys/file.h>
#include <dirent.h>
+#include <fcntl.h>
#include <math.h>
#include <unistd.h>
@@ -739,9 +740,6 @@ pg_current_logfile(PG_FUNCTION_ARGS)
FILE *fd;
char lbuffer[MAXPGPATH];
char *logfmt;
- char *log_filepath;
- char *log_format = lbuffer;
- char *nlpos;
/* The log format parameter is optional */
if (PG_NARGS() == 0 || PG_ARGISNULL(0))
@@ -768,16 +766,23 @@ pg_current_logfile(PG_FUNCTION_ARGS)
PG_RETURN_NULL();
}
+#ifdef WIN32
+ /* syslogger.c writes CRLF line endings on Windows */
+ _setmode(_fileno(fd), _O_TEXT);
+#endif
+
/*
* Read the file to gather current log filename(s) registered by the
* syslogger.
*/
while (fgets(lbuffer, sizeof(lbuffer), fd) != NULL)
{
- /*
- * Extract log format and log file path from the line; lbuffer ==
- * log_format, they share storage.
- */
+ char *log_format;
+ char *log_filepath;
+ char *nlpos;
+
+ /* Extract log format and log file path from the line. */
+ log_format = lbuffer;
log_filepath = strchr(lbuffer, ' ');
if (log_filepath == NULL)
{
diff --git a/src/bin/pg_ctl/t/004_logrotate.pl b/src/bin/pg_ctl/t/004_logrotate.pl
index 71dbfd20301..acaade8d812 100644
--- a/src/bin/pg_ctl/t/004_logrotate.pl
+++ b/src/bin/pg_ctl/t/004_logrotate.pl
@@ -3,7 +3,7 @@ use warnings;
use PostgresNode;
use TestLib;
-use Test::More tests => 4;
+use Test::More tests => 5;
use Time::HiRes qw(usleep);
# Set up node with logging collector
@@ -47,6 +47,10 @@ for (my $attempts = 0; $attempts < $max_attempts; $attempts++)
like($first_logfile, qr/division by zero/, 'found expected log file content');
+# While we're at it, test pg_current_logfile() function
+is($node->safe_psql('postgres', "SELECT pg_current_logfile('stderr')"),
+ $lfname, 'pg_current_logfile() gives correct answer');
+
# Sleep 2 seconds and ask for log rotation; this should result in
# output into a different log file name.
sleep(2);