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

Commitebe2166

Browse files
author
Michael Paquier
committed
Refactor code in pgsql_src for server monitoring
Most of those things are taken from pg_ctl.c, but were somewhat notreally in a place corresponding to their role.
1 parent5f3823c commitebe2166

File tree

3 files changed

+35
-46
lines changed

3 files changed

+35
-46
lines changed

‎Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ SRCS = \
1010
pg_rman.c\
1111
restore.c\
1212
show.c\
13+
status.c\
1314
util.c\
1415
validate.c\
1516
xlog.c\
16-
pgsql_src/pg_ctl.c\
1717
pgut/pgut.c\
1818
pgut/pgut-port.c
1919
OBJS =$(SRCS:.c=.o)

‎pgsql_src/COPYRIGHT.pgsql_src

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎pgsql_src/pg_ctl.crenamed to‎status.c

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*-------------------------------------------------------------------------
22
*
3-
*pg_ctl --- start/stops/restarts the PostgreSQL server
3+
*status.c
44
*
55
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
66
*
7-
*$PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.111 2009/06/11 14:49:07 momjian Exp $
7+
*Monitor status of a PostgreSQL server.
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -24,36 +24,51 @@ typedef long pgpid_t;
2424
staticpgpid_tget_pgpid(void);
2525
staticboolpostmaster_is_alive(pid_tpid);
2626

27-
staticcharpid_file[MAXPGPATH];
28-
29-
27+
/*
28+
* get_pgpid
29+
*
30+
* Get PID of postmaster, by scanning postmaster.pid.
31+
*/
3032
staticpgpid_t
3133
get_pgpid(void)
3234
{
3335
FILE*pidf;
3436
longpid;
37+
charpid_file[MAXPGPATH];
3538

3639
snprintf(pid_file,lengthof(pid_file),"%s/postmaster.pid",pgdata);
40+
3741
pidf=fopen(pid_file,"r");
3842
if (pidf==NULL)
3943
{
4044
/* No pid file, not an error on startup */
4145
if (errno==ENOENT)
4246
return0;
4347
else
48+
{
4449
elog(ERROR_SYSTEM,_("could not open PID file \"%s\": %s\n"),
45-
pid_file,strerror(errno));
50+
pid_file,strerror(errno));
51+
}
52+
if (fscanf(pidf,"%ld",&pid)!=1)
53+
{
54+
/* Is the file empty? */
55+
if (ftell(pidf)==0&&feof(pidf))
56+
elog(ERROR_SYSTEM,_("the PID file \"%s\" is empty\n"),
57+
pid_file);
58+
else
59+
elog(ERROR_SYSTEM,_("invalid data in PID file \"%s\"\n"),
60+
pid_file);
61+
}
4662
}
47-
if (fscanf(pidf,"%ld",&pid)!=1)
48-
elog(ERROR_PID_BROKEN,_("invalid data in PID file \"%s\"\n"),pid_file);
4963
fclose(pidf);
5064
return (pgpid_t)pid;
5165
}
5266

5367
/*
54-
*utility routines
68+
* postmaster_is_alive
69+
*
70+
* Check whether postmaster is alive or not.
5571
*/
56-
5772
staticbool
5873
postmaster_is_alive(pid_tpid)
5974
{
@@ -79,27 +94,25 @@ postmaster_is_alive(pid_t pid)
7994
}
8095

8196
/*
82-
* original is do_status() in src/bin/pg_ctl/pg_ctl.c
83-
* changes are:
84-
* renamed from do_status() from do_status().
85-
* return true if PG server is running.
86-
* don't print any message.
87-
* don't print postopts file.
88-
* log with elog() in pgut library.
97+
* is_pg_running
98+
*
99+
*
89100
*/
90101
bool
91102
is_pg_running(void)
92103
{
93104
pgpid_tpid;
94105

95106
pid=get_pgpid();
96-
if (pid==0)/* 0 means no pid file */
107+
108+
/* 0 means no pid file */
109+
if (pid==0)
97110
return false;
98111

99-
if (pid<0)/* standalone backend */
112+
/* Case of a standalone backend */
113+
if (pid<0)
100114
pid=-pid;
101115

102-
116+
/* Check if postmaster is alive */
103117
returnpostmaster_is_alive((pid_t)pid);
104118
}
105-

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp