From fb1e2ee2100ffe6e7d3c5c3aeb6f5d75b410eeab Mon Sep 17 00:00:00 2001
From: Hari Babu <kommi.haribabu@gmail.com>
Date: Tue, 15 Jan 2019 14:58:21 +1100
Subject: [PATCH] Adjust current_logfiles file permissions

current_logfiles contains the current log file locations,
but this file is not a log file. This file should follow
the permissions with other files instead of log file
permissions (log_file_mode).
---
 src/backend/postmaster/syslogger.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index d1ea46deb8..021db0de3e 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -30,7 +30,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <sys/time.h>
-
+#include "common/file_perm.h"
 #include "lib/stringinfo.h"
 #include "libpq/pqsignal.h"
 #include "miscadmin.h"
@@ -1453,6 +1453,7 @@ static void
 update_metainfo_datafile(void)
 {
 	FILE	   *fh;
+	mode_t		oumask;
 
 	if (!(Log_destination & LOG_DESTINATION_STDERR) &&
 		!(Log_destination & LOG_DESTINATION_CSVLOG))
@@ -1465,12 +1466,19 @@ update_metainfo_datafile(void)
 		return;
 	}
 
-	if ((fh = logfile_open(LOG_METAINFO_DATAFILE_TMP, "w", true)) == NULL)
+	/*
+	 * Adjust the new file permissions according to the files in the
+	 * data directory.
+	 */
+	oumask = umask(pg_file_create_mode);
+
+	if ((fh = fopen(LOG_METAINFO_DATAFILE_TMP, "w")) == NULL)
 	{
 		ereport(LOG,
 				(errcode_for_file_access(),
 				 errmsg("could not open file \"%s\": %m",
 						LOG_METAINFO_DATAFILE_TMP)));
+		umask (oumask);
 		return;
 	}
 
@@ -1483,6 +1491,7 @@ update_metainfo_datafile(void)
 					 errmsg("could not write file \"%s\": %m",
 							LOG_METAINFO_DATAFILE_TMP)));
 			fclose(fh);
+			umask (oumask);
 			return;
 		}
 	}
@@ -1496,10 +1505,12 @@ update_metainfo_datafile(void)
 					 errmsg("could not write file \"%s\": %m",
 							LOG_METAINFO_DATAFILE_TMP)));
 			fclose(fh);
+			umask (oumask);
 			return;
 		}
 	}
 	fclose(fh);
+	umask (oumask);
 
 	if (rename(LOG_METAINFO_DATAFILE_TMP, LOG_METAINFO_DATAFILE) != 0)
 		ereport(LOG,
-- 
2.20.1.windows.1

