4242 * Portions Copyright (c) 1994, Regents of the University of California
4343 * Portions taken from FreeBSD.
4444 *
45- * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.181 2010/01/02 16:57:58 momjian Exp $
45+ * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.182 2010/01/06 23:23:51 momjian Exp $
4646 *
4747 *-------------------------------------------------------------------------
4848 */
@@ -156,16 +156,15 @@ static intmkdir_p(char *path, mode_t omode);
156156static void exit_nicely (void );
157157static char * get_id (void );
158158static char * get_encoding_id (char * encoding_name );
159- static char * get_short_version (void );
160159static int check_data_dir (char * dir );
161160static bool mkdatadir (const char * subdir );
162161static void set_input (char * * dest ,char * filename );
163162static void check_input (char * path );
164- static void set_short_version ( char * short_version , char * extrapath );
163+ static void write_version_file ( char * extrapath );
165164static void set_null_conf (void );
166165static void test_config_settings (void );
167166static void setup_config (void );
168- static void bootstrap_template1 (char * short_version );
167+ static void bootstrap_template1 (void );
169168static void setup_auth (void );
170169static void get_set_pwd (void );
171170static void setup_depend (void );
@@ -802,42 +801,6 @@ find_matching_ts_config(const char *lc_type)
802801}
803802
804803
805- /*
806- * get short version of VERSION
807- */
808- static char *
809- get_short_version (void )
810- {
811- bool gotdot = false;
812- int end ;
813- char * vr ;
814-
815- vr = xstrdup (PG_VERSION );
816-
817- for (end = 0 ;vr [end ]!= '\0' ;end ++ )
818- {
819- if (vr [end ]== '.' )
820- {
821- if (end == 0 )
822- return NULL ;
823- else if (gotdot )
824- break ;
825- else
826- gotdot = true;
827- }
828- else if (vr [end ]< '0' || vr [end ]> '9' )
829- {
830- /* gone past digits and dots */
831- break ;
832- }
833- }
834- if (end == 0 || vr [end - 1 ]== '.' || !gotdot )
835- return NULL ;
836-
837- vr [end ]= '\0' ;
838- return vr ;
839- }
840-
841804/*
842805 * make sure the directory either doesn't exist or is empty
843806 *
@@ -972,7 +935,7 @@ check_input(char *path)
972935 * if extrapath is not NULL
973936 */
974937static void
975- set_short_version ( char * short_version , char * extrapath )
938+ write_version_file ( char * extrapath )
976939{
977940FILE * version_file ;
978941char * path ;
@@ -987,14 +950,14 @@ set_short_version(char *short_version, char *extrapath)
987950path = pg_malloc (strlen (pg_data )+ strlen (extrapath )+ 13 );
988951sprintf (path ,"%s/%s/PG_VERSION" ,pg_data ,extrapath );
989952}
990- version_file = fopen ( path , PG_BINARY_W );
991- if (version_file == NULL )
953+
954+ if (( version_file = fopen ( path , PG_BINARY_W )) == NULL )
992955{
993956fprintf (stderr ,_ ("%s: could not open file \"%s\" for writing: %s\n" ),
994957progname ,path ,strerror (errno ));
995958exit_nicely ();
996959}
997- if (fprintf (version_file ,"%s\n" ,short_version )< 0 ||
960+ if (fprintf (version_file ,"%s\n" ,PG_MAJORVERSION )< 0 ||
998961fclose (version_file ))
999962{
1000963fprintf (stderr ,_ ("%s: could not write file \"%s\": %s\n" ),
@@ -1297,7 +1260,7 @@ setup_config(void)
12971260 * run the BKI script in bootstrap mode to create template1
12981261 */
12991262static void
1300- bootstrap_template1 (char * short_version )
1263+ bootstrap_template1 (void )
13011264{
13021265PG_CMD_DECL ;
13031266char * * line ;
@@ -1317,7 +1280,7 @@ bootstrap_template1(char *short_version)
13171280/* Check that bki file appears to be of the right version */
13181281
13191282snprintf (headerline ,sizeof (headerline ),"# PostgreSQL %s\n" ,
1320- short_version );
1283+ PG_MAJORVERSION );
13211284
13221285if (strcmp (headerline ,* bki_lines )!= 0 )
13231286{
@@ -2480,7 +2443,6 @@ main(int argc, char *argv[])
24802443i ,
24812444ret ;
24822445int option_index ;
2483- char * short_version ;
24842446char * effective_user ;
24852447char * pgdenv ;/* PGDATA value gotten from and sent to
24862448 * environment */
@@ -2788,12 +2750,6 @@ main(int argc, char *argv[])
27882750
27892751canonicalize_path (share_path );
27902752
2791- if ((short_version = get_short_version ())== NULL )
2792- {
2793- fprintf (stderr ,_ ("%s: could not determine valid short version string\n" ),progname );
2794- exit (1 );
2795- }
2796-
27972753effective_user = get_id ();
27982754if (strlen (username )== 0 )
27992755username = effective_user ;
@@ -3123,7 +3079,7 @@ main(int argc, char *argv[])
31233079check_ok ();
31243080
31253081/* Top level PG_VERSION is checked by bootstrapper, so make it first */
3126- set_short_version ( short_version , NULL );
3082+ write_version_file ( NULL );
31273083
31283084/* Select suitable configuration settings */
31293085set_null_conf ();
@@ -3133,12 +3089,12 @@ main(int argc, char *argv[])
31333089setup_config ();
31343090
31353091/* Bootstrap template1 */
3136- bootstrap_template1 (short_version );
3092+ bootstrap_template1 ();
31373093
31383094/*
31393095 * Make the per-database PG_VERSION for template1 only after init'ing it
31403096 */
3141- set_short_version ( short_version , "base/1" );
3097+ write_version_file ( "base/1" );
31423098
31433099/* Create the stuff we don't need to use bootstrap mode for */
31443100