Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
9d220fc1
Commit
9d220fc1
authored
14 years ago
by
Bruce Momjian
Browse files
Options
Downloads
Patches
Plain Diff
Simplify pg_upgrade checking of executable permissions.
parent
0c5933d0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
contrib/pg_upgrade/exec.c
+25
-48
25 additions, 48 deletions
contrib/pg_upgrade/exec.c
with
25 additions
and
48 deletions
contrib/pg_upgrade/exec.c
+
25
−
48
View file @
9d220fc1
...
...
@@ -15,8 +15,7 @@
static
void
check_data_dir
(
const
char
*
pg_data
);
static
void
check_bin_dir
(
ClusterInfo
*
cluster
);
static
int
check_exec
(
const
char
*
dir
,
const
char
*
cmdName
);
static
const
char
*
validate_exec
(
const
char
*
path
);
static
void
validate_exec
(
const
char
*
dir
,
const
char
*
cmdName
);
/*
...
...
@@ -160,58 +159,32 @@ check_data_dir(const char *pg_data)
static
void
check_bin_dir
(
ClusterInfo
*
cluster
)
{
check
_exec
(
cluster
->
bindir
,
"postgres"
);
check
_exec
(
cluster
->
bindir
,
"pg_ctl"
);
check
_exec
(
cluster
->
bindir
,
"pg_resetxlog"
);
validate
_exec
(
cluster
->
bindir
,
"postgres"
);
validate
_exec
(
cluster
->
bindir
,
"pg_ctl"
);
validate
_exec
(
cluster
->
bindir
,
"pg_resetxlog"
);
if
(
cluster
==
&
new_cluster
)
{
/* these are only needed in the new cluster */
check
_exec
(
cluster
->
bindir
,
"pg_config"
);
check
_exec
(
cluster
->
bindir
,
"psql"
);
check
_exec
(
cluster
->
bindir
,
"pg_dumpall"
);
validate
_exec
(
cluster
->
bindir
,
"pg_config"
);
validate
_exec
(
cluster
->
bindir
,
"psql"
);
validate
_exec
(
cluster
->
bindir
,
"pg_dumpall"
);
}
}
/*
* check_exec()
*
* Checks whether either of the two command names (cmdName and alternative)
* appears to be an executable (in the given directory). If dir/cmdName is
* an executable, this function returns 1. If dir/alternative is an
* executable, this function returns 2. If neither of the given names is
* a valid executable, this function returns 0 to indicated failure.
*/
static
int
check_exec
(
const
char
*
dir
,
const
char
*
cmdName
)
{
char
path
[
MAXPGPATH
];
const
char
*
errMsg
;
snprintf
(
path
,
sizeof
(
path
),
"%s/%s"
,
dir
,
cmdName
);
if
((
errMsg
=
validate_exec
(
path
))
==
NULL
)
return
1
;
/* 1 -> first alternative OK */
else
pg_log
(
PG_FATAL
,
"check for %s failed - %s
\n
"
,
cmdName
,
errMsg
);
return
0
;
/* 0 -> neither alternative is acceptable */
}
/*
* validate_exec()
*
* validate "path" as an executable file
* returns 0 if the file is found and no error is encountered.
* -1 if the regular file "path" does not exist or cannot be executed.
* -2 if the file is otherwise valid but cannot be read.
*/
static
const
char
*
validate_exec
(
const
char
*
path
)
static
void
validate_exec
(
const
char
*
dir
,
const
char
*
cmdName
)
{
char
path
[
MAXPGPATH
];
struct
stat
buf
;
snprintf
(
path
,
sizeof
(
path
),
"%s/%s"
,
dir
,
cmdName
);
#ifdef WIN32
/* Win32 requires a .exe suffix for stat() */
char
path_exe
[
MAXPGPATH
+
sizeof
(
EXE_EXT
)
-
1
];
...
...
@@ -229,10 +202,12 @@ validate_exec(const char *path)
* Ensure that the file exists and is a regular file.
*/
if
(
stat
(
path
,
&
buf
)
<
0
)
return
getErrorText
(
errno
);
pg_log
(
PG_FATAL
,
"check for %s failed - %s
\n
"
,
cmdName
,
getErrorText
(
errno
));
if
(
!
S_ISREG
(
buf
.
st_mode
))
return
"not an executable file"
;
pg_log
(
PG_FATAL
,
"check for %s failed - not an executable file
\n
"
,
cmdName
);
/*
* Ensure that the file is both executable and readable (required for
...
...
@@ -240,15 +215,17 @@ validate_exec(const char *path)
*/
#ifndef WIN32
if
(
access
(
path
,
R_OK
)
!=
0
)
return
"can't read file (permission denied)"
;
if
(
access
(
path
,
X_OK
)
!=
0
)
return
"can't execute (permission denied)"
;
return
NULL
;
#else
if
((
buf
.
st_mode
&
S_IRUSR
)
==
0
)
return
"can't read file (permission denied)"
;
#endif
pg_log
(
PG_FATAL
,
"check for %s failed - cannot read file (permission denied)
\n
"
,
cmdName
);
#ifndef WIN32
if
(
access
(
path
,
X_OK
)
!=
0
)
#else
if
((
buf
.
st_mode
&
S_IXUSR
)
==
0
)
return
"can't execute (permission denied)"
;
return
NULL
;
#endif
pg_log
(
PG_FATAL
,
"check for %s failed - cannot execute (permission denied)
\n
"
,
cmdName
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment