mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
Make sure -D is an absolute path when starting server on Windows.
This is needed because Windows services may get started with a different current directory than where pg_ctl is executed. We want relative -D paths to be interpreted relative to pg_ctl's CWD, similarly to what happens on other platforms. In support of this, move the backend's make_absolute_path() function into src/port/path.c (where it probably should have been long since) and get rid of the rather inferior version in pg_regress. Kumar Rajeev Rastogi, reviewed by MauMau
This commit is contained in:
@ -117,77 +117,6 @@ ChangeToDataDir(void)
|
||||
DataDir)));
|
||||
}
|
||||
|
||||
/*
|
||||
* If the given pathname isn't already absolute, make it so, interpreting
|
||||
* it relative to the current working directory.
|
||||
*
|
||||
* Also canonicalizes the path. The result is always a malloc'd copy.
|
||||
*
|
||||
* Note: interpretation of relative-path arguments during postmaster startup
|
||||
* should happen before doing ChangeToDataDir(), else the user will probably
|
||||
* not like the results.
|
||||
*/
|
||||
char *
|
||||
make_absolute_path(const char *path)
|
||||
{
|
||||
char *new;
|
||||
|
||||
/* Returning null for null input is convenient for some callers */
|
||||
if (path == NULL)
|
||||
return NULL;
|
||||
|
||||
if (!is_absolute_path(path))
|
||||
{
|
||||
char *buf;
|
||||
size_t buflen;
|
||||
|
||||
buflen = MAXPGPATH;
|
||||
for (;;)
|
||||
{
|
||||
buf = malloc(buflen);
|
||||
if (!buf)
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
|
||||
if (getcwd(buf, buflen))
|
||||
break;
|
||||
else if (errno == ERANGE)
|
||||
{
|
||||
free(buf);
|
||||
buflen *= 2;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
free(buf);
|
||||
elog(FATAL, "could not get current working directory: %m");
|
||||
}
|
||||
}
|
||||
|
||||
new = malloc(strlen(buf) + strlen(path) + 2);
|
||||
if (!new)
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
sprintf(new, "%s/%s", buf, path);
|
||||
free(buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
new = strdup(path);
|
||||
if (!new)
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
}
|
||||
|
||||
/* Make sure punctuation is canonical, too */
|
||||
canonicalize_path(new);
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* User ID state
|
||||
|
Reference in New Issue
Block a user