Line data Source code
1 : /*-------------------------------------------------------------------------
2 : *
3 : * pqsignal.c
4 : * Backend signal(2) support (see also src/port/pqsignal.c)
5 : *
6 : * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
7 : * Portions Copyright (c) 1994, Regents of the University of California
8 : *
9 : *
10 : * IDENTIFICATION
11 : * src/backend/libpq/pqsignal.c
12 : *
13 : * ------------------------------------------------------------------------
14 : */
15 :
16 : #include "postgres.h"
17 :
18 : #include "libpq/pqsignal.h"
19 :
20 :
21 : /* Global variables */
22 : sigset_t UnBlockSig,
23 : BlockSig,
24 : StartupBlockSig;
25 :
26 :
27 : /*
28 : * Initialize BlockSig, UnBlockSig, and StartupBlockSig.
29 : *
30 : * BlockSig is the set of signals to block when we are trying to block
31 : * signals. This includes all signals we normally expect to get, but NOT
32 : * signals that should never be turned off.
33 : *
34 : * StartupBlockSig is the set of signals to block during startup packet
35 : * collection; it's essentially BlockSig minus SIGTERM, SIGQUIT, SIGALRM.
36 : *
37 : * UnBlockSig is the set of signals to block when we don't want to block
38 : * signals (is this ever nonzero??)
39 : */
40 : void
41 217 : pqinitmask(void)
42 : {
43 217 : sigemptyset(&UnBlockSig);
44 :
45 : /* First set all signals, then clear some. */
46 217 : sigfillset(&BlockSig);
47 217 : sigfillset(&StartupBlockSig);
48 :
49 : /*
50 : * Unmark those signals that should never be blocked. Some of these signal
51 : * names don't exist on all platforms. Most do, but might as well ifdef
52 : * them all for consistency...
53 : */
54 : #ifdef SIGTRAP
55 217 : sigdelset(&BlockSig, SIGTRAP);
56 217 : sigdelset(&StartupBlockSig, SIGTRAP);
57 : #endif
58 : #ifdef SIGABRT
59 217 : sigdelset(&BlockSig, SIGABRT);
60 217 : sigdelset(&StartupBlockSig, SIGABRT);
61 : #endif
62 : #ifdef SIGILL
63 217 : sigdelset(&BlockSig, SIGILL);
64 217 : sigdelset(&StartupBlockSig, SIGILL);
65 : #endif
66 : #ifdef SIGFPE
67 217 : sigdelset(&BlockSig, SIGFPE);
68 217 : sigdelset(&StartupBlockSig, SIGFPE);
69 : #endif
70 : #ifdef SIGSEGV
71 217 : sigdelset(&BlockSig, SIGSEGV);
72 217 : sigdelset(&StartupBlockSig, SIGSEGV);
73 : #endif
74 : #ifdef SIGBUS
75 217 : sigdelset(&BlockSig, SIGBUS);
76 217 : sigdelset(&StartupBlockSig, SIGBUS);
77 : #endif
78 : #ifdef SIGSYS
79 217 : sigdelset(&BlockSig, SIGSYS);
80 217 : sigdelset(&StartupBlockSig, SIGSYS);
81 : #endif
82 : #ifdef SIGCONT
83 217 : sigdelset(&BlockSig, SIGCONT);
84 217 : sigdelset(&StartupBlockSig, SIGCONT);
85 : #endif
86 :
87 : /* Signals unique to startup */
88 : #ifdef SIGQUIT
89 217 : sigdelset(&StartupBlockSig, SIGQUIT);
90 : #endif
91 : #ifdef SIGTERM
92 217 : sigdelset(&StartupBlockSig, SIGTERM);
93 : #endif
94 : #ifdef SIGALRM
95 217 : sigdelset(&StartupBlockSig, SIGALRM);
96 : #endif
97 217 : }
|