From 7e26a8241d081ff7ba83f3093726639b9b6d1122 Mon Sep 17 00:00:00 2001 From: Jan Wieck Date: Fri, 7 Sep 2001 16:12:49 +0000 Subject: [PATCH] Enable SIGTERM and SIGQUIT during client authentication so the postmaster can kill the forked off processes when shutdown is requested. Jan --- src/backend/libpq/pqsignal.c | 21 ++++++++++++++++++++- src/backend/postmaster/postmaster.c | 20 +++++++++++++++++--- src/backend/tcop/postgres.c | 14 ++++++++++++-- src/include/libpq/pqsignal.h | 5 +++-- src/include/tcop/tcopprot.h | 3 ++- 5 files changed, 54 insertions(+), 9 deletions(-) diff --git a/src/backend/libpq/pqsignal.c b/src/backend/libpq/pqsignal.c index 9bdcd27b70..028db10408 100644 --- a/src/backend/libpq/pqsignal.c +++ b/src/backend/libpq/pqsignal.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/libpq/pqsignal.c,v 1.21 2001/08/24 14:07:49 petere Exp $ + * $Header: /cvsroot/pgsql/src/backend/libpq/pqsignal.c,v 1.22 2001/09/07 16:12:48 wieck Exp $ * * NOTES * This shouldn't be in libpq, but the monitor and some other @@ -61,6 +61,7 @@ pqinitmask(void) #ifdef HAVE_SIGPROCMASK sigemptyset(&UnBlockSig); sigfillset(&BlockSig); + sigfillset(&AuthBlockSig); /* * Unmark those signals that should never be blocked. Some of these @@ -69,27 +70,41 @@ pqinitmask(void) */ #ifdef SIGTRAP sigdelset(&BlockSig, SIGTRAP); + sigdelset(&AuthBlockSig, SIGTRAP); #endif #ifdef SIGABRT sigdelset(&BlockSig, SIGABRT); + sigdelset(&AuthBlockSig, SIGABRT); #endif #ifdef SIGILL sigdelset(&BlockSig, SIGILL); + sigdelset(&AuthBlockSig, SIGILL); #endif #ifdef SIGFPE sigdelset(&BlockSig, SIGFPE); + sigdelset(&AuthBlockSig, SIGFPE); #endif #ifdef SIGSEGV sigdelset(&BlockSig, SIGSEGV); + sigdelset(&AuthBlockSig, SIGSEGV); #endif #ifdef SIGBUS sigdelset(&BlockSig, SIGBUS); + sigdelset(&AuthBlockSig, SIGBUS); #endif #ifdef SIGSYS sigdelset(&BlockSig, SIGSYS); + sigdelset(&AuthBlockSig, SIGSYS); #endif #ifdef SIGCONT sigdelset(&BlockSig, SIGCONT); + sigdelset(&AuthBlockSig, SIGCONT); +#endif +#ifdef SIGTERM + sigdelset(&AuthBlockSig, SIGTERM); +#endif +#ifdef SIGQUIT + sigdelset(&AuthBlockSig, SIGQUIT); #endif #else UnBlockSig = 0; @@ -98,6 +113,10 @@ pqinitmask(void) sigmask(SIGINT) | sigmask(SIGUSR1) | sigmask(SIGUSR2) | sigmask(SIGCHLD) | sigmask(SIGWINCH) | sigmask(SIGFPE); + AuthBlockSig = sigmask(SIGHUP) | sigmask(SIGALRM) | + sigmask(SIGINT) | sigmask(SIGUSR1) | + sigmask(SIGUSR2) | sigmask(SIGCHLD) | + sigmask(SIGWINCH) | sigmask(SIGFPE); #endif } diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 5cdf81cd8f..0de3ad6b12 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -37,7 +37,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.239 2001/09/07 00:46:42 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.240 2001/09/07 16:12:48 wieck Exp $ * * NOTES * @@ -112,10 +112,12 @@ #ifdef HAVE_SIGPROCMASK sigset_t UnBlockSig, - BlockSig; + BlockSig, + AuthBlockSig; #else int UnBlockSig, - BlockSig; + BlockSig, + AuthBlockSig; #endif /* @@ -1932,6 +1934,16 @@ DoBackend(Port *port) whereToSendOutput = Remote; /* XXX probably doesn't belong here */ + /* + * We arrange for a simple exit(0) if we receive SIGTERM or SIGQUIT + * during any client authentication related communication. Otherwise + * the postmaster cannot shutdown the database FAST or IMMED cleanly + * if a buggy client blocks a backend during authentication. + */ + pqsignal(SIGTERM, authdie); + pqsignal(SIGQUIT, authdie); + PG_SETMASK(&AuthBlockSig); + /* * Receive the startup packet (which might turn out to be a cancel * request packet); then perform client authentication. @@ -1943,6 +1955,8 @@ DoBackend(Port *port) ClientAuthentication(MyProcPort); /* might not return, if failure */ + PG_SETMASK(&BlockSig); + /* * Don't want backend to be able to see the postmaster random number * generator state. We have to clobber the static random_seed *and* diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index ac701704c1..b8c57bb4d7 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.230 2001/08/04 00:14:43 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.231 2001/09/07 16:12:48 wieck Exp $ * * NOTES * this is the "main" module of the postgres backend and @@ -965,6 +965,16 @@ die(SIGNAL_ARGS) errno = save_errno; } +/* + * Shutdown signal from postmaster during client authentication. + * Simply exit(0). + */ +void +authdie(SIGNAL_ARGS) +{ + exit(0); +} + /* * Query-cancel signal from postmaster: abort current transaction * at soonest convenient time @@ -1713,7 +1723,7 @@ PostgresMain(int argc, char *argv[], if (!IsUnderPostmaster) { puts("\nPOSTGRES backend interactive interface "); - puts("$Revision: 1.230 $ $Date: 2001/08/04 00:14:43 $\n"); + puts("$Revision: 1.231 $ $Date: 2001/09/07 16:12:48 $\n"); } /* diff --git a/src/include/libpq/pqsignal.h b/src/include/libpq/pqsignal.h index ec22aa4b99..812377186f 100644 --- a/src/include/libpq/pqsignal.h +++ b/src/include/libpq/pqsignal.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: pqsignal.h,v 1.15 2001/01/24 19:43:25 momjian Exp $ + * $Id: pqsignal.h,v 1.16 2001/09/07 16:12:49 wieck Exp $ * * NOTES * This shouldn't be in libpq, but the monitor and some other @@ -22,7 +22,8 @@ #ifdef HAVE_SIGPROCMASK extern sigset_t UnBlockSig, - BlockSig; + BlockSig, + AuthBlockSig; #define PG_SETMASK(mask) sigprocmask(SIG_SETMASK, mask, NULL) #else diff --git a/src/include/tcop/tcopprot.h b/src/include/tcop/tcopprot.h index d29dddd40a..dccea51fe2 100644 --- a/src/include/tcop/tcopprot.h +++ b/src/include/tcop/tcopprot.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: tcopprot.h,v 1.41 2001/06/08 21:16:48 petere Exp $ + * $Id: tcopprot.h,v 1.42 2001/09/07 16:12:49 wieck Exp $ * * OLD COMMENTS * 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, extern void die(SIGNAL_ARGS); extern void quickdie(SIGNAL_ARGS); +extern void authdie(SIGNAL_ARGS); extern int PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const char *username); extern void ResetUsage(void); -- 2.40.0