Skip to content

Commit 452064f

Browse files
committed
Fix unobvious interaction between -X switch and subdirectory creation.
Turns out the only reason initdb -X worked is that pg_mkdir_p won't whine if you point it at something that's a symlink to a directory. Otherwise, the attempt to create pg_xlog/ just like all the other subdirectories would have failed. Let's be a little more explicit about what's happening. Oversight in my patch for bug #13853 (mea culpa for not testing -X ...)
1 parent 9486d02 commit 452064f

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

src/bin/initdb/initdb.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ char *restrict_env;
188188
#endif
189189
const char *subdirs[] = {
190190
"global",
191-
"pg_xlog",
192191
"pg_xlog/archive_status",
193192
"pg_clog",
194193
"pg_notify",
@@ -270,7 +269,7 @@ void setup_locale_encoding(void);
270269
void setup_signals(void);
271270
void setup_text_search(void);
272271
void create_data_directory(void);
273-
void create_xlog_symlink(void);
272+
void create_xlog_or_symlink(void);
274273
void warn_on_mount_point(int error);
275274
void initialize_data_directory(void);
276275

@@ -3250,13 +3249,18 @@ create_data_directory(void)
32503249
}
32513250

32523251

3252+
/* Create transaction log directory, and symlink if required */
32533253
void
3254-
create_xlog_symlink(void)
3254+
create_xlog_or_symlink(void)
32553255
{
3256-
/* Create transaction log symlink, if required */
3256+
char *subdirloc;
3257+
3258+
/* form name of the place for the subdirectory or symlink */
3259+
subdirloc = (char *) pg_malloc(strlen(pg_data) + 8 + 1);
3260+
sprintf(subdirloc, "%s/pg_xlog", pg_data);
3261+
32573262
if (strcmp(xlog_dir, "") != 0)
32583263
{
3259-
char *linkloc;
32603264
int ret;
32613265

32623266
/* clean up xlog directory name, check it's absolute */
@@ -3329,22 +3333,30 @@ create_xlog_symlink(void)
33293333
exit_nicely();
33303334
}
33313335

3332-
/* form name of the place where the symlink must go */
3333-
linkloc = (char *) pg_malloc(strlen(pg_data) + 8 + 1);
3334-
sprintf(linkloc, "%s/pg_xlog", pg_data);
3335-
33363336
#ifdef HAVE_SYMLINK
3337-
if (symlink(xlog_dir, linkloc) != 0)
3337+
if (symlink(xlog_dir, subdirloc) != 0)
33383338
{
33393339
fprintf(stderr, _("%s: could not create symbolic link \"%s\": %s\n"),
3340-
progname, linkloc, strerror(errno));
3340+
progname, subdirloc, strerror(errno));
33413341
exit_nicely();
33423342
}
33433343
#else
33443344
fprintf(stderr, _("%s: symlinks are not supported on this platform"));
33453345
exit_nicely();
33463346
#endif
33473347
}
3348+
else
3349+
{
3350+
/* Without -X option, just make the subdirectory normally */
3351+
if (mkdir(subdirloc, S_IRWXU) < 0)
3352+
{
3353+
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
3354+
progname, subdirloc, strerror(errno));
3355+
exit_nicely();
3356+
}
3357+
}
3358+
3359+
free(subdirloc);
33483360
}
33493361

33503362

@@ -3375,9 +3387,9 @@ initialize_data_directory(void)
33753387

33763388
create_data_directory();
33773389

3378-
create_xlog_symlink();
3390+
create_xlog_or_symlink();
33793391

3380-
/* Create required subdirectories */
3392+
/* Create required subdirectories (other than pg_xlog) */
33813393
printf(_("creating subdirectories ... "));
33823394
fflush(stdout);
33833395

0 commit comments

Comments
 (0)