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

Commit1d96c1b

Browse files
committed
Fix incorrect ordering of operations in pg_resetwal and pg_rewind.
Commitc37b3d0 dropped its added GetDataDirectoryCreatePerm call intothe wrong place in pg_resetwal.c, namely after the chdir to DataDir.That broke invocations using a relative path, as reported by Tushar Ahuja.We could have left it where it was and changed the argument to be ".",but that'd result in a rather confusing error message in event of afailure, so re-ordering seems like a better solution.Similarly reorder operations in pg_rewind.c. The issue there is thatit doesn't seem like a good idea to do any actual operations before thenot-root check (on Unix) or the restricted token acquisition (on Windows).I don't know that this is an actual bug, but I'm definitely not convincedthat it isn't, either.Assorted other code review forc37b3d0 andda9b580: fix somemisspelled or otherwise badly worded comments, put the #include for<sys/stat.h> where it actually belongs, etc.Discussion:https://postgr.es/m/aeb9c3a7-3c3f-a57f-1a18-c8d4fcdc2a1f@enterprisedb.com
1 parentb06d8e5 commit1d96c1b

File tree

6 files changed

+26
-27
lines changed

6 files changed

+26
-27
lines changed

‎src/backend/storage/file/fd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3552,8 +3552,8 @@ fsync_parent_path(const char *fname, int elevel)
35523552
/*
35533553
* Create a PostgreSQL data sub-directory
35543554
*
3555-
* The data directory itself,along withmostotherdirectories, are created at
3556-
* initdb-time, but we do have someoccations where we create directoriesfrom
3555+
* The data directory itself,andmostof its sub-directories, are created at
3556+
* initdbtime, but we do have someoccasions when we create directoriesin
35573557
* the backend (CREATE TABLESPACE, for example). In those cases, we want to
35583558
* make sure that those directories are created consistently. Today, that means
35593559
* making sure that the created directory has the correct permissions, which is
@@ -3562,8 +3562,8 @@ fsync_parent_path(const char *fname, int elevel)
35623562
* Note that we also set the umask() based on what we understand the correct
35633563
* permissions to be (see file_perm.c).
35643564
*
3565-
* For permissions other than the default mkdir() can be used directly, but be
3566-
* sure to consider carefully such cases -- a directory with incorrect
3565+
* For permissions other than the default, mkdir() can be used directly, but
3566+
*besure to consider carefully such cases -- asub-directory with incorrect
35673567
* permissions in a PostgreSQL data directory could cause backups and other
35683568
* processes to fail.
35693569
*/

‎src/backend/utils/init/globals.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919
#include"postgres.h"
2020

21-
#include<sys/stat.h>
22-
2321
#include"common/file_perm.h"
2422
#include"libpq/libpq-be.h"
2523
#include"libpq/pqcomm.h"
@@ -63,7 +61,7 @@ struct Latch *MyLatch;
6361
char*DataDir=NULL;
6462

6563
/*
66-
* Mode of the data directory. The default is 0700 butmay it be changed in
64+
* Mode of the data directory. The default is 0700 butit may be changed in
6765
* checkDataDir() to 0750 if the data directory actually has that mode.
6866
*/
6967
intdata_directory_mode=PG_DIR_MODE_OWNER;

‎src/bin/pg_resetwal/pg_resetwal.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,6 @@ main(int argc, char *argv[])
356356

357357
get_restricted_token(progname);
358358

359-
if (chdir(DataDir)<0)
360-
{
361-
fprintf(stderr,_("%s: could not change directory to \"%s\": %s\n"),
362-
progname,DataDir,strerror(errno));
363-
exit(1);
364-
}
365-
366359
/* Set mask based on PGDATA permissions */
367360
if (!GetDataDirectoryCreatePerm(DataDir))
368361
{
@@ -373,6 +366,13 @@ main(int argc, char *argv[])
373366

374367
umask(pg_mode_mask);
375368

369+
if (chdir(DataDir)<0)
370+
{
371+
fprintf(stderr,_("%s: could not change directory to \"%s\": %s\n"),
372+
progname,DataDir,strerror(errno));
373+
exit(1);
374+
}
375+
376376
/* Check that data directory matches our server version */
377377
CheckDataVersion();
378378

‎src/bin/pg_rewind/pg_rewind.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,6 @@ main(int argc, char **argv)
186186
exit(1);
187187
}
188188

189-
/* Set mask based on PGDATA permissions */
190-
if (!GetDataDirectoryCreatePerm(datadir_target))
191-
{
192-
fprintf(stderr,_("%s: could not read permissions of directory \"%s\": %s\n"),
193-
progname,datadir_target,strerror(errno));
194-
exit(1);
195-
}
196-
197-
umask(pg_mode_mask);
198-
199189
/*
200190
* Don't allow pg_rewind to be run as root, to avoid overwriting the
201191
* ownership of files in the data directory. We need only check for root
@@ -214,6 +204,16 @@ main(int argc, char **argv)
214204

215205
get_restricted_token(progname);
216206

207+
/* Set mask based on PGDATA permissions */
208+
if (!GetDataDirectoryCreatePerm(datadir_target))
209+
{
210+
fprintf(stderr,_("%s: could not read permissions of directory \"%s\": %s\n"),
211+
progname,datadir_target,strerror(errno));
212+
exit(1);
213+
}
214+
215+
umask(pg_mode_mask);
216+
217217
/* Connect to remote server */
218218
if (connstr_source)
219219
libpqConnect(connstr_source);

‎src/common/file_perm.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
13-
#include<sys/stat.h>
14-
1513
#include"c.h"
14+
1615
#include"common/file_perm.h"
1716

1817
/* Modes for creating directories and files in the data directory */

‎src/include/common/file_perm.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*-------------------------------------------------------------------------
22
*
3-
* File and directory permissionconstants
3+
* File and directory permissiondefinitions
44
*
55
*
66
* Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
@@ -13,6 +13,8 @@
1313
#ifndefFILE_PERM_H
1414
#defineFILE_PERM_H
1515

16+
#include<sys/stat.h>
17+
1618
/*
1719
* Mode mask for data directory permissions that only allows the owner to
1820
* read/write directories and files.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp