Enable SIGTERM and SIGQUIT during client authentication so

the postmaster can kill the forked off processes when shutdown
is requested.

Jan
This commit is contained in:
Jan Wieck 2001-09-07 16:12:49 +00:00
parent d9044b5637
commit 7e26a8241d
5 changed files with 54 additions and 9 deletions

View File

@ -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
}

View File

@ -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*

View File

@ -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");
}
/*

View File

@ -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

View File

@ -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);