aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-01-07 18:20:57 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2016-01-07 18:20:57 -0500
commit506ef1d07f8b51e9799f6856b03a4317297a39cb (patch)
tree7b2a61e2e38487b15703ee688279e5947909cec2 /src
parent32e7e7fa77bab73c9df8ea4bdb1fd65793451ff6 (diff)
downloadpostgresql-506ef1d07f8b51e9799f6856b03a4317297a39cb.tar.gz
postgresql-506ef1d07f8b51e9799f6856b03a4317297a39cb.zip
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 ...)
Diffstat (limited to 'src')
-rw-r--r--src/bin/initdb/initdb.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 862751e5e59..12baae50f43 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -189,7 +189,6 @@ static const char *backend_options = "--single -F -O -c search_path=pg_catalog -
static const char *subdirs[] = {
"global",
- "pg_xlog",
"pg_xlog/archive_status",
"pg_clog",
"pg_commit_ts",
@@ -276,7 +275,7 @@ void setup_locale_encoding(void);
void setup_signals(void);
void setup_text_search(void);
void create_data_directory(void);
-void create_xlog_symlink(void);
+void create_xlog_or_symlink(void);
void warn_on_mount_point(int error);
void initialize_data_directory(void);
@@ -3167,13 +3166,17 @@ create_data_directory(void)
}
+/* Create transaction log directory, and symlink if required */
void
-create_xlog_symlink(void)
+create_xlog_or_symlink(void)
{
- /* Create transaction log symlink, if required */
+ char *subdirloc;
+
+ /* form name of the place for the subdirectory or symlink */
+ subdirloc = psprintf("%s/pg_xlog", pg_data);
+
if (strcmp(xlog_dir, "") != 0)
{
- char *linkloc;
int ret;
/* clean up xlog directory name, check it's absolute */
@@ -3246,22 +3249,30 @@ create_xlog_symlink(void)
exit_nicely();
}
- /* form name of the place where the symlink must go */
- linkloc = psprintf("%s/pg_xlog", pg_data);
-
#ifdef HAVE_SYMLINK
- if (symlink(xlog_dir, linkloc) != 0)
+ if (symlink(xlog_dir, subdirloc) != 0)
{
fprintf(stderr, _("%s: could not create symbolic link \"%s\": %s\n"),
- progname, linkloc, strerror(errno));
+ progname, subdirloc, strerror(errno));
exit_nicely();
}
#else
fprintf(stderr, _("%s: symlinks are not supported on this platform"));
exit_nicely();
#endif
- free(linkloc);
}
+ else
+ {
+ /* Without -X option, just make the subdirectory normally */
+ if (mkdir(subdirloc, S_IRWXU) < 0)
+ {
+ fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
+ progname, subdirloc, strerror(errno));
+ exit_nicely();
+ }
+ }
+
+ free(subdirloc);
}
@@ -3292,9 +3303,9 @@ initialize_data_directory(void)
create_data_directory();
- create_xlog_symlink();
+ create_xlog_or_symlink();
- /* Create required subdirectories */
+ /* Create required subdirectories (other than pg_xlog) */
printf(_("creating subdirectories ... "));
fflush(stdout);