Header And Logo

PostgreSQL
| The world's most advanced open source database.

pqsignal.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * pqsignal.c
00004  *    Backend signal(2) support (see also src/port/pqsignal.c)
00005  *
00006  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00007  * Portions Copyright (c) 1994, Regents of the University of California
00008  *
00009  *
00010  * IDENTIFICATION
00011  *    src/backend/libpq/pqsignal.c
00012  *
00013  * ------------------------------------------------------------------------
00014  */
00015 
00016 #include "postgres.h"
00017 
00018 #include "libpq/pqsignal.h"
00019 
00020 
00021 #ifdef HAVE_SIGPROCMASK
00022 sigset_t    UnBlockSig,
00023             BlockSig,
00024             StartupBlockSig;
00025 #else
00026 int         UnBlockSig,
00027             BlockSig,
00028             StartupBlockSig;
00029 #endif
00030 
00031 
00032 /*
00033  * Initialize BlockSig, UnBlockSig, and StartupBlockSig.
00034  *
00035  * BlockSig is the set of signals to block when we are trying to block
00036  * signals.  This includes all signals we normally expect to get, but NOT
00037  * signals that should never be turned off.
00038  *
00039  * StartupBlockSig is the set of signals to block during startup packet
00040  * collection; it's essentially BlockSig minus SIGTERM, SIGQUIT, SIGALRM.
00041  *
00042  * UnBlockSig is the set of signals to block when we don't want to block
00043  * signals (is this ever nonzero??)
00044  */
00045 void
00046 pqinitmask(void)
00047 {
00048 #ifdef HAVE_SIGPROCMASK
00049 
00050     sigemptyset(&UnBlockSig);
00051 
00052     /* First set all signals, then clear some. */
00053     sigfillset(&BlockSig);
00054     sigfillset(&StartupBlockSig);
00055 
00056     /*
00057      * Unmark those signals that should never be blocked. Some of these signal
00058      * names don't exist on all platforms.  Most do, but might as well ifdef
00059      * them all for consistency...
00060      */
00061 #ifdef SIGTRAP
00062     sigdelset(&BlockSig, SIGTRAP);
00063     sigdelset(&StartupBlockSig, SIGTRAP);
00064 #endif
00065 #ifdef SIGABRT
00066     sigdelset(&BlockSig, SIGABRT);
00067     sigdelset(&StartupBlockSig, SIGABRT);
00068 #endif
00069 #ifdef SIGILL
00070     sigdelset(&BlockSig, SIGILL);
00071     sigdelset(&StartupBlockSig, SIGILL);
00072 #endif
00073 #ifdef SIGFPE
00074     sigdelset(&BlockSig, SIGFPE);
00075     sigdelset(&StartupBlockSig, SIGFPE);
00076 #endif
00077 #ifdef SIGSEGV
00078     sigdelset(&BlockSig, SIGSEGV);
00079     sigdelset(&StartupBlockSig, SIGSEGV);
00080 #endif
00081 #ifdef SIGBUS
00082     sigdelset(&BlockSig, SIGBUS);
00083     sigdelset(&StartupBlockSig, SIGBUS);
00084 #endif
00085 #ifdef SIGSYS
00086     sigdelset(&BlockSig, SIGSYS);
00087     sigdelset(&StartupBlockSig, SIGSYS);
00088 #endif
00089 #ifdef SIGCONT
00090     sigdelset(&BlockSig, SIGCONT);
00091     sigdelset(&StartupBlockSig, SIGCONT);
00092 #endif
00093 
00094 /* Signals unique to startup */
00095 #ifdef SIGQUIT
00096     sigdelset(&StartupBlockSig, SIGQUIT);
00097 #endif
00098 #ifdef SIGTERM
00099     sigdelset(&StartupBlockSig, SIGTERM);
00100 #endif
00101 #ifdef SIGALRM
00102     sigdelset(&StartupBlockSig, SIGALRM);
00103 #endif
00104 #else
00105     /* Set the signals we want. */
00106     UnBlockSig = 0;
00107     BlockSig = sigmask(SIGQUIT) |
00108         sigmask(SIGTERM) | sigmask(SIGALRM) |
00109     /* common signals between two */
00110         sigmask(SIGHUP) |
00111         sigmask(SIGINT) | sigmask(SIGUSR1) |
00112         sigmask(SIGUSR2) | sigmask(SIGCHLD) |
00113         sigmask(SIGWINCH) | sigmask(SIGFPE);
00114     StartupBlockSig = sigmask(SIGHUP) |
00115         sigmask(SIGINT) | sigmask(SIGUSR1) |
00116         sigmask(SIGUSR2) | sigmask(SIGCHLD) |
00117         sigmask(SIGWINCH) | sigmask(SIGFPE);
00118 #endif
00119 }