Skip to content

Commit aa06259

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 33b0512 commit aa06259

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/bin/initdb/initdb.c

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ char *restrict_env;
191191
#endif
192192
static const char *subdirs[] = {
193193
"global",
194-
"pg_xlog",
195194
"pg_xlog/archive_status",
196195
"pg_clog",
197196
"pg_dynshmem",
@@ -278,7 +277,7 @@ void setup_locale_encoding(void);
278277
void setup_signals(void);
279278
void setup_text_search(void);
280279
void create_data_directory(void);
281-
void create_xlog_symlink(void);
280+
void create_xlog_or_symlink(void);
282281
void warn_on_mount_point(int error);
283282
void initialize_data_directory(void);
284283

@@ -3329,13 +3328,17 @@ create_data_directory(void)
33293328
}
33303329

33313330

3331+
/* Create transaction log directory, and symlink if required */
33323332
void
3333-
create_xlog_symlink(void)
3333+
create_xlog_or_symlink(void)
33343334
{
3335-
/* Create transaction log symlink, if required */
3335+
char *subdirloc;
3336+
3337+
/* form name of the place for the subdirectory or symlink */
3338+
subdirloc = psprintf("%s/pg_xlog", pg_data);
3339+
33363340
if (strcmp(xlog_dir, "") != 0)
33373341
{
3338-
char *linkloc;
33393342
int ret;
33403343

33413344
/* clean up xlog directory name, check it's absolute */
@@ -3408,22 +3411,30 @@ create_xlog_symlink(void)
34083411
exit_nicely();
34093412
}
34103413

3411-
/* form name of the place where the symlink must go */
3412-
linkloc = psprintf("%s/pg_xlog", pg_data);
3413-
34143414
#ifdef HAVE_SYMLINK
3415-
if (symlink(xlog_dir, linkloc) != 0)
3415+
if (symlink(xlog_dir, subdirloc) != 0)
34163416
{
34173417
fprintf(stderr, _("%s: could not create symbolic link \"%s\": %s\n"),
3418-
progname, linkloc, strerror(errno));
3418+
progname, subdirloc, strerror(errno));
34193419
exit_nicely();
34203420
}
34213421
#else
34223422
fprintf(stderr, _("%s: symlinks are not supported on this platform"));
34233423
exit_nicely();
34243424
#endif
3425-
free(linkloc);
34263425
}
3426+
else
3427+
{
3428+
/* Without -X option, just make the subdirectory normally */
3429+
if (mkdir(subdirloc, S_IRWXU) < 0)
3430+
{
3431+
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
3432+
progname, subdirloc, strerror(errno));
3433+
exit_nicely();
3434+
}
3435+
}
3436+
3437+
free(subdirloc);
34273438
}
34283439

34293440

@@ -3454,9 +3465,9 @@ initialize_data_directory(void)
34543465

34553466
create_data_directory();
34563467

3457-
create_xlog_symlink();
3468+
create_xlog_or_symlink();
34583469

3459-
/* Create required subdirectories */
3470+
/* Create required subdirectories (other than pg_xlog) */
34603471
printf(_("creating subdirectories ... "));
34613472
fflush(stdout);
34623473

0 commit comments

Comments
 (0)