Skip to content

Commit b41fb65

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 fa838b5 commit b41fb65

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
@@ -193,7 +193,6 @@ static const char *backend_options = "--single -F -O -j -c search_path=pg_catalo
193193

194194
static const char *const subdirs[] = {
195195
"global",
196-
"pg_xlog",
197196
"pg_xlog/archive_status",
198197
"pg_clog",
199198
"pg_commit_ts",
@@ -280,7 +279,7 @@ void setup_locale_encoding(void);
280279
void setup_signals(void);
281280
void setup_text_search(void);
282281
void create_data_directory(void);
283-
void create_xlog_symlink(void);
282+
void create_xlog_or_symlink(void);
284283
void warn_on_mount_point(int error);
285284
void initialize_data_directory(void);
286285

@@ -2948,13 +2947,17 @@ create_data_directory(void)
29482947
}
29492948

29502949

2950+
/* Create transaction log directory, and symlink if required */
29512951
void
2952-
create_xlog_symlink(void)
2952+
create_xlog_or_symlink(void)
29532953
{
2954-
/* Create transaction log symlink, if required */
2954+
char *subdirloc;
2955+
2956+
/* form name of the place for the subdirectory or symlink */
2957+
subdirloc = psprintf("%s/pg_xlog", pg_data);
2958+
29552959
if (strcmp(xlog_dir, "") != 0)
29562960
{
2957-
char *linkloc;
29582961
int ret;
29592962

29602963
/* clean up xlog directory name, check it's absolute */
@@ -3027,22 +3030,30 @@ create_xlog_symlink(void)
30273030
exit_nicely();
30283031
}
30293032

3030-
/* form name of the place where the symlink must go */
3031-
linkloc = psprintf("%s/pg_xlog", pg_data);
3032-
30333033
#ifdef HAVE_SYMLINK
3034-
if (symlink(xlog_dir, linkloc) != 0)
3034+
if (symlink(xlog_dir, subdirloc) != 0)
30353035
{
30363036
fprintf(stderr, _("%s: could not create symbolic link \"%s\": %s\n"),
3037-
progname, linkloc, strerror(errno));
3037+
progname, subdirloc, strerror(errno));
30383038
exit_nicely();
30393039
}
30403040
#else
30413041
fprintf(stderr, _("%s: symlinks are not supported on this platform"));
30423042
exit_nicely();
30433043
#endif
3044-
free(linkloc);
30453044
}
3045+
else
3046+
{
3047+
/* Without -X option, just make the subdirectory normally */
3048+
if (mkdir(subdirloc, S_IRWXU) < 0)
3049+
{
3050+
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
3051+
progname, subdirloc, strerror(errno));
3052+
exit_nicely();
3053+
}
3054+
}
3055+
3056+
free(subdirloc);
30463057
}
30473058

30483059

@@ -3074,9 +3085,9 @@ initialize_data_directory(void)
30743085

30753086
create_data_directory();
30763087

3077-
create_xlog_symlink();
3088+
create_xlog_or_symlink();
30783089

3079-
/* Create required subdirectories */
3090+
/* Create required subdirectories (other than pg_xlog) */
30803091
printf(_("creating subdirectories ... "));
30813092
fflush(stdout);
30823093

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy