summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-01-07 18:20:58 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2016-01-07 18:20:58 -0500
commitb05a34739fc1188056931eeec780817bdbb84381 (patch)
tree8029158394bd7859f52654ceb2c938e83a860642
parent099541e8f1988cd8c1ae1a00ded015370fbc61b2 (diff)
downloadpostgresql-b05a34739fc1188056931eeec780817bdbb84381.tar.gz
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 ...)
-rw-r--r--src/bin/initdb/initdb.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 179393424e..93ebc4b69f 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -2505,6 +2505,7 @@ main(int argc, char *argv[])
char *pgdenv; /* PGDATA value gotten from and sent to
* environment */
char bin_dir[MAXPGPATH];
+ char *xlogsubdirloc;
char *pg_data_native;
int user_enc;
@@ -2513,7 +2514,6 @@ main(int argc, char *argv[])
#endif
static const char *subdirs[] = {
"global",
- "pg_xlog",
"pg_xlog/archive_status",
"pg_clog",
"pg_notify",
@@ -3082,11 +3082,12 @@ main(int argc, char *argv[])
exit_nicely();
}
- /* Create transaction log symlink, if required */
+ /* Create transaction log directory, and symlink if required */
+ xlogsubdirloc = (char *) pg_malloc(strlen(pg_data) + 8 + 1);
+ sprintf(xlogsubdirloc, "%s/pg_xlog", pg_data);
+
if (strcmp(xlog_dir, "") != 0)
{
- char *linkloc;
-
/* clean up xlog directory name, check it's absolute */
canonicalize_path(xlog_dir);
if (!is_absolute_path(xlog_dir))
@@ -3152,15 +3153,11 @@ main(int argc, char *argv[])
exit_nicely();
}
- /* form name of the place where the symlink must go */
- linkloc = (char *) pg_malloc(strlen(pg_data) + 8 + 1);
- sprintf(linkloc, "%s/pg_xlog", pg_data);
-
#ifdef HAVE_SYMLINK
- if (symlink(xlog_dir, linkloc) != 0)
+ if (symlink(xlog_dir, xlogsubdirloc) != 0)
{
fprintf(stderr, _("%s: could not create symbolic link \"%s\": %s\n"),
- progname, linkloc, strerror(errno));
+ progname, xlogsubdirloc, strerror(errno));
exit_nicely();
}
#else
@@ -3168,8 +3165,18 @@ main(int argc, char *argv[])
exit_nicely();
#endif
}
+ else
+ {
+ /* Without -X option, just make the subdirectory normally */
+ if (mkdir(xlogsubdirloc, S_IRWXU) < 0)
+ {
+ fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
+ progname, xlogsubdirloc, strerror(errno));
+ exit_nicely();
+ }
+ }
- /* Create required subdirectories */
+ /* Create required subdirectories (other than pg_xlog) */
printf(_("creating subdirectories ... "));
fflush(stdout);