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

Commit32e7e7f

Browse files
committed
Use plain mkdir() not pg_mkdir_p() to create subdirectories of PGDATA.
When we're creating subdirectories of PGDATA during initdb, we know darnwell that the parent directory exists (or should exist) and that the newsubdirectory doesn't (or shouldn't). There is therefore no need to useanything more complicated than mkdir(). Using pg_mkdir_p() just opens usup to unexpected failure modes, such as the one exhibited in bug #13853from Nuri Boardman. It's not very clear why pg_mkdir_p() went wrong there,but it is clear that we didn't need to be trying to create parentdirectories in the first place. We're not even saving any code, as provenby the fact that this patch nets out at minus five lines.Since this is a response to a field bug report, back-patch to all branches.
1 parent744d01c commit32e7e7f

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

‎src/bin/initdb/initdb.c

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ static const char *subdirs[] = {
199199
"pg_snapshots",
200200
"pg_subtrans",
201201
"pg_twophase",
202+
"pg_multixact",
202203
"pg_multixact/members",
203204
"pg_multixact/offsets",
204205
"base",
@@ -236,7 +237,6 @@ static FILE *popen_check(const char *command, const char *mode);
236237
staticvoidexit_nicely(void);
237238
staticchar*get_id(void);
238239
staticchar*get_encoding_id(char*encoding_name);
239-
staticboolmkdatadir(constchar*subdir);
240240
staticvoidset_input(char**dest,char*filename);
241241
staticvoidcheck_input(char*path);
242242
staticvoidwrite_version_file(char*extrapath);
@@ -924,29 +924,6 @@ find_matching_ts_config(const char *lc_type)
924924
}
925925

926926

927-
/*
928-
* make the data directory (or one of its subdirectories if subdir is not NULL)
929-
*/
930-
staticbool
931-
mkdatadir(constchar*subdir)
932-
{
933-
char*path;
934-
935-
if (subdir)
936-
path=psprintf("%s/%s",pg_data,subdir);
937-
else
938-
path=pg_strdup(pg_data);
939-
940-
if (pg_mkdir_p(path,S_IRWXU)==0)
941-
return true;
942-
943-
fprintf(stderr,_("%s: could not create directory \"%s\": %s\n"),
944-
progname,path,strerror(errno));
945-
946-
return false;
947-
}
948-
949-
950927
/*
951928
* set name of given input file variable under data directory
952929
*/
@@ -3134,8 +3111,12 @@ create_data_directory(void)
31343111
pg_data);
31353112
fflush(stdout);
31363113

3137-
if (!mkdatadir(NULL))
3114+
if (pg_mkdir_p(pg_data,S_IRWXU)!=0)
3115+
{
3116+
fprintf(stderr,_("%s: could not create directory \"%s\": %s\n"),
3117+
progname,pg_data,strerror(errno));
31383118
exit_nicely();
3119+
}
31393120
else
31403121
check_ok();
31413122

@@ -3317,10 +3298,24 @@ initialize_data_directory(void)
33173298
printf(_("creating subdirectories ... "));
33183299
fflush(stdout);
33193300

3320-
for (i=0;i<(sizeof(subdirs) /sizeof(char*));i++)
3301+
for (i=0;i<lengthof(subdirs);i++)
33213302
{
3322-
if (!mkdatadir(subdirs[i]))
3303+
char*path;
3304+
3305+
path=psprintf("%s/%s",pg_data,subdirs[i]);
3306+
3307+
/*
3308+
* The parent directory already exists, so we only need mkdir() not
3309+
* pg_mkdir_p() here, which avoids some failure modes; cf bug #13853.
3310+
*/
3311+
if (mkdir(path,S_IRWXU)<0)
3312+
{
3313+
fprintf(stderr,_("%s: could not create directory \"%s\": %s\n"),
3314+
progname,path,strerror(errno));
33233315
exit_nicely();
3316+
}
3317+
3318+
free(path);
33243319
}
33253320

33263321
check_ok();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp