3737 *
3838 *
3939 * IDENTIFICATION
40- * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.385 2004/05/12 13:38:39 momjian Exp $
40+ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.386 2004/05/13 22:45:02 momjian Exp $
4141 *
4242 * NOTES
4343 *
@@ -181,7 +181,6 @@ static int ListenSocket[MAXLISTEN];
181181/* Used to reduce macros tests */
182182#ifdef EXEC_BACKEND
183183const bool ExecBackend = true;
184-
185184#else
186185const bool ExecBackend = false;
187186#endif
@@ -286,7 +285,7 @@ static long PostmasterRandom(void);
286285static void RandomSalt (char * cryptSalt , char * md5Salt );
287286static void SignalChildren (int signal );
288287static int CountChildren (void );
289- static bool CreateOptsFile (int argc , char * argv []);
288+ static bool CreateOptsFile (int argc , char * argv [], char * fullprogname );
290289NON_EXEC_STATIC void SSDataBaseInit (int xlop );
291290static pid_t SSDataBase (int xlop );
292291static void
@@ -295,6 +294,9 @@ postmaster_error(const char *fmt,...)
295294__attribute__((format (printf , 1 , 2 )));
296295
297296#ifdef EXEC_BACKEND
297+
298+ static char postgres_exec_path [MAXPGPATH ];
299+
298300#ifdef WIN32
299301pid_t win32_forkexec (const char * path , char * argv []);
300302
@@ -323,7 +325,6 @@ static void ShmemBackendArrayRemove(pid_t pid);
323325#define StartBackgroundWriter () SSDataBase(BS_XLOG_BGWRITER)
324326#define ShutdownDataBase () SSDataBase(BS_XLOG_SHUTDOWN)
325327
326-
327328static void
328329checkDataDir (const char * checkdir )
329330{
@@ -692,11 +693,18 @@ PostmasterMain(int argc, char *argv[])
692693 /*
693694 * On some systems our dynloader code needs the executable's pathname.
694695 */
695- if (find_my_exec (pg_pathname , argv [0 ]) < 0 )
696+ if (find_my_exec (my_exec_path , argv [0 ]) < 0 )
696697 ereport (FATAL ,
697- (errmsg ("%s: could not locate postgres executable" ,
698+ (errmsg ("%s: could not locate my own executable path " ,
698699 progname )));
699700
701+ #ifdef EXEC_BACKEND
702+ if (find_other_exec (postgres_exec_path , argv [0 ], "postgres" , PG_VERSIONSTR ) < 0 )
703+ ereport (FATAL ,
704+ (errmsg ("%s: could not locate postgres executable or non-matching version" ,
705+ progname )));
706+ #endif
707+
700708 /*
701709 * Initialize SSL library, if specified.
702710 */
@@ -852,7 +860,7 @@ PostmasterMain(int argc, char *argv[])
852860 * recording bogus options (eg, NBuffers too high for available
853861 * memory).
854862 */
855- if (!CreateOptsFile (argc , argv ))
863+ if (!CreateOptsFile (argc , argv , my_exec_path ))
856864 ExitPostmaster (1 );
857865
858866 /*
@@ -2754,10 +2762,10 @@ Backend_forkexec(Port *port)
27542762 Assert (ac <= lengthof (av ));
27552763
27562764#ifdef WIN32
2757- pid = win32_forkexec (pg_pathname , av ); /* logs on error */
2765+ pid = win32_forkexec (postgres_exec_path , av ); /* logs on error */
27582766#else
27592767 /* Fire off execv in child */
2760- if ((pid = fork ()) == 0 && (execv (pg_pathname , av ) == -1 ))
2768+ if ((pid = fork ()) == 0 && (execv (postgres_exec_path , av ) == -1 ))
27612769 /*
27622770 * FIXME: [fork/exec] suggestions for what to do here?
27632771 * Probably OK to issue error (unlike pgstat case)
@@ -3116,12 +3124,12 @@ SSDataBase(int xlop)
31163124#ifdef EXEC_BACKEND
31173125 /* EXEC_BACKEND case; fork/exec here */
31183126#ifdef WIN32
3119- pid = win32_forkexec (pg_pathname , av ); /* logs on error */
3127+ pid = win32_forkexec (postgres_exec_path , av ); /* logs on error */
31203128#else
3121- if ((pid = fork ()) == 0 && (execv (pg_pathname , av ) == -1 ))
3129+ if ((pid = fork ()) == 0 && (execv (postgres_exec_path , av ) == -1 ))
31223130 {
31233131 /* in child */
3124- elog (ERROR ,"unable to execv in SSDataBase: %m" );
3132+ elog (ERROR , "unable to execv in SSDataBase: %m" );
31253133 exit (0 );
31263134 }
31273135#endif
@@ -3215,19 +3223,12 @@ SSDataBase(int xlop)
32153223 * Create the opts file
32163224 */
32173225static bool
3218- CreateOptsFile (int argc , char * argv [])
3226+ CreateOptsFile (int argc , char * argv [], char * fullprogname )
32193227{
3220- char fullprogname [MAXPGPATH ];
32213228 char filename [MAXPGPATH ];
32223229 FILE * fp ;
32233230 int i ;
32243231
3225- if (find_my_exec (fullprogname , argv [0 ]) < 0 )
3226- {
3227- elog (LOG , "could not locate postmaster" );
3228- return false;
3229- }
3230-
32313232 snprintf (filename , sizeof (filename ), "%s/postmaster.opts" , DataDir );
32323233
32333234 if ((fp = fopen (filename , "w" )) == NULL )
0 commit comments