aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/storage/file/fd.c8
-rw-r--r--src/backend/utils/init/globals.c4
-rw-r--r--src/bin/pg_resetwal/pg_resetwal.c14
-rw-r--r--src/bin/pg_rewind/pg_rewind.c20
-rw-r--r--src/common/file_perm.c3
-rw-r--r--src/include/common/file_perm.h4
6 files changed, 26 insertions, 27 deletions
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 441f18dcf56..8dd51f17674 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -3552,8 +3552,8 @@ fsync_parent_path(const char *fname, int elevel)
/*
* Create a PostgreSQL data sub-directory
*
- * The data directory itself, along with most other directories, are created at
- * initdb-time, but we do have some occations where we create directories from
+ * The data directory itself, and most of its sub-directories, are created at
+ * initdb time, but we do have some occasions when we create directories in
* the backend (CREATE TABLESPACE, for example). In those cases, we want to
* make sure that those directories are created consistently. Today, that means
* making sure that the created directory has the correct permissions, which is
@@ -3562,8 +3562,8 @@ fsync_parent_path(const char *fname, int elevel)
* Note that we also set the umask() based on what we understand the correct
* permissions to be (see file_perm.c).
*
- * For permissions other than the default mkdir() can be used directly, but be
- * sure to consider carefully such cases -- a directory with incorrect
+ * For permissions other than the default, mkdir() can be used directly, but
+ * be sure to consider carefully such cases -- a sub-directory with incorrect
* permissions in a PostgreSQL data directory could cause backups and other
* processes to fail.
*/
diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c
index 36ffd874a40..f7d6617a138 100644
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -18,8 +18,6 @@
*/
#include "postgres.h"
-#include <sys/stat.h>
-
#include "common/file_perm.h"
#include "libpq/libpq-be.h"
#include "libpq/pqcomm.h"
@@ -63,7 +61,7 @@ struct Latch *MyLatch;
char *DataDir = NULL;
/*
- * Mode of the data directory. The default is 0700 but may it be changed in
+ * Mode of the data directory. The default is 0700 but it may be changed in
* checkDataDir() to 0750 if the data directory actually has that mode.
*/
int data_directory_mode = PG_DIR_MODE_OWNER;
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index ee28c338f88..8cff5356925 100644
--- a/src/bin/pg_resetwal/pg_resetwal.c
+++ b/src/bin/pg_resetwal/pg_resetwal.c
@@ -356,13 +356,6 @@ main(int argc, char *argv[])
get_restricted_token(progname);
- if (chdir(DataDir) < 0)
- {
- fprintf(stderr, _("%s: could not change directory to \"%s\": %s\n"),
- progname, DataDir, strerror(errno));
- exit(1);
- }
-
/* Set mask based on PGDATA permissions */
if (!GetDataDirectoryCreatePerm(DataDir))
{
@@ -373,6 +366,13 @@ main(int argc, char *argv[])
umask(pg_mode_mask);
+ if (chdir(DataDir) < 0)
+ {
+ fprintf(stderr, _("%s: could not change directory to \"%s\": %s\n"),
+ progname, DataDir, strerror(errno));
+ exit(1);
+ }
+
/* Check that data directory matches our server version */
CheckDataVersion();
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index cabcff5c13b..b0fd3f66ace 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -186,16 +186,6 @@ main(int argc, char **argv)
exit(1);
}
- /* Set mask based on PGDATA permissions */
- if (!GetDataDirectoryCreatePerm(datadir_target))
- {
- fprintf(stderr, _("%s: could not read permissions of directory \"%s\": %s\n"),
- progname, datadir_target, strerror(errno));
- exit(1);
- }
-
- umask(pg_mode_mask);
-
/*
* Don't allow pg_rewind to be run as root, to avoid overwriting the
* ownership of files in the data directory. We need only check for root
@@ -214,6 +204,16 @@ main(int argc, char **argv)
get_restricted_token(progname);
+ /* Set mask based on PGDATA permissions */
+ if (!GetDataDirectoryCreatePerm(datadir_target))
+ {
+ fprintf(stderr, _("%s: could not read permissions of directory \"%s\": %s\n"),
+ progname, datadir_target, strerror(errno));
+ exit(1);
+ }
+
+ umask(pg_mode_mask);
+
/* Connect to remote server */
if (connstr_source)
libpqConnect(connstr_source);
diff --git a/src/common/file_perm.c b/src/common/file_perm.c
index f2c8f846093..9fd11df2886 100644
--- a/src/common/file_perm.c
+++ b/src/common/file_perm.c
@@ -10,9 +10,8 @@
*
*-------------------------------------------------------------------------
*/
-#include <sys/stat.h>
-
#include "c.h"
+
#include "common/file_perm.h"
/* Modes for creating directories and files in the data directory */
diff --git a/src/include/common/file_perm.h b/src/include/common/file_perm.h
index 3090f789317..cfa0546385a 100644
--- a/src/include/common/file_perm.h
+++ b/src/include/common/file_perm.h
@@ -1,6 +1,6 @@
/*-------------------------------------------------------------------------
*
- * File and directory permission constants
+ * File and directory permission definitions
*
*
* Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
@@ -13,6 +13,8 @@
#ifndef FILE_PERM_H
#define FILE_PERM_H
+#include <sys/stat.h>
+
/*
* Mode mask for data directory permissions that only allows the owner to
* read/write directories and files.