1996-07-09 06:22:35 +00:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-13 23:22:53 +00:00
|
|
|
* pqsignal.c
|
2013-03-17 12:06:42 -04:00
|
|
|
* Backend signal(2) support (see also src/port/pqsignal.c)
|
1996-07-09 06:22:35 +00:00
|
|
|
*
|
2015-01-06 11:43:47 -05:00
|
|
|
* Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
|
2000-01-26 05:58:53 +00:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 06:22:35 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/backend/libpq/pqsignal.c
|
1996-07-09 06:22:35 +00:00
|
|
|
*
|
2013-03-17 12:06:42 -04:00
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
2004-01-27 00:45:26 +00:00
|
|
|
|
1999-07-16 05:00:38 +00:00
|
|
|
#include "postgres.h"
|
|
|
|
|
1999-07-15 23:04:24 +00:00
|
|
|
#include "libpq/pqsignal.h"
|
1996-07-09 06:22:35 +00:00
|
|
|
|
2000-06-28 03:33:33 +00:00
|
|
|
|
2004-05-29 22:48:23 +00:00
|
|
|
#ifdef HAVE_SIGPROCMASK
|
|
|
|
sigset_t UnBlockSig,
|
|
|
|
BlockSig,
|
2009-08-29 19:26:52 +00:00
|
|
|
StartupBlockSig;
|
2004-05-29 22:48:23 +00:00
|
|
|
#else
|
|
|
|
int UnBlockSig,
|
|
|
|
BlockSig,
|
2009-08-29 19:26:52 +00:00
|
|
|
StartupBlockSig;
|
2004-05-29 22:48:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2000-06-28 03:33:33 +00:00
|
|
|
/*
|
2009-08-29 19:26:52 +00:00
|
|
|
* Initialize BlockSig, UnBlockSig, and StartupBlockSig.
|
2000-06-28 03:33:33 +00:00
|
|
|
*
|
|
|
|
* BlockSig is the set of signals to block when we are trying to block
|
|
|
|
* signals. This includes all signals we normally expect to get, but NOT
|
|
|
|
* signals that should never be turned off.
|
|
|
|
*
|
2009-08-29 19:26:52 +00:00
|
|
|
* StartupBlockSig is the set of signals to block during startup packet
|
|
|
|
* collection; it's essentially BlockSig minus SIGTERM, SIGQUIT, SIGALRM.
|
2001-09-08 01:10:21 +00:00
|
|
|
*
|
2000-06-28 03:33:33 +00:00
|
|
|
* UnBlockSig is the set of signals to block when we don't want to block
|
|
|
|
* signals (is this ever nonzero??)
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pqinitmask(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_SIGPROCMASK
|
2005-02-14 23:02:03 +00:00
|
|
|
|
2000-06-28 03:33:33 +00:00
|
|
|
sigemptyset(&UnBlockSig);
|
2005-02-14 23:02:03 +00:00
|
|
|
|
|
|
|
/* First set all signals, then clear some. */
|
2000-06-28 03:33:33 +00:00
|
|
|
sigfillset(&BlockSig);
|
2009-08-29 19:26:52 +00:00
|
|
|
sigfillset(&StartupBlockSig);
|
2001-03-22 04:01:46 +00:00
|
|
|
|
2000-06-29 02:17:42 +00:00
|
|
|
/*
|
2005-10-15 02:49:52 +00:00
|
|
|
* Unmark those signals that should never be blocked. Some of these signal
|
|
|
|
* names don't exist on all platforms. Most do, but might as well ifdef
|
|
|
|
* them all for consistency...
|
2000-06-29 02:17:42 +00:00
|
|
|
*/
|
|
|
|
#ifdef SIGTRAP
|
|
|
|
sigdelset(&BlockSig, SIGTRAP);
|
2009-08-29 19:26:52 +00:00
|
|
|
sigdelset(&StartupBlockSig, SIGTRAP);
|
2000-06-29 02:17:42 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGABRT
|
2000-06-28 03:33:33 +00:00
|
|
|
sigdelset(&BlockSig, SIGABRT);
|
2009-08-29 19:26:52 +00:00
|
|
|
sigdelset(&StartupBlockSig, SIGABRT);
|
2000-06-29 02:17:42 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGILL
|
2000-06-28 03:33:33 +00:00
|
|
|
sigdelset(&BlockSig, SIGILL);
|
2009-08-29 19:26:52 +00:00
|
|
|
sigdelset(&StartupBlockSig, SIGILL);
|
2000-06-29 02:17:42 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGFPE
|
|
|
|
sigdelset(&BlockSig, SIGFPE);
|
2009-08-29 19:26:52 +00:00
|
|
|
sigdelset(&StartupBlockSig, SIGFPE);
|
2000-06-29 02:17:42 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSEGV
|
2000-06-28 03:33:33 +00:00
|
|
|
sigdelset(&BlockSig, SIGSEGV);
|
2009-08-29 19:26:52 +00:00
|
|
|
sigdelset(&StartupBlockSig, SIGSEGV);
|
2000-06-29 02:17:42 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGBUS
|
2000-06-28 03:33:33 +00:00
|
|
|
sigdelset(&BlockSig, SIGBUS);
|
2009-08-29 19:26:52 +00:00
|
|
|
sigdelset(&StartupBlockSig, SIGBUS);
|
2000-06-29 02:17:42 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGSYS
|
2000-06-28 03:33:33 +00:00
|
|
|
sigdelset(&BlockSig, SIGSYS);
|
2009-08-29 19:26:52 +00:00
|
|
|
sigdelset(&StartupBlockSig, SIGSYS);
|
2000-06-29 02:17:42 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SIGCONT
|
|
|
|
sigdelset(&BlockSig, SIGCONT);
|
2009-08-29 19:26:52 +00:00
|
|
|
sigdelset(&StartupBlockSig, SIGCONT);
|
2001-09-07 16:12:49 +00:00
|
|
|
#endif
|
2005-02-14 23:02:35 +00:00
|
|
|
|
2009-08-29 19:26:52 +00:00
|
|
|
/* Signals unique to startup */
|
2001-09-07 16:12:49 +00:00
|
|
|
#ifdef SIGQUIT
|
2009-08-29 19:26:52 +00:00
|
|
|
sigdelset(&StartupBlockSig, SIGQUIT);
|
2000-06-29 02:17:42 +00:00
|
|
|
#endif
|
2005-02-14 23:02:35 +00:00
|
|
|
#ifdef SIGTERM
|
2009-08-29 19:26:52 +00:00
|
|
|
sigdelset(&StartupBlockSig, SIGTERM);
|
2005-02-14 23:02:35 +00:00
|
|
|
#endif
|
2001-09-21 17:06:12 +00:00
|
|
|
#ifdef SIGALRM
|
2009-08-29 19:26:52 +00:00
|
|
|
sigdelset(&StartupBlockSig, SIGALRM);
|
2001-09-21 17:06:12 +00:00
|
|
|
#endif
|
2000-06-28 03:33:33 +00:00
|
|
|
#else
|
2005-02-14 23:02:03 +00:00
|
|
|
/* Set the signals we want. */
|
2000-06-28 03:33:33 +00:00
|
|
|
UnBlockSig = 0;
|
2005-02-14 23:02:35 +00:00
|
|
|
BlockSig = sigmask(SIGQUIT) |
|
2000-06-28 03:33:33 +00:00
|
|
|
sigmask(SIGTERM) | sigmask(SIGALRM) |
|
2005-10-15 02:49:52 +00:00
|
|
|
/* common signals between two */
|
2005-02-14 23:02:35 +00:00
|
|
|
sigmask(SIGHUP) |
|
2000-06-28 03:33:33 +00:00
|
|
|
sigmask(SIGINT) | sigmask(SIGUSR1) |
|
|
|
|
sigmask(SIGUSR2) | sigmask(SIGCHLD) |
|
|
|
|
sigmask(SIGWINCH) | sigmask(SIGFPE);
|
2009-08-29 19:26:52 +00:00
|
|
|
StartupBlockSig = sigmask(SIGHUP) |
|
2001-09-07 16:12:49 +00:00
|
|
|
sigmask(SIGINT) | sigmask(SIGUSR1) |
|
|
|
|
sigmask(SIGUSR2) | sigmask(SIGCHLD) |
|
|
|
|
sigmask(SIGWINCH) | sigmask(SIGFPE);
|
2000-06-28 03:33:33 +00:00
|
|
|
#endif
|
|
|
|
}
|