3 * $Header: /cvsroot/pgpool/pgpool-II/pool_signal.c,v 1.3.2.1 2009/08/22 04:19:49 t-ishii Exp $
5 * pgpool: a language independent connection pool server for PostgreSQL
6 * written by Tatsuo Ishii
8 * Portions Copyright (c) 2003-2008, PgPool Global Development Group
9 * Portions Copyright (c) 2003-2004, PostgreSQL Global Development Group
11 * Permission to use, copy, modify, and distribute this software and
12 * its documentation for any purpose and without fee is hereby
13 * granted, provided that the above copyright notice appear in all
14 * copies and that both that copyright notice and this permission
15 * notice appear in supporting documentation, and that the name of the
16 * author not be used in advertising or publicity pertaining to
17 * distribution of the software without specific, written prior
18 * permission. The author makes no representations about the
19 * suitability of this software for any purpose. It is provided "as
20 * is" without express or implied warranty.
24 * Signal stuff. Stolen from PostgreSQL source code.
28 #include "pool_signal.h"
31 #ifdef HAVE_SIGPROCMASK
43 * Initialize BlockSig, UnBlockSig, and AuthBlockSig.
45 * BlockSig is the set of signals to block when we are trying to block
46 * signals. This includes all signals we normally expect to get, but NOT
47 * signals that should never be turned off.
49 * AuthBlockSig is the set of signals to block during authentication;
50 * it's essentially BlockSig minus SIGTERM, SIGQUIT, SIGALRM.
52 * UnBlockSig is the set of signals to block when we don't want to block
53 * signals (is this ever nonzero??)
58 #ifdef HAVE_SIGPROCMASK
59 sigemptyset(&UnBlockSig);
60 sigfillset(&BlockSig);
61 sigfillset(&AuthBlockSig);
64 * Unmark those signals that should never be blocked. Some of these
65 * signal names don't exist on all platforms. Most do, but might as
66 * well ifdef them all for consistency...
69 sigdelset(&BlockSig, SIGTRAP);
70 sigdelset(&AuthBlockSig, SIGTRAP);
73 sigdelset(&BlockSig, SIGABRT);
74 sigdelset(&AuthBlockSig, SIGABRT);
77 sigdelset(&BlockSig, SIGILL);
78 sigdelset(&AuthBlockSig, SIGILL);
81 sigdelset(&BlockSig, SIGFPE);
82 sigdelset(&AuthBlockSig, SIGFPE);
85 sigdelset(&BlockSig, SIGSEGV);
86 sigdelset(&AuthBlockSig, SIGSEGV);
89 sigdelset(&BlockSig, SIGBUS);
90 sigdelset(&AuthBlockSig, SIGBUS);
93 sigdelset(&BlockSig, SIGSYS);
94 sigdelset(&AuthBlockSig, SIGSYS);
97 sigdelset(&BlockSig, SIGCONT);
98 sigdelset(&AuthBlockSig, SIGCONT);
101 sigdelset(&AuthBlockSig, SIGTERM);
104 sigdelset(&AuthBlockSig, SIGQUIT);
107 sigdelset(&AuthBlockSig, SIGALRM);
111 BlockSig = sigmask(SIGHUP) | sigmask(SIGQUIT) |
112 sigmask(SIGTERM) | sigmask(SIGALRM) |
113 sigmask(SIGINT) | sigmask(SIGUSR1) |
114 sigmask(SIGUSR2) | sigmask(SIGCHLD) |
115 sigmask(SIGWINCH) | sigmask(SIGFPE);
116 AuthBlockSig = sigmask(SIGHUP) |
117 sigmask(SIGINT) | sigmask(SIGUSR1) |
118 sigmask(SIGUSR2) | sigmask(SIGCHLD) |
119 sigmask(SIGWINCH) | sigmask(SIGFPE);
124 /* Win32 signal handling is in backend/port/win32/signal.c */
128 * We need to check actually the system has the posix signals or not, but...
130 #define HAVE_POSIX_SIGNALS
132 * Set up a signal handler
135 pool_signal(int signo, pool_sighandler_t func)
137 #if !defined(HAVE_POSIX_SIGNALS)
138 return signal(signo, func);
140 struct sigaction act,
143 act.sa_handler = func;
144 sigemptyset(&act.sa_mask);
146 if (signo != SIGALRM)
147 act.sa_flags |= SA_RESTART;
149 if (signo == SIGCHLD)
150 act.sa_flags |= SA_NOCLDSTOP;
152 if (sigaction(signo, &act, &oact) < 0)
154 return oact.sa_handler;
155 #endif /* !HAVE_POSIX_SIGNALS */