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

Commitdad8e41

Browse files
committed
Fix handling of SIGCHLD, per recent pghackers discussion: on some
platforms system(2) gets confused unless the signal handler is set toSIG_DFL, not SIG_IGN. pgstats.c now uses pqsignal() as it should,not signal(). Also, arrange for the stats collector process to showa reasonable ID in 'ps', rather than looking like a postmaster.
1 parent2b769c8 commitdad8e41

File tree

6 files changed

+92
-73
lines changed

6 files changed

+92
-73
lines changed

‎src/backend/bootstrap/bootstrap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.112 2001/07/16 05:06:57 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.113 2001/08/04 00:14:43 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -310,13 +310,15 @@ BootstrapMain(int argc, char *argv[])
310310
pqsignal(SIGINT,SIG_IGN);/* ignore query-cancel */
311311
pqsignal(SIGTERM,die);
312312
pqsignal(SIGQUIT,quickdie);
313+
pqsignal(SIGALRM,SIG_IGN);
314+
pqsignal(SIGPIPE,SIG_IGN);
313315
pqsignal(SIGUSR1,SIG_IGN);
314316
pqsignal(SIGUSR2,SIG_IGN);
315317

316318
/*
317319
* Reset some signals that are accepted by postmaster but not here
318320
*/
319-
pqsignal(SIGCHLD,SIG_IGN);
321+
pqsignal(SIGCHLD,SIG_DFL);
320322
pqsignal(SIGTTIN,SIG_DFL);
321323
pqsignal(SIGTTOU,SIG_DFL);
322324
pqsignal(SIGCONT,SIG_DFL);

‎src/backend/commands/dbcommands.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.76 2001/07/02 20:50:46 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.77 2001/08/04 00:14:43 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -58,7 +58,6 @@ createdb(const char *dbname, const char *dbpath,
5858
char*target_dir;
5959
charsrc_loc[MAXPGPATH];
6060
charbuf[2*MAXPGPATH+100];
61-
intret;
6261
booluse_super,
6362
use_createdb;
6463
Oidsrc_dboid;
@@ -195,9 +194,7 @@ createdb(const char *dbname, const char *dbpath,
195194
/* Copy the template database to the new location */
196195
snprintf(buf,sizeof(buf),"cp -r '%s' '%s'",src_loc,target_dir);
197196

198-
ret=system(buf);
199-
/* Some versions of SunOS seem to return ECHILD after a system() call */
200-
if (ret!=0&&errno!=ECHILD)
197+
if (system(buf)!=0)
201198
{
202199
if (remove_dbdirs(nominal_loc,alt_loc))
203200
elog(ERROR,"CREATE DATABASE: could not initialize database directory");
@@ -557,7 +554,7 @@ remove_dbdirs(const char *nominal_loc, const char *alt_loc)
557554

558555
snprintf(buf,sizeof(buf),"rm -rf '%s'",target_dir);
559556

560-
if (system(buf)!=0&&errno!=ECHILD)
557+
if (system(buf)!=0)
561558
{
562559
elog(NOTICE,"database directory '%s' could not be removed",
563560
target_dir);

‎src/backend/postmaster/pgstat.c

Lines changed: 73 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,41 @@
1616
*
1717
*Copyright (c) 2001, PostgreSQL Global Development Group
1818
*
19-
*$Id:pgstat.c,v 1.4 2001/07/05 15:19:40 wieck Exp $
19+
*$Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.5 2001/08/04 00:14:43 tgl Exp $
2020
* ----------
2121
*/
2222
#include"postgres.h"
2323

2424
#include<unistd.h>
2525
#include<fcntl.h>
26-
2726
#include<sys/param.h>
2827
#include<sys/time.h>
2928
#include<sys/types.h>
3029
#include<sys/socket.h>
3130
#include<netinet/in.h>
3231
#include<arpa/inet.h>
33-
3432
#include<errno.h>
3533
#include<signal.h>
3634

35+
#include"access/xact.h"
36+
#include"access/heapam.h"
37+
#include"catalog/catname.h"
38+
#include"catalog/pg_shadow.h"
39+
#include"catalog/pg_database.h"
40+
#include"libpq/pqsignal.h"
3741
#include"miscadmin.h"
3842
#include"utils/memutils.h"
3943
#include"storage/backendid.h"
4044
#include"utils/rel.h"
4145
#include"utils/hsearch.h"
46+
#include"utils/ps_status.h"
4247
#include"utils/syscache.h"
43-
#include"access/xact.h"
44-
#include"access/heapam.h"
45-
#include"catalog/catname.h"
46-
#include"catalog/pg_shadow.h"
47-
#include"catalog/pg_database.h"
4848

4949
#include"pgstat.h"
5050

5151

5252
/* ----------
53-
*Global data
53+
*GUC parameters
5454
* ----------
5555
*/
5656
boolpgstat_collect_startcollector= true;
@@ -95,8 +95,8 @@ static charpgStat_fname[MAXPGPATH];
9595
* Local function forward declarations
9696
* ----------
9797
*/
98-
staticvoidpgstat_main(void);
99-
staticvoidpgstat_recvbuffer(void);
98+
staticvoidpgstat_main(intreal_argc,char*real_argv[]);
99+
staticvoidpgstat_recvbuffer(intreal_argc,char*real_argv[]);
100100

101101
staticintpgstat_add_backend(PgStat_MsgHdr*msg);
102102
staticvoidpgstat_sub_backend(intprocpid);
@@ -227,11 +227,14 @@ pgstat_init(void)
227227
* pgstat_start() -
228228
*
229229
*Called from postmaster at startup or after an existing collector
230-
*died. Fire up a fresh statistics collector.
230+
*died. Fire up a fresh statistics collector.
231+
*
232+
*The process' original argc and argv are passed, because they are
233+
*needed by init_ps_display() on some platforms.
231234
* ----------
232235
*/
233236
int
234-
pgstat_start(void)
237+
pgstat_start(intreal_argc,char*real_argv[])
235238
{
236239
/*
237240
* Do nothing if no collector needed
@@ -267,7 +270,8 @@ pgstat_start(void)
267270
return0;
268271
}
269272

270-
pgstat_main();
273+
pgstat_main(real_argc,real_argv);
274+
271275
exit(0);
272276
}
273277

@@ -989,15 +993,6 @@ pgstat_fetch_stat_numbackends(void)
989993

990994

991995

992-
993-
994-
995-
996-
997-
998-
999-
1000-
1001996
/* ------------------------------------------------------------
1002997
* Local support functions follow
1003998
* ------------------------------------------------------------
@@ -1053,7 +1048,7 @@ pgstat_send(void *msg, int len)
10531048
* ----------
10541049
*/
10551050
staticvoid
1056-
pgstat_main(void)
1051+
pgstat_main(intreal_argc,char*real_argv[])
10571052
{
10581053
PgStat_Msgmsg;
10591054
fd_setrfds;
@@ -1076,27 +1071,22 @@ pgstat_main(void)
10761071
/*
10771072
* Ignore all signals usually bound to some action in the postmaster
10781073
*/
1079-
signal(SIGHUP,SIG_IGN);
1080-
signal(SIGINT,SIG_IGN);
1081-
signal(SIGQUIT,SIG_IGN);
1082-
signal(SIGTERM,SIG_IGN);
1083-
signal(SIGALRM,SIG_IGN);
1084-
signal(SIGPIPE,SIG_IGN);
1085-
signal(SIGUSR1,SIG_IGN);
1086-
signal(SIGUSR2,SIG_IGN);
1087-
signal(SIGCHLD,SIG_IGN);
1088-
signal(SIGTTIN,SIG_IGN);
1089-
signal(SIGTTOU,SIG_IGN);
1090-
signal(SIGWINCH,SIG_IGN);
1091-
1092-
/*
1093-
* Write the initial status file right at startup
1094-
*/
1095-
gettimeofday(&next_statwrite,NULL);
1096-
need_statwrite= TRUE;
1097-
1098-
/*
1099-
* Now we start the buffer process to read from the socket, so
1074+
pqsignal(SIGHUP,SIG_IGN);
1075+
pqsignal(SIGINT,SIG_IGN);
1076+
pqsignal(SIGTERM,SIG_IGN);
1077+
pqsignal(SIGQUIT,SIG_IGN);
1078+
pqsignal(SIGALRM,SIG_IGN);
1079+
pqsignal(SIGPIPE,SIG_IGN);
1080+
pqsignal(SIGUSR1,SIG_IGN);
1081+
pqsignal(SIGUSR2,SIG_IGN);
1082+
pqsignal(SIGCHLD,SIG_DFL);
1083+
pqsignal(SIGTTIN,SIG_DFL);
1084+
pqsignal(SIGTTOU,SIG_DFL);
1085+
pqsignal(SIGCONT,SIG_DFL);
1086+
pqsignal(SIGWINCH,SIG_DFL);
1087+
1088+
/*
1089+
* Start a buffering subprocess to read from the socket, so
11001090
* we have a little more time to process incoming messages.
11011091
*/
11021092
if (pipe(pgStatPipe)<0)
@@ -1107,19 +1097,38 @@ pgstat_main(void)
11071097

11081098
switch(fork())
11091099
{
1110-
case-1:perror("PGSTAT: fork(2)");
1111-
exit(1);
1100+
case-1:
1101+
perror("PGSTAT: fork(2)");
1102+
exit(1);
11121103

1113-
case0:close(pgStatPipe[0]);
1114-
signal(SIGPIPE,SIG_DFL);
1115-
pgstat_recvbuffer();
1116-
exit(2);
1104+
case0:
1105+
close(pgStatPipe[0]);
1106+
/* child process should die if can't pipe to parent collector */
1107+
pqsignal(SIGPIPE,SIG_DFL);
1108+
pgstat_recvbuffer(real_argc,real_argv);
1109+
exit(2);
11171110

1118-
default:close(pgStatPipe[1]);
1119-
close(pgStatSock);
1120-
break;
1111+
default:
1112+
close(pgStatPipe[1]);
1113+
close(pgStatSock);
1114+
break;
11211115
}
11221116

1117+
/*
1118+
* Identify myself via ps
1119+
*
1120+
* WARNING: On some platforms the environment will be moved around to
1121+
* make room for the ps display string.
1122+
*/
1123+
init_ps_display(real_argc,real_argv,"stats collector process","","");
1124+
set_ps_display("");
1125+
1126+
/*
1127+
* Arrange to write the initial status file right away
1128+
*/
1129+
gettimeofday(&next_statwrite,NULL);
1130+
need_statwrite= TRUE;
1131+
11231132
/*
11241133
* Read in an existing statistics stats file or initialize the
11251134
* stats to zero.
@@ -1358,7 +1367,7 @@ pgstat_main(void)
13581367
* ----------
13591368
*/
13601369
staticvoid
1361-
pgstat_recvbuffer(void)
1370+
pgstat_recvbuffer(intreal_argc,char*real_argv[])
13621371
{
13631372
fd_setrfds;
13641373
fd_setwfds;
@@ -1373,6 +1382,15 @@ pgstat_recvbuffer(void)
13731382
intfromlen;
13741383
intoverflow=0;
13751384

1385+
/*
1386+
* Identify myself via ps
1387+
*
1388+
* WARNING: On some platforms the environment will be moved around to
1389+
* make room for the ps display string.
1390+
*/
1391+
init_ps_display(real_argc,real_argv,"stats buffer process","","");
1392+
set_ps_display("");
1393+
13761394
/*
13771395
* Allocate the message buffer
13781396
*/

‎src/backend/postmaster/postmaster.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.233 2001/07/31 22:55:45 tgl Exp $
40+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.234 2001/08/04 00:14:43 tgl Exp $
4141
*
4242
* NOTES
4343
*
@@ -696,7 +696,7 @@ PostmasterMain(int argc, char *argv[])
696696
*/
697697
if (pgstat_init()<0)
698698
ExitPostmaster(1);
699-
if (pgstat_start()<0)
699+
if (pgstat_start(real_argc,real_argv)<0)
700700
ExitPostmaster(1);
701701

702702
/*
@@ -1488,7 +1488,7 @@ reaper(SIGNAL_ARGS)
14881488
{
14891489
fprintf(stderr,"%s: Performance collector exited with status %d\n",
14901490
progname,exitstatus);
1491-
pgstat_start();
1491+
pgstat_start(real_argc,real_argv);
14921492
continue;
14931493
}
14941494

‎src/backend/tcop/postgres.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.229 2001/07/31 22:55:45 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.230 2001/08/04 00:14:43 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -1102,7 +1102,9 @@ usage(char *progname)
11021102
* ----------------------------------------------------------------
11031103
*/
11041104
int
1105-
PostgresMain(intargc,char*argv[],intreal_argc,char*real_argv[],constchar*username)
1105+
PostgresMain(intargc,char*argv[],
1106+
intreal_argc,char*real_argv[],
1107+
constchar*username)
11061108
{
11071109
intflag;
11081110

@@ -1535,15 +1537,15 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
15351537
*/
15361538
pqsignal(SIGPIPE,SIG_IGN);
15371539
pqsignal(SIGUSR1,SIG_IGN);/* this signal available for use */
1540+
15381541
pqsignal(SIGUSR2,Async_NotifyHandler);/* flush also sinval cache */
15391542
pqsignal(SIGFPE,FloatExceptionHandler);
1540-
pqsignal(SIGCHLD,SIG_IGN);/* ignored (may get this in system()
1541-
* calls) */
15421543

15431544
/*
15441545
* Reset some signals that are accepted by postmaster but not by
15451546
* backend
15461547
*/
1548+
pqsignal(SIGCHLD,SIG_DFL);/* system() requires this on some platforms */
15471549
pqsignal(SIGTTIN,SIG_DFL);
15481550
pqsignal(SIGTTOU,SIG_DFL);
15491551
pqsignal(SIGCONT,SIG_DFL);
@@ -1711,7 +1713,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
17111713
if (!IsUnderPostmaster)
17121714
{
17131715
puts("\nPOSTGRES backend interactive interface ");
1714-
puts("$Revision: 1.229 $ $Date: 2001/07/31 22:55:45 $\n");
1716+
puts("$Revision: 1.230 $ $Date: 2001/08/04 00:14:43 $\n");
17151717
}
17161718

17171719
/*

‎src/include/pgstat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*Copyright (c) 2001, PostgreSQL Global Development Group
77
*
8-
* $Id: pgstat.h,v 1.4 2001/07/05 15:19:40 wieck Exp $
8+
* $Id: pgstat.h,v 1.5 2001/08/04 00:14:43 tgl Exp $
99
* ----------
1010
*/
1111
#ifndefPGSTAT_H
@@ -336,7 +336,7 @@ extern boolpgstat_collect_blocklevel;
336336
* ----------
337337
*/
338338
externintpgstat_init(void);
339-
externintpgstat_start(void);
339+
externintpgstat_start(intreal_argc,char*real_argv[]);
340340
externintpgstat_ispgstat(intpid);
341341
externvoidpgstat_beterm(intpid);
342342

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp