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

Commit7e26a82

Browse files
Jan WieckJan Wieck
Jan Wieck
authored and
Jan Wieck
committed
Enable SIGTERM and SIGQUIT during client authentication so
the postmaster can kill the forked off processes when shutdownis requested.Jan
1 parentd9044b5 commit7e26a82

File tree

5 files changed

+54
-9
lines changed

5 files changed

+54
-9
lines changed

‎src/backend/libpq/pqsignal.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/libpq/pqsignal.c,v 1.21 2001/08/24 14:07:49 petere Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/libpq/pqsignal.c,v 1.22 2001/09/07 16:12:48 wieck Exp $
1313
*
1414
* NOTES
1515
*This shouldn't be in libpq, but the monitor and some other
@@ -61,6 +61,7 @@ pqinitmask(void)
6161
#ifdefHAVE_SIGPROCMASK
6262
sigemptyset(&UnBlockSig);
6363
sigfillset(&BlockSig);
64+
sigfillset(&AuthBlockSig);
6465

6566
/*
6667
* Unmark those signals that should never be blocked. Some of these
@@ -69,27 +70,41 @@ pqinitmask(void)
6970
*/
7071
#ifdefSIGTRAP
7172
sigdelset(&BlockSig,SIGTRAP);
73+
sigdelset(&AuthBlockSig,SIGTRAP);
7274
#endif
7375
#ifdefSIGABRT
7476
sigdelset(&BlockSig,SIGABRT);
77+
sigdelset(&AuthBlockSig,SIGABRT);
7578
#endif
7679
#ifdefSIGILL
7780
sigdelset(&BlockSig,SIGILL);
81+
sigdelset(&AuthBlockSig,SIGILL);
7882
#endif
7983
#ifdefSIGFPE
8084
sigdelset(&BlockSig,SIGFPE);
85+
sigdelset(&AuthBlockSig,SIGFPE);
8186
#endif
8287
#ifdefSIGSEGV
8388
sigdelset(&BlockSig,SIGSEGV);
89+
sigdelset(&AuthBlockSig,SIGSEGV);
8490
#endif
8591
#ifdefSIGBUS
8692
sigdelset(&BlockSig,SIGBUS);
93+
sigdelset(&AuthBlockSig,SIGBUS);
8794
#endif
8895
#ifdefSIGSYS
8996
sigdelset(&BlockSig,SIGSYS);
97+
sigdelset(&AuthBlockSig,SIGSYS);
9098
#endif
9199
#ifdefSIGCONT
92100
sigdelset(&BlockSig,SIGCONT);
101+
sigdelset(&AuthBlockSig,SIGCONT);
102+
#endif
103+
#ifdefSIGTERM
104+
sigdelset(&AuthBlockSig,SIGTERM);
105+
#endif
106+
#ifdefSIGQUIT
107+
sigdelset(&AuthBlockSig,SIGQUIT);
93108
#endif
94109
#else
95110
UnBlockSig=0;
@@ -98,6 +113,10 @@ pqinitmask(void)
98113
sigmask(SIGINT) |sigmask(SIGUSR1) |
99114
sigmask(SIGUSR2) |sigmask(SIGCHLD) |
100115
sigmask(SIGWINCH) |sigmask(SIGFPE);
116+
AuthBlockSig=sigmask(SIGHUP) |sigmask(SIGALRM) |
117+
sigmask(SIGINT) |sigmask(SIGUSR1) |
118+
sigmask(SIGUSR2) |sigmask(SIGCHLD) |
119+
sigmask(SIGWINCH) |sigmask(SIGFPE);
101120
#endif
102121
}
103122

‎src/backend/postmaster/postmaster.c

Lines changed: 17 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.239 2001/09/0700:46:42 tgl Exp $
40+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.240 2001/09/0716:12:48 wieck Exp $
4141
*
4242
* NOTES
4343
*
@@ -112,10 +112,12 @@
112112

113113
#ifdefHAVE_SIGPROCMASK
114114
sigset_tUnBlockSig,
115-
BlockSig;
115+
BlockSig,
116+
AuthBlockSig;
116117
#else
117118
intUnBlockSig,
118-
BlockSig;
119+
BlockSig,
120+
AuthBlockSig;
119121
#endif
120122

121123
/*
@@ -1932,6 +1934,16 @@ DoBackend(Port *port)
19321934

19331935
whereToSendOutput=Remote;/* XXX probably doesn't belong here */
19341936

1937+
/*
1938+
* We arrange for a simple exit(0) if we receive SIGTERM or SIGQUIT
1939+
* during any client authentication related communication. Otherwise
1940+
* the postmaster cannot shutdown the database FAST or IMMED cleanly
1941+
* if a buggy client blocks a backend during authentication.
1942+
*/
1943+
pqsignal(SIGTERM,authdie);
1944+
pqsignal(SIGQUIT,authdie);
1945+
PG_SETMASK(&AuthBlockSig);
1946+
19351947
/*
19361948
* Receive the startup packet (which might turn out to be a cancel
19371949
* request packet); then perform client authentication.
@@ -1943,6 +1955,8 @@ DoBackend(Port *port)
19431955

19441956
ClientAuthentication(MyProcPort);/* might not return, if failure */
19451957

1958+
PG_SETMASK(&BlockSig);
1959+
19461960
/*
19471961
* Don't want backend to be able to see the postmaster random number
19481962
* generator state. We have to clobber the static random_seed *and*

‎src/backend/tcop/postgres.c

Lines changed: 12 additions & 2 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.230 2001/08/04 00:14:43 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.231 2001/09/07 16:12:48 wieck Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -965,6 +965,16 @@ die(SIGNAL_ARGS)
965965
errno=save_errno;
966966
}
967967

968+
/*
969+
* Shutdown signal from postmaster during client authentication.
970+
* Simply exit(0).
971+
*/
972+
void
973+
authdie(SIGNAL_ARGS)
974+
{
975+
exit(0);
976+
}
977+
968978
/*
969979
* Query-cancel signal from postmaster: abort current transaction
970980
* at soonest convenient time
@@ -1713,7 +1723,7 @@ PostgresMain(int argc, char *argv[],
17131723
if (!IsUnderPostmaster)
17141724
{
17151725
puts("\nPOSTGRES backend interactive interface ");
1716-
puts("$Revision: 1.230 $ $Date: 2001/08/04 00:14:43 $\n");
1726+
puts("$Revision: 1.231 $ $Date: 2001/09/07 16:12:48 $\n");
17171727
}
17181728

17191729
/*

‎src/include/libpq/pqsignal.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pqsignal.h,v 1.15 2001/01/24 19:43:25 momjian Exp $
10+
* $Id: pqsignal.h,v 1.16 2001/09/07 16:12:49 wieck Exp $
1111
*
1212
* NOTES
1313
* This shouldn't be in libpq, but the monitor and some other
@@ -22,7 +22,8 @@
2222

2323
#ifdefHAVE_SIGPROCMASK
2424
externsigset_tUnBlockSig,
25-
BlockSig;
25+
BlockSig,
26+
AuthBlockSig;
2627

2728
#definePG_SETMASK(mask)sigprocmask(SIG_SETMASK, mask, NULL)
2829
#else

‎src/include/tcop/tcopprot.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: tcopprot.h,v 1.41 2001/06/08 21:16:48 petere Exp $
10+
* $Id: tcopprot.h,v 1.42 2001/09/0716:12:49 wieck Exp $
1111
*
1212
* OLD COMMENTS
1313
* This file was created so that other c files could get the two
@@ -44,6 +44,7 @@ extern void pg_exec_query_string(char *query_string,
4444

4545
externvoiddie(SIGNAL_ARGS);
4646
externvoidquickdie(SIGNAL_ARGS);
47+
externvoidauthdie(SIGNAL_ARGS);
4748
externintPostgresMain(intargc,char*argv[],
4849
intreal_argc,char*real_argv[],constchar*username);
4950
externvoidResetUsage(void);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp