aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/Makefile13
-rw-r--r--src/backend/postmaster/postmaster.c71
-rw-r--r--src/backend/utils/adt/version.c3
-rw-r--r--src/backend/utils/init/miscinit.c51
-rw-r--r--src/backend/utils/init/postinit.c11
5 files changed, 80 insertions, 69 deletions
diff --git a/src/backend/Makefile b/src/backend/Makefile
index ab691cef462..5c3a520fbdd 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -34,7 +34,7 @@
#
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.56 2000/06/28 03:30:57 tgl Exp $
+# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.57 2000/07/02 15:20:44 petere Exp $
#
#-------------------------------------------------------------------------
@@ -57,10 +57,8 @@ ifeq ($(PORTNAME), qnx4)
OBJS+= bootstrap/bootstrap.o
endif
-VERSIONOBJ = $(SRCDIR)/utils/version.o
-
ifeq ($(MAKE_DLL), true)
-DLLOBJS= $(OBJS) $(VERSIONOBJ)
+DLLOBJS= $(OBJS)
DLLLIBS= -L/usr/local/lib -lcygipc -lcrypt -lcygwin -lkernel32
postgres.def: $(DLLOBJS)
@@ -74,8 +72,8 @@ all: prebuildheaders postgres $(POSTGRES_IMP)
ifneq ($(PORTNAME), win)
-postgres: $(OBJS) $(VERSIONOBJ)
- $(CC) $(CFLAGS) -o postgres $(OBJS) $(VERSIONOBJ) $(LDFLAGS)
+postgres: $(OBJS)
+ $(CC) $(CFLAGS) -o postgres $(OBJS) $(LDFLAGS)
else
@@ -93,9 +91,6 @@ $(OBJS): $(DIRS:%=%.dir)
$(DIRS:%=%.dir):
$(MAKE) -C $(subst .dir,,$@) all
-$(VERSIONOBJ): $(SRCDIR)/utils/version.c $(SRCDIR)/include/version.h
- $(MAKE) -C $(SRCDIR)/utils version.o
-
$(SRCDIR)/utils/dllinit.o: $(SRCDIR)/utils/dllinit.c
$(MAKE) -C $(SRCDIR)/utils dllinit.o
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 135b6d5950e..f7d2e0d8a6d 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.150 2000/06/28 03:31:52 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.151 2000/07/02 15:20:48 petere Exp $
*
* NOTES
*
@@ -84,7 +84,6 @@
#include "access/xlog.h"
#include "tcop/tcopprot.h"
#include "utils/guc.h"
-#include "version.h"
/*
* "postmaster.opts" is a file containing options for postmaser.
@@ -300,8 +299,11 @@ int assert_enabled = 1;
#endif
static void
-checkDataDir(const char *DataDir, bool *DataDirOK)
+checkDataDir(const char *DataDir)
{
+ char path[MAXPGPATH];
+ FILE *fp;
+
if (DataDir == NULL)
{
fprintf(stderr, "%s does not know where to find the database system "
@@ -309,59 +311,35 @@ checkDataDir(const char *DataDir, bool *DataDirOK)
"database system either by specifying the -D invocation "
"option or by setting the PGDATA environment variable.\n\n",
progname);
- *DataDirOK = false;
+ exit(2);
}
- else
- {
- char path[MAXPGPATH];
- FILE *fp;
- snprintf(path, sizeof(path), "%s%cbase%ctemplate1%cpg_class",
- DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR);
- fp = AllocateFile(path, PG_BINARY_R);
- if (fp == NULL)
- {
- fprintf(stderr, "%s does not find the database system. "
- "Expected to find it "
- "in the PGDATA directory \"%s\", but unable to open file "
- "with pathname \"%s\".\n\n",
- progname, DataDir, path);
- *DataDirOK = false;
- }
- else
- {
- char *reason;
+ snprintf(path, sizeof(path), "%s%cbase%ctemplate1%cpg_class",
+ DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR);
- /* reason ValidatePgVersion failed. NULL if didn't */
+ fp = AllocateFile(path, PG_BINARY_R);
+ if (fp == NULL)
+ {
+ fprintf(stderr, "%s does not find the database system. "
+ "Expected to find it "
+ "in the PGDATA directory \"%s\", but unable to open file "
+ "with pathname \"%s\".\n\n",
+ progname, DataDir, path);
+ exit(2);
+ }
- FreeFile(fp);
+ FreeFile(fp);
- ValidatePgVersion(DataDir, &reason);
- if (reason)
- {
- fprintf(stderr,
- "Database system in directory %s "
- "is not compatible with this version of "
- "Postgres, or we are unable to read the "
- "PG_VERSION file. "
- "Explanation from ValidatePgVersion: %s\n\n",
- DataDir, reason);
- free(reason);
- *DataDirOK = false;
- }
- else
- *DataDirOK = true;
- }
- }
+ ValidatePgVersion(DataDir);
}
+
int
PostmasterMain(int argc, char *argv[])
{
int opt;
int status;
int silentflag = 0;
- bool DataDirOK; /* We have a usable PGDATA value */
char original_extraoptions[MAXPGPATH];
IsUnderPostmaster = true; /* so that backends know this */
@@ -435,12 +413,7 @@ PostmasterMain(int argc, char *argv[])
}
optind = 1; /* start over */
- checkDataDir(DataDir, &DataDirOK); /* issues error messages */
- if (!DataDirOK)
- {
- fprintf(stderr, "No data directory -- can't proceed.\n");
- exit(2);
- }
+ checkDataDir(DataDir); /* issues error messages */
ProcessConfigFile(PGC_POSTMASTER);
diff --git a/src/backend/utils/adt/version.c b/src/backend/utils/adt/version.c
index 2d4dd5cf273..4914acc8e35 100644
--- a/src/backend/utils/adt/version.c
+++ b/src/backend/utils/adt/version.c
@@ -5,14 +5,13 @@
*
* IDENTIFICATION
*
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/version.c,v 1.9 1999/07/17 20:18:00 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/version.c,v 1.10 2000/07/02 15:20:51 petere Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
-#include "version.h"
text *version(void);
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index eaee59d81fe..2b63ace0eca 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.50 2000/06/14 18:17:46 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.51 2000/07/02 15:20:56 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -24,6 +24,7 @@
#include <grp.h>
#include <pwd.h>
#include <stdlib.h>
+#include <errno.h>
#include "catalog/catname.h"
#include "catalog/pg_shadow.h"
@@ -520,3 +521,51 @@ SetPidFile(pid_t pid)
return (0);
}
+
+
+
+/*
+ * Determine whether the PG_VERSION file in directory `path' indicates
+ * a data version compatible with the version of this program.
+ *
+ * If compatible, return. Otherwise, elog(FATAL).
+ */
+void
+ValidatePgVersion(const char *path)
+{
+ char full_path[MAXPGPATH];
+ FILE *file;
+ int ret;
+ long file_major, file_minor;
+ long my_major = 0, my_minor = 0;
+ char *endptr;
+ const char *version_string = PG_VERSION;
+
+ my_major = strtol(version_string, &endptr, 10);
+ if (*endptr == '.')
+ my_minor = strtol(endptr+1, NULL, 10);
+
+ snprintf(full_path, MAXPGPATH, "%s/PG_VERSION", path);
+
+ file = AllocateFile(full_path, "r");
+ if (!file)
+ {
+ if (errno == ENOENT)
+ elog(FATAL, "File %s is missing. This is not a valid data directory.", full_path);
+ else
+ elog(FATAL, "cannot open %s: %s", full_path, strerror(errno));
+ }
+
+ ret = fscanf(file, "%ld.%ld", &file_major, &file_minor);
+ if (ret == EOF)
+ elog(FATAL, "cannot read %s: %s", full_path, strerror(errno));
+ else if (ret != 2)
+ elog(FATAL, "`%s' does not have a valid format. You need to initdb.", full_path);
+
+ FreeFile(file);
+
+ if (my_major != file_major || my_minor != file_minor)
+ elog(FATAL, "The data directory was initalized by PostgreSQL version %ld.%ld, "
+ "which is not compatible with this verion %s.",
+ file_major, file_minor, version_string);
+}
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index f2a5864666c..813eb131174 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.60 2000/06/28 03:32:43 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.61 2000/07/02 15:20:56 petere Exp $
*
*
*-------------------------------------------------------------------------
@@ -34,7 +34,6 @@
#include "utils/portal.h"
#include "utils/relcache.h"
#include "utils/syscache.h"
-#include "version.h"
#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
@@ -267,9 +266,7 @@ InitPostgres(const char *dbname)
elog(FATAL, "Database system not found. Data directory '%s' does not exist.",
DataDir);
- ValidatePgVersion(DataDir, &reason);
- if (reason != NULL)
- elog(FATAL, reason);
+ ValidatePgVersion(DataDir);
/*-----------------
* Find oid and path of the database we're about to open. Since we're
@@ -300,9 +297,7 @@ InitPostgres(const char *dbname)
elog(FATAL, "Database \"%s\" does not exist. The data directory '%s' is missing.",
dbname, fullpath);
- ValidatePgVersion(fullpath, &reason);
- if (reason != NULL)
- elog(FATAL, "%s", reason);
+ ValidatePgVersion(fullpath);
if (chdir(fullpath) == -1)
elog(FATAL, "Unable to change directory to '%s': %s", fullpath, strerror(errno));