Skip to content

Commit 506ef1d

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 32e7e7f commit 506ef1d

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
@@ -189,7 +189,6 @@ static const char *backend_options = "--single -F -O -c search_path=pg_catalog -
189189

190190
static const char *subdirs[] = {
191191
"global",
192-
"pg_xlog",
193192
"pg_xlog/archive_status",
194193
"pg_clog",
195194
"pg_commit_ts",
@@ -276,7 +275,7 @@ void setup_locale_encoding(void);
276275
void setup_signals(void);
277276
void setup_text_search(void);
278277
void create_data_directory(void);
279-
void create_xlog_symlink(void);
278+
void create_xlog_or_symlink(void);
280279
void warn_on_mount_point(int error);
281280
void initialize_data_directory(void);
282281

@@ -3167,13 +3166,17 @@ create_data_directory(void)
31673166
}
31683167

31693168

3169+
/* Create transaction log directory, and symlink if required */
31703170
void
3171-
create_xlog_symlink(void)
3171+
create_xlog_or_symlink(void)
31723172
{
3173-
/* Create transaction log symlink, if required */
3173+
char *subdirloc;
3174+
3175+
/* form name of the place for the subdirectory or symlink */
3176+
subdirloc = psprintf("%s/pg_xlog", pg_data);
3177+
31743178
if (strcmp(xlog_dir, "") != 0)
31753179
{
3176-
char *linkloc;
31773180
int ret;
31783181

31793182
/* clean up xlog directory name, check it's absolute */
@@ -3246,22 +3249,30 @@ create_xlog_symlink(void)
32463249
exit_nicely();
32473250
}
32483251

3249-
/* form name of the place where the symlink must go */
3250-
linkloc = psprintf("%s/pg_xlog", pg_data);
3251-
32523252
#ifdef HAVE_SYMLINK
3253-
if (symlink(xlog_dir, linkloc) != 0)
3253+
if (symlink(xlog_dir, subdirloc) != 0)
32543254
{
32553255
fprintf(stderr, _("%s: could not create symbolic link \"%s\": %s\n"),
3256-
progname, linkloc, strerror(errno));
3256+
progname, subdirloc, strerror(errno));
32573257
exit_nicely();
32583258
}
32593259
#else
32603260
fprintf(stderr, _("%s: symlinks are not supported on this platform"));
32613261
exit_nicely();
32623262
#endif
3263-
free(linkloc);
32643263
}
3264+
else
3265+
{
3266+
/* Without -X option, just make the subdirectory normally */
3267+
if (mkdir(subdirloc, S_IRWXU) < 0)
3268+
{
3269+
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
3270+
progname, subdirloc, strerror(errno));
3271+
exit_nicely();
3272+
}
3273+
}
3274+
3275+
free(subdirloc);
32653276
}
32663277

32673278

@@ -3292,9 +3303,9 @@ initialize_data_directory(void)
32923303

32933304
create_data_directory();
32943305

3295-
create_xlog_symlink();
3306+
create_xlog_or_symlink();
32963307

3297-
/* Create required subdirectories */
3308+
/* Create required subdirectories (other than pg_xlog) */
32983309
printf(_("creating subdirectories ... "));
32993310
fflush(stdout);
33003311

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