1515
1616static void check_data_dir (const char * pg_data );
1717static void check_bin_dir (ClusterInfo * cluster );
18- static int check_exec (const char * dir ,const char * cmdName );
19- static const char * validate_exec (const char * path );
18+ static void validate_exec (const char * dir ,const char * cmdName );
2019
2120
2221/*
@@ -160,58 +159,32 @@ check_data_dir(const char *pg_data)
160159static void
161160check_bin_dir (ClusterInfo * cluster )
162161{
163- check_exec (cluster -> bindir ,"postgres" );
164- check_exec (cluster -> bindir ,"pg_ctl" );
165- check_exec (cluster -> bindir ,"pg_resetxlog" );
162+ validate_exec (cluster -> bindir ,"postgres" );
163+ validate_exec (cluster -> bindir ,"pg_ctl" );
164+ validate_exec (cluster -> bindir ,"pg_resetxlog" );
166165if (cluster == & new_cluster )
167166{
168167/* these are only needed in the new cluster */
169- check_exec (cluster -> bindir ,"pg_config" );
170- check_exec (cluster -> bindir ,"psql" );
171- check_exec (cluster -> bindir ,"pg_dumpall" );
168+ validate_exec (cluster -> bindir ,"pg_config" );
169+ validate_exec (cluster -> bindir ,"psql" );
170+ validate_exec (cluster -> bindir ,"pg_dumpall" );
172171}
173172}
174173
175174
176- /*
177- * check_exec()
178- *
179- *Checks whether either of the two command names (cmdName and alternative)
180- *appears to be an executable (in the given directory). If dir/cmdName is
181- *an executable, this function returns 1. If dir/alternative is an
182- *executable, this function returns 2. If neither of the given names is
183- *a valid executable, this function returns 0 to indicated failure.
184- */
185- static int
186- check_exec (const char * dir ,const char * cmdName )
187- {
188- char path [MAXPGPATH ];
189- const char * errMsg ;
190-
191- snprintf (path ,sizeof (path ),"%s/%s" ,dir ,cmdName );
192-
193- if ((errMsg = validate_exec (path ))== NULL )
194- return 1 ;/* 1 -> first alternative OK */
195- else
196- pg_log (PG_FATAL ,"check for %s failed - %s\n" ,cmdName ,errMsg );
197-
198- return 0 ;/* 0 -> neither alternative is acceptable */
199- }
200-
201-
202175/*
203176 * validate_exec()
204177 *
205178 * validate "path" as an executable file
206- * returns 0 if the file is found and no error is encountered.
207- * -1 if the regular file "path" does not exist or cannot be executed.
208- * -2 if the file is otherwise valid but cannot be read.
209179 */
210- static const char *
211- validate_exec (const char * path )
180+ static void
181+ validate_exec (const char * dir , const char * cmdName )
212182{
183+ char path [MAXPGPATH ];
213184struct stat buf ;
214185
186+ snprintf (path ,sizeof (path ),"%s/%s" ,dir ,cmdName );
187+
215188#ifdef WIN32
216189/* Win32 requires a .exe suffix for stat() */
217190char path_exe [MAXPGPATH + sizeof (EXE_EXT )- 1 ];
@@ -229,26 +202,30 @@ validate_exec(const char *path)
229202 * Ensure that the file exists and is a regular file.
230203 */
231204if (stat (path ,& buf )< 0 )
232- return getErrorText (errno );
205+ pg_log (PG_FATAL ,"check for %s failed - %s\n" ,
206+ cmdName ,getErrorText (errno ));
233207
234208if (!S_ISREG (buf .st_mode ))
235- return "not an executable file" ;
209+ pg_log (PG_FATAL ,"check for %s failed - not an executable file\n" ,
210+ cmdName );
236211
237212/*
238213 * Ensure that the file is both executable and readable (required for
239214 * dynamic loading).
240215 */
241216#ifndef WIN32
242217if (access (path ,R_OK )!= 0 )
243- return "can't read file (permission denied)" ;
244- if (access (path ,X_OK )!= 0 )
245- return "can't execute (permission denied)" ;
246- return NULL ;
247218#else
248219if ((buf .st_mode & S_IRUSR )== 0 )
249- return "can't read file (permission denied)" ;
220+ #endif
221+ pg_log (PG_FATAL ,"check for %s failed - cannot read file (permission denied)\n" ,
222+ cmdName );
223+
224+ #ifndef WIN32
225+ if (access (path ,X_OK )!= 0 )
226+ #else
250227if ((buf .st_mode & S_IXUSR )== 0 )
251- return "can't execute (permission denied)" ;
252- return NULL ;
253228#endif
229+ pg_log (PG_FATAL ,"check for %s failed - cannot execute (permission denied)\n" ,
230+ cmdName );
254231}