Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 51e61b0

Browse files
committed
Ensure pg_ctl behaves sanely when data directory is not specified.
Commit aaa6e1d introduced multiple hazards in the case where pg_ctl is executed with neither a -D switch nor any PGDATA environment variable. It would dump core on machines which are unforgiving about printf("%s", NULL), or failing that possibly give a rather unhelpful complaint about being unable to execute "postgres -C", rather than the logically prior complaint about not being told where the data directory is. Edmund Horner's report suggests that there is another, Windows-specific hazard here, but I'm not the person to fix that; it would in any case only be significant when trying to use a config-only PGDATA pointer.
1 parent bf0945e commit 51e61b0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/bin/pg_ctl/pg_ctl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,10 @@ adjust_data_dir(void)
19021902
*my_exec_path;
19031903
FILE *fd;
19041904

1905+
/* do nothing if we're working without knowledge of data dir */
1906+
if (pg_config == NULL)
1907+
return;
1908+
19051909
/* If there is no postgresql.conf, it can't be a config-only dir */
19061910
snprintf(filename, sizeof(filename), "%s/postgresql.conf", pg_config);
19071911
if ((fd = fopen(filename, "r")) == NULL)
@@ -2188,8 +2192,10 @@ main(int argc, char **argv)
21882192
pg_data = xstrdup(pg_config);
21892193
}
21902194

2195+
/* -D might point at config-only directory; if so find the real PGDATA */
21912196
adjust_data_dir();
21922197

2198+
/* Complain if -D needed and not provided */
21932199
if (pg_config == NULL &&
21942200
ctl_command != KILL_COMMAND && ctl_command != UNREGISTER_COMMAND)
21952201
{

0 commit comments

Comments
 (0)