it to an absolute path.
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.95 2000/10/24 09:56:09 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.96 2000/11/04 12:43:23 petere Exp $
*
*-------------------------------------------------------------------------
*/
+#include "postgres.h"
+
#include <unistd.h>
#include <time.h>
#include <signal.h>
#define BOOTSTRAP_INCLUDE /* mask out stuff in tcop/tcopprot.h */
-#include "postgres.h"
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
char *dbName;
int flag;
bool xloginit = false;
+ char *potential_DataDir = NULL;
extern int optind;
extern char *optarg;
if (!IsUnderPostmaster)
{
ResetAllOptions();
- DataDir = getenv("PGDATA"); /* Null if no PGDATA variable */
+ potential_DataDir = getenv("PGDATA"); /* Null if no PGDATA variable */
}
while ((flag = getopt(argc, argv, "D:dCQxpB:F")) != EOF)
switch (flag)
{
case 'D':
- DataDir = optarg;
+ potential_DataDir = optarg;
break;
case 'd':
DebugMode = true; /* print out debugging info while
SetProcessingMode(BootstrapProcessing);
IgnoreSystemIndexes(true);
- if (!DataDir)
+ if (!IsUnderPostmaster)
{
- fprintf(stderr, "%s does not know where to find the database system "
- "data. You must specify the directory that contains the "
- "database system either by specifying the -D invocation "
- "option or by setting the PGDATA environment variable.\n\n",
- argv[0]);
- proc_exit(1);
+ if (!potential_DataDir)
+ {
+ fprintf(stderr, "%s does not know where to find the database system "
+ "data. You must specify the directory that contains the "
+ "database system either by specifying the -D invocation "
+ "option or by setting the PGDATA environment variable.\n\n",
+ argv[0]);
+ proc_exit(1);
+ }
+ SetDataDir(potential_DataDir);
}
+ Assert(DataDir);
if (dbName == NULL)
{
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.177 2000/11/01 21:14:02 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.178 2000/11/04 12:43:23 petere Exp $
*
* NOTES
*
static void
-checkDataDir(const char *DataDir)
+checkDataDir(const char *checkdir)
{
char path[MAXPGPATH];
FILE *fp;
- if (DataDir == NULL)
+ if (checkdir == NULL)
{
fprintf(stderr, "%s does not know where to find the database system "
"data. You must specify the directory that contains the "
#ifdef OLD_FILE_NAMING
snprintf(path, sizeof(path), "%s%cbase%ctemplate1%cpg_class",
- DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR);
+ checkdir, SEP_CHAR, SEP_CHAR, SEP_CHAR);
#else
snprintf(path, sizeof(path), "%s%cbase%c%u%c%u",
- DataDir, SEP_CHAR, SEP_CHAR,
+ checkdir, SEP_CHAR, SEP_CHAR,
TemplateDbOid, SEP_CHAR, RelOid_pg_class);
#endif
fprintf(stderr, "%s does not find the database system."
"\n\tExpected to find it in the PGDATA directory \"%s\","
"\n\tbut unable to open file \"%s\": %s\n\n",
- progname, DataDir, path, strerror(errno));
+ progname, checkdir, path, strerror(errno));
exit(2);
}
FreeFile(fp);
- ValidatePgVersion(DataDir);
+ ValidatePgVersion(checkdir);
}
int opt;
int status;
char original_extraoptions[MAXPGPATH];
+ char *potential_DataDir = NULL;
IsUnderPostmaster = true; /* so that backends know this */
/*
* Options setup
*/
- if (getenv("PGDATA"))
- DataDir = strdup(getenv("PGDATA")); /* default value */
+ potential_DataDir = getenv("PGDATA"); /* default value */
ResetAllOptions();
switch(opt)
{
case 'D':
- if (DataDir)
- free(DataDir);
- DataDir = strdup(optarg);
+ potential_DataDir = optarg;
break;
case '-':
}
}
- optind = 1; /* start over */
- checkDataDir(DataDir); /* issues error messages */
+ checkDataDir(potential_DataDir); /* issues error messages */
+ SetDataDir(potential_DataDir);
ProcessConfigFile(PGC_POSTMASTER);
IgnoreSystemIndexes(false);
+
+ optind = 1; /* start over */
while ((opt = getopt(argc, argv, "A:a:B:b:D:d:Film:MN:no:p:Ss-:?")) != EOF)
{
switch (opt)
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.184 2000/10/28 18:27:56 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.185 2000/11/04 12:43:24 petere Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
#include <errno.h>
#if HAVE_SYS_SELECT_H
#include <sys/select.h>
-#endif /* aix */
+#endif
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
char *remote_host;
unsigned short remote_port;
+ char *potential_DataDir = NULL;
+
extern int optind;
extern char *optarg;
extern int DebugLvl;
if (!IsUnderPostmaster)
{
ResetAllOptions();
- if (getenv("PGDATA"))
- DataDir = strdup(getenv("PGDATA"));
+ potential_DataDir = getenv("PGDATA");
}
StatFp = stderr;
case 'D': /* PGDATA directory */
if (secure)
{
- if (DataDir)
- free(DataDir);
- DataDir = strdup(optarg);
+ potential_DataDir = optarg;
}
break;
Show_query_stats = false;
}
- if (!DataDir)
+ if (!IsUnderPostmaster)
{
- fprintf(stderr, "%s does not know where to find the database system "
- "data. You must specify the directory that contains the "
- "database system either by specifying the -D invocation "
- "option or by setting the PGDATA environment variable.\n\n",
- argv[0]);
- proc_exit(1);
+ if (!potential_DataDir)
+ {
+ fprintf(stderr, "%s does not know where to find the database system "
+ "data. You must specify the directory that contains the "
+ "database system either by specifying the -D invocation "
+ "option or by setting the PGDATA environment variable.\n\n",
+ argv[0]);
+ proc_exit(1);
+ }
+ SetDataDir(potential_DataDir);
}
+ Assert(DataDir);
/*
* 1. Set BlockSig and UnBlockSig masks. 2. Set up signal handlers. 3.
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
- puts("$Revision: 1.184 $ $Date: 2000/10/28 18:27:56 $\n");
+ puts("$Revision: 1.185 $ $Date: 2000/11/04 12:43:24 $\n");
}
/*
*
*
* 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 $
*
*-------------------------------------------------------------------------
*/
+/*-------------------------------------------------------------------------
+ * 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:
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: miscadmin.h,v 1.68 2000/10/08 09:25:38 ishii Exp $
+ * $Id: miscadmin.h,v 1.69 2000/11/04 12:43:24 petere Exp $
*
* NOTES
* some of the information in this file will be moved to
extern void SetSessionUserId(Oid userid);
extern void SetSessionUserIdFromUserName(const char *username);
+extern void SetDataDir(const char *dir);
+
extern int FindExec(char *full_path, const char *argv0, const char *binary_name);
extern int CheckPathAccess(char *path, char *name, int open_mode);