@@ -71,7 +71,8 @@ is_server_running(const char *datadir)
7171if ((fd = open (path ,O_RDONLY ,0 ))< 0 )
7272{
7373if (errno != ENOENT )
74- pg_log (PG_FATAL ,"could not open file \"%s\" for reading\n" ,
74+ /* issue a warning but continue so we can throw a clearer error later */
75+ pg_log (PG_WARNING ,"could not open file \"%s\" for reading\n" ,
7576path );
7677
7778return false;
9495verify_directories (void )
9596{
9697
98+ prep_status ("Checking current, bin, and data directories" );
99+
97100if (access ("." ,R_OK |W_OK
98101#ifndef WIN32
99102/*
@@ -107,20 +110,10 @@ verify_directories(void)
107110pg_log (PG_FATAL ,
108111"You must have read and write access in the current directory.\n" );
109112
110- prep_status ("Checking old data directory (%s)" ,old_cluster .pgdata );
111- check_data_dir (old_cluster .pgdata );
112- check_ok ();
113-
114- prep_status ("Checking old bin directory (%s)" ,old_cluster .bindir );
115113check_bin_dir (& old_cluster );
116- check_ok ();
117-
118- prep_status ("Checking new data directory (%s)" ,new_cluster .pgdata );
119- check_data_dir (new_cluster .pgdata );
120- check_ok ();
121-
122- prep_status ("Checking new bin directory (%s)" ,new_cluster .bindir );
114+ check_data_dir (old_cluster .pgdata );
123115check_bin_dir (& new_cluster );
116+ check_data_dir (new_cluster .pgdata );
124117check_ok ();
125118}
126119
@@ -139,25 +132,25 @@ check_data_dir(const char *pg_data)
139132{
140133char subDirName [MAXPGPATH ];
141134int subdirnum ;
142- const char * requiredSubdirs []= {"base" ,"global" ,"pg_clog" ,
135+ /* start check with top-most directory */
136+ const char * requiredSubdirs []= {"" ,"base" ,"global" ,"pg_clog" ,
143137"pg_multixact" ,"pg_subtrans" ,"pg_tblspc" ,"pg_twophase" ,
144- "pg_xlog" };
138+ "pg_xlog" };
145139
146140for (subdirnum = 0 ;
147141subdirnum < sizeof (requiredSubdirs ) /sizeof (requiredSubdirs [0 ]);
148142++ subdirnum )
149143{
150144struct stat statBuf ;
151-
152145snprintf (subDirName ,sizeof (subDirName ),"%s/%s" ,pg_data ,
153146requiredSubdirs [subdirnum ]);
154147
155148if (stat (subDirName ,& statBuf )!= 0 )
156149report_status (PG_FATAL ,"check for %s failed: %s\n" ,
157- requiredSubdirs [ subdirnum ] ,getErrorText (errno ));
150+ subDirName ,getErrorText (errno ));
158151else if (!S_ISDIR (statBuf .st_mode ))
159152report_status (PG_FATAL ,"%s is not a directory\n" ,
160- requiredSubdirs [ subdirnum ] );
153+ subDirName );
161154}
162155}
163156
@@ -173,6 +166,16 @@ check_data_dir(const char *pg_data)
173166static void
174167check_bin_dir (ClusterInfo * cluster )
175168{
169+ struct stat statBuf ;
170+
171+ /* check bindir */
172+ if (stat (cluster -> bindir ,& statBuf )!= 0 )
173+ report_status (PG_FATAL ,"check for %s failed: %s\n" ,
174+ cluster -> bindir ,getErrorText (errno ));
175+ else if (!S_ISDIR (statBuf .st_mode ))
176+ report_status (PG_FATAL ,"%s is not a directory\n" ,
177+ cluster -> bindir );
178+
176179validate_exec (cluster -> bindir ,"postgres" );
177180validate_exec (cluster -> bindir ,"pg_ctl" );
178181validate_exec (cluster -> bindir ,"pg_resetxlog" );
@@ -211,11 +214,10 @@ validate_exec(const char *dir, const char *cmdName)
211214 */
212215if (stat (path ,& buf )< 0 )
213216pg_log (PG_FATAL ,"check for %s failed - %s\n" ,
214- cmdName ,getErrorText (errno ));
215-
216- if (!S_ISREG (buf .st_mode ))
217+ path ,getErrorText (errno ));
218+ else if (!S_ISREG (buf .st_mode ))
217219pg_log (PG_FATAL ,"check for %s failed - not an executable file\n" ,
218- cmdName );
220+ path );
219221
220222/*
221223 * Ensure that the file is both executable and readable (required for
@@ -227,13 +229,13 @@ validate_exec(const char *dir, const char *cmdName)
227229if ((buf .st_mode & S_IRUSR )== 0 )
228230#endif
229231pg_log (PG_FATAL ,"check for %s failed - cannot read file (permission denied)\n" ,
230- cmdName );
232+ path );
231233
232234#ifndef WIN32
233235if (access (path ,X_OK )!= 0 )
234236#else
235237if ((buf .st_mode & S_IXUSR )== 0 )
236238#endif
237239pg_log (PG_FATAL ,"check for %s failed - cannot execute (permission denied)\n" ,
238- cmdName );
240+ path );
239241}