1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-12 05:01:15 +03:00

Make initdb safe against using

a) mismatching backend program, by checking --version output
b) mismatching bki files, by putting a version-identifying comment atop
   those files.
This commit is contained in:
Peter Eisentraut
2000-10-28 22:14:14 +00:00
parent c44323176e
commit 3280cba2ac
3 changed files with 75 additions and 39 deletions

View File

@@ -2,7 +2,7 @@
#
# Makefile for catalog
#
# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.31 2000/10/24 01:38:23 tgl Exp $
# $Header: /cvsroot/pgsql/src/backend/catalog/Makefile,v 1.32 2000/10/28 22:14:14 petere Exp $
#
#-------------------------------------------------------------------------
@@ -39,11 +39,11 @@ pg_includes := $(sort -I$(top_srcdir)/src/include -I$(top_builddir)/src/include)
global.bki global.description: genbki.sh $(GLOBAL_BKI_SRCS) $(top_srcdir)/src/include/catalog/indexing.h \
$(top_srcdir)/src/include/postgres_ext.h $(top_builddir)/src/include/config.h
CPP='$(CPP)' AWK='$(AWK)' $(SHELL) $< $(BKIOPTS) -o global $(pg_includes) $(GLOBAL_BKI_SRCS)
CPP='$(CPP)' AWK='$(AWK)' $(SHELL) $< $(BKIOPTS) -o global $(pg_includes) $(GLOBAL_BKI_SRCS) --set-version=$(VERSION)
template1.bki template1.description: genbki.sh $(TEMPLATE1_BKI_SRCS) \
$(top_srcdir)/src/include/postgres_ext.h $(top_builddir)/src/include/config.h
CPP='$(CPP)' AWK='$(AWK)' $(SHELL) $< $(BKIOPTS) -o template1 $(pg_includes) $(TEMPLATE1_BKI_SRCS)
CPP='$(CPP)' AWK='$(AWK)' $(SHELL) $< $(BKIOPTS) -o template1 $(pg_includes) $(TEMPLATE1_BKI_SRCS) --set-version=$(VERSION)
.PHONY: install-bki
install-bki: $(BKIFILES) installdirs

View File

@@ -10,7 +10,7 @@
#
#
# IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/catalog/Attic/genbki.sh,v 1.17 2000/10/20 21:03:42 petere Exp $
# $Header: /cvsroot/pgsql/src/backend/catalog/Attic/genbki.sh,v 1.18 2000/10/28 22:14:14 petere Exp $
#
# NOTES
# non-essential whitespace is removed from the generated file.
@@ -28,6 +28,7 @@ BKIOPTS=
INCLUDE_DIRS=
OUTPUT_PREFIX=
INFILES=
major_version=
#
# Process command line switches.
@@ -54,15 +55,20 @@ do
-o*)
OUTPUT_PREFIX=`echo $1 | sed -e 's/^-o//'`
;;
--set-version=*)
arg=`expr x"$1" : x"--set-version=\(.*\)"`
major_version=`expr x"$arg" : x'\([0-9][0-9]*\.[0-9][0-9]*\)'`
;;
--help)
echo "$CMDNAME generates system catalog bootstrapping files."
echo
echo "Usage:"
echo " $CMDNAME [ -D define [...] ] [ -I dir ] [ -o prefix ]"
echo " $CMDNAME [ -D define [...] ] [ -I dir ] --set-version=VERSION -o prefix files..."
echo
echo "Options:"
echo " -I path to postgres_ext.h and config.h files"
echo " -o prefix of output files"
echo " --set-version PostgreSQL version number for initdb cross-check"
echo
echo "The environment variables CPP and AWK determine which C"
echo "preprocessor and Awk program to use. The defaults are"
@@ -97,6 +103,10 @@ if [ x"$INCLUDE_DIRS" = x"" ] ; then
exit 1
fi
if [ x"$major_version" = x"" ] ; then
echo "$CMDNAME: invalid or no version number specified" 1>&2
exit 1
fi
if [ x"$TMPDIR" = x"" ] ; then
TMPDIR=/tmp
@@ -105,12 +115,7 @@ fi
TMPFILE="$TMPDIR/genbkitmp.c"
trap "rm -f $TMPFILE" 0 1 2 3 15
# clear output files
> ${OUTPUT_PREFIX}.bki
> ${OUTPUT_PREFIX}.description
trap "rm -f $TMPFILE ${OUTPUT_PREFIX}.bki.$$ ${OUTPUT_PREFIX}.description.$$" 0 1 2 3 15
# Get NAMEDATALEN from postgres_ext.h
@@ -136,6 +141,8 @@ done
INDEXMAXKEYS2=`expr $INDEXMAXKEYS '*' 2` || exit
INDEXMAXKEYS4=`expr $INDEXMAXKEYS '*' 4` || exit
touch ${OUTPUT_PREFIX}.description.$$
# ----------------
# strip comments and trash from .h before we generate
# the .bki file...
@@ -360,11 +367,15 @@ END {
reln_open = 0;
}
}
' "descriptionfile=${OUTPUT_PREFIX}.description" > $TMPFILE || exit
' "descriptionfile=${OUTPUT_PREFIX}.description.$$" > $TMPFILE || exit
echo "# PostgreSQL $major_version" >${OUTPUT_PREFIX}.bki.$$
$CPP $BKIOPTS $TMPFILE | \
sed -e '/^[ ]*$/d' \
-e 's/[ ][ ]*/ /g' > ${OUTPUT_PREFIX}.bki || exit
-e 's/[ ][ ]*/ /g' >>${OUTPUT_PREFIX}.bki.$$ || exit
mv ${OUTPUT_PREFIX}.bki.$$ ${OUTPUT_PREFIX}.bki || exit
mv ${OUTPUT_PREFIX}.description.$$ ${OUTPUT_PREFIX}.description || exit
exit 0