Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
2f8c7c86
Commit
2f8c7c86
authored
Apr 20, 2005
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make pg_ctl status do a kill() test to verify that the PID found in
postmaster.pid still represents a live postmaster.
parent
1c155c8d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
23 deletions
+61
-23
src/bin/pg_ctl/pg_ctl.c
src/bin/pg_ctl/pg_ctl.c
+61
-23
No files found.
src/bin/pg_ctl/pg_ctl.c
View file @
2f8c7c86
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
*
*
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
*
*
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.5
5 2005/03/11 17:20:33 momjian
Exp $
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.5
6 2005/04/20 23:10:16 tgl
Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -236,7 +236,7 @@ static pgpid_t
...
@@ -236,7 +236,7 @@ static pgpid_t
get_pgpid
(
void
)
get_pgpid
(
void
)
{
{
FILE
*
pidf
;
FILE
*
pidf
;
pgpid_t
pid
;
long
pid
;
pidf
=
fopen
(
pid_file
,
"r"
);
pidf
=
fopen
(
pid_file
,
"r"
);
if
(
pidf
==
NULL
)
if
(
pidf
==
NULL
)
...
@@ -246,14 +246,19 @@ get_pgpid(void)
...
@@ -246,14 +246,19 @@ get_pgpid(void)
return
0
;
return
0
;
else
else
{
{
write_stderr
(
_
(
"%s: could not open PID file
\"
%s
\"
: %s"
),
write_stderr
(
_
(
"%s: could not open PID file
\"
%s
\"
: %s
\n
"
),
progname
,
pid_file
,
strerror
(
errno
));
progname
,
pid_file
,
strerror
(
errno
));
exit
(
1
);
exit
(
1
);
}
}
}
}
fscanf
(
pidf
,
"%ld"
,
&
pid
);
if
(
fscanf
(
pidf
,
"%ld"
,
&
pid
)
!=
1
)
{
write_stderr
(
_
(
"%s: invalid data in PID file
\"
%s
\"\n
"
),
progname
,
pid_file
);
exit
(
1
);
}
fclose
(
pidf
);
fclose
(
pidf
);
return
pid
;
return
(
pgpid_t
)
pid
;
}
}
...
@@ -766,34 +771,67 @@ do_reload(void)
...
@@ -766,34 +771,67 @@ do_reload(void)
* utility routines
* utility routines
*/
*/
static
bool
postmaster_is_alive
(
pid_t
pid
)
{
/*
* Test to see if the process is still there. Note that we do not
* consider an EPERM failure to mean that the process is still there;
* EPERM must mean that the given PID belongs to some other userid,
* and considering the permissions on $PGDATA, that means it's not
* the postmaster we are after.
*
* Don't believe that our own PID or parent shell's PID is the postmaster,
* either. (Windows hasn't got getppid(), though.)
*/
if
(
pid
==
getpid
())
return
false
;
#ifndef WIN32
if
(
pid
==
getppid
())
return
false
;
#endif
if
(
kill
(
pid
,
0
)
==
0
)
return
true
;
return
false
;
}
static
void
static
void
do_status
(
void
)
do_status
(
void
)
{
{
pgpid_t
pid
;
pgpid_t
pid
;
pid
=
get_pgpid
();
pid
=
get_pgpid
();
if
(
pid
==
0
)
/* no pid file */
if
(
pid
!=
0
)
/* 0 means no pid file */
{
printf
(
_
(
"%s: neither postmaster nor postgres running
\n
"
),
progname
);
exit
(
1
);
}
else
if
(
pid
<
0
)
/* standalone backend */
{
pid
=
-
pid
;
printf
(
_
(
"%s: a standalone backend
\"
postgres
\"
is running (PID: %ld)
\n
"
),
progname
,
pid
);
}
else
/* postmaster */
{
{
char
**
optlines
;
if
(
pid
<
0
)
/* standalone backend */
{
pid
=
-
pid
;
if
(
postmaster_is_alive
((
pid_t
)
pid
))
{
printf
(
_
(
"%s: a standalone backend
\"
postgres
\"
is running (PID: %ld)
\n
"
),
progname
,
pid
);
return
;
}
}
else
/* postmaster */
{
if
(
postmaster_is_alive
((
pid_t
)
pid
))
{
char
**
optlines
;
printf
(
_
(
"%s: postmaster is running (PID: %ld)
\n
"
),
progname
,
pid
);
printf
(
_
(
"%s: postmaster is running (PID: %ld)
\n
"
),
progname
,
pid
);
optlines
=
readfile
(
postopts_file
);
optlines
=
readfile
(
postopts_file
);
if
(
optlines
!=
NULL
)
if
(
optlines
!=
NULL
)
for
(;
*
optlines
!=
NULL
;
optlines
++
)
for
(;
*
optlines
!=
NULL
;
optlines
++
)
fputs
(
*
optlines
,
stdout
);
fputs
(
*
optlines
,
stdout
);
return
;
}
}
}
}
printf
(
_
(
"%s: neither postmaster nor postgres running
\n
"
),
progname
);
exit
(
1
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment