Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9d220fc

Browse files
committed
Simplify pg_upgrade checking of executable permissions.
1 parent0c5933d commit9d220fc

File tree

1 file changed

+25
-48
lines changed

1 file changed

+25
-48
lines changed

‎contrib/pg_upgrade/exec.c

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515

1616
staticvoidcheck_data_dir(constchar*pg_data);
1717
staticvoidcheck_bin_dir(ClusterInfo*cluster);
18-
staticintcheck_exec(constchar*dir,constchar*cmdName);
19-
staticconstchar*validate_exec(constchar*path);
18+
staticvoidvalidate_exec(constchar*dir,constchar*cmdName);
2019

2120

2221
/*
@@ -160,58 +159,32 @@ check_data_dir(const char *pg_data)
160159
staticvoid
161160
check_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");
166165
if (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-
staticint
186-
check_exec(constchar*dir,constchar*cmdName)
187-
{
188-
charpath[MAXPGPATH];
189-
constchar*errMsg;
190-
191-
snprintf(path,sizeof(path),"%s/%s",dir,cmdName);
192-
193-
if ((errMsg=validate_exec(path))==NULL)
194-
return1;/* 1 -> first alternative OK */
195-
else
196-
pg_log(PG_FATAL,"check for %s failed - %s\n",cmdName,errMsg);
197-
198-
return0;/* 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-
staticconstchar*
211-
validate_exec(constchar*path)
180+
staticvoid
181+
validate_exec(constchar*dir,constchar*cmdName)
212182
{
183+
charpath[MAXPGPATH];
213184
structstatbuf;
214185

186+
snprintf(path,sizeof(path),"%s/%s",dir,cmdName);
187+
215188
#ifdefWIN32
216189
/* Win32 requires a .exe suffix for stat() */
217190
charpath_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
*/
231204
if (stat(path,&buf)<0)
232-
returngetErrorText(errno);
205+
pg_log(PG_FATAL,"check for %s failed - %s\n",
206+
cmdName,getErrorText(errno));
233207

234208
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);
236211

237212
/*
238213
* Ensure that the file is both executable and readable (required for
239214
* dynamic loading).
240215
*/
241216
#ifndefWIN32
242217
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-
returnNULL;
247218
#else
248219
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+
#ifndefWIN32
225+
if (access(path,X_OK)!=0)
226+
#else
250227
if ((buf.st_mode&S_IXUSR)==0)
251-
return"can't execute (permission denied)";
252-
returnNULL;
253228
#endif
229+
pg_log(PG_FATAL,"check for %s failed - cannot execute (permission denied)\n",
230+
cmdName);
254231
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp