15
15
16
16
static void check_data_dir (const char * pg_data );
17
17
static 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 );
20
19
21
20
22
21
/*
@@ -160,58 +159,32 @@ check_data_dir(const char *pg_data)
160
159
static void
161
160
check_bin_dir (ClusterInfo * cluster )
162
161
{
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" );
166
165
if (cluster == & new_cluster )
167
166
{
168
167
/* 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" );
172
171
}
173
172
}
174
173
175
174
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
-
202
175
/*
203
176
* validate_exec()
204
177
*
205
178
* 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.
209
179
*/
210
- static const char *
211
- validate_exec (const char * path )
180
+ static void
181
+ validate_exec (const char * dir , const char * cmdName )
212
182
{
183
+ char path [MAXPGPATH ];
213
184
struct stat buf ;
214
185
186
+ snprintf (path , sizeof (path ), "%s/%s" , dir , cmdName );
187
+
215
188
#ifdef WIN32
216
189
/* Win32 requires a .exe suffix for stat() */
217
190
char path_exe [MAXPGPATH + sizeof (EXE_EXT ) - 1 ];
@@ -229,26 +202,30 @@ validate_exec(const char *path)
229
202
* Ensure that the file exists and is a regular file.
230
203
*/
231
204
if (stat (path , & buf ) < 0 )
232
- return getErrorText (errno );
205
+ pg_log (PG_FATAL , "check for %s failed - %s\n" ,
206
+ cmdName , getErrorText (errno ));
233
207
234
208
if (!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 );
236
211
237
212
/*
238
213
* Ensure that the file is both executable and readable (required for
239
214
* dynamic loading).
240
215
*/
241
216
#ifndef WIN32
242
217
if (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 ;
247
218
#else
248
219
if ((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
250
227
if ((buf .st_mode & S_IXUSR ) == 0 )
251
- return "can't execute (permission denied)" ;
252
- return NULL ;
253
228
#endif
229
+ pg_log (PG_FATAL , "check for %s failed - cannot execute (permission denied)\n" ,
230
+ cmdName );
254
231
}
0 commit comments