1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-13 07:41:39 +03:00

Make the backend grok relative paths for the data directory by converting

it to an absolute path.
This commit is contained in:
Peter Eisentraut
2000-11-04 12:43:24 +00:00
parent 7bea44f449
commit abfb417574
5 changed files with 111 additions and 42 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.55 2000/09/19 18:17:57 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.56 2000/11/04 12:43:24 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -366,6 +366,62 @@ GetUserName(Oid userid)
/*-------------------------------------------------------------------------
* Set data directory, but make sure it's an absolute path. Use this,
* never set DataDir directly.
*-------------------------------------------------------------------------
*/
void
SetDataDir(const char *dir)
{
char *new;
AssertArg(dir);
if (DataDir)
free(DataDir);
if (dir[0] != '/')
{
char *buf;
size_t buflen;
buflen = MAXPGPATH;
for (;;)
{
buf = malloc(buflen);
if (!buf)
elog(FATAL, "out of memory");
if (getcwd(buf, buflen))
break;
else if (errno == ERANGE)
{
free(buf);
buflen *= 2;
continue;
}
else
{
free(buf);
elog(FATAL, "cannot get current working directory: %m");
}
}
new = malloc(strlen(buf) + 1 + strlen(dir) + 1);
sprintf(new, "%s/%s", buf, dir);
}
else
{
new = strdup(dir);
}
if (!new)
elog(FATAL, "out of memory");
DataDir = new;
}
/*-------------------------------------------------------------------------
*
* postmaster pid file stuffs. $DATADIR/postmaster.pid is created when: