PostgreSQL Source Code  git master
pqsignal.c File Reference
#include "postgres.h"
#include "libpq/pqsignal.h"
Include dependency graph for pqsignal.c:

Go to the source code of this file.

Functions

void pqinitmask (void)
 
pqsigfunc pqsignal_pm (int signo, pqsigfunc func)
 

Variables

sigset_t UnBlockSig
 
sigset_t BlockSig
 
sigset_t StartupBlockSig
 

Function Documentation

◆ pqinitmask()

void pqinitmask ( void  )

Definition at line 41 of file pqsignal.c.

References BlockSig, SIGABRT, SIGALRM, SIGCONT, SIGQUIT, SIGTRAP, StartupBlockSig, and UnBlockSig.

Referenced by BackendRun(), PostgresMain(), and PostmasterMain().

42 {
43  sigemptyset(&UnBlockSig);
44 
45  /* First set all signals, then clear some. */
46  sigfillset(&BlockSig);
47  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  sigdelset(&BlockSig, SIGTRAP);
56  sigdelset(&StartupBlockSig, SIGTRAP);
57 #endif
58 #ifdef SIGABRT
59  sigdelset(&BlockSig, SIGABRT);
60  sigdelset(&StartupBlockSig, SIGABRT);
61 #endif
62 #ifdef SIGILL
63  sigdelset(&BlockSig, SIGILL);
64  sigdelset(&StartupBlockSig, SIGILL);
65 #endif
66 #ifdef SIGFPE
67  sigdelset(&BlockSig, SIGFPE);
68  sigdelset(&StartupBlockSig, SIGFPE);
69 #endif
70 #ifdef SIGSEGV
71  sigdelset(&BlockSig, SIGSEGV);
72  sigdelset(&StartupBlockSig, SIGSEGV);
73 #endif
74 #ifdef SIGBUS
75  sigdelset(&BlockSig, SIGBUS);
76  sigdelset(&StartupBlockSig, SIGBUS);
77 #endif
78 #ifdef SIGSYS
79  sigdelset(&BlockSig, SIGSYS);
80  sigdelset(&StartupBlockSig, SIGSYS);
81 #endif
82 #ifdef SIGCONT
83  sigdelset(&BlockSig, SIGCONT);
84  sigdelset(&StartupBlockSig, SIGCONT);
85 #endif
86 
87 /* Signals unique to startup */
88 #ifdef SIGQUIT
89  sigdelset(&StartupBlockSig, SIGQUIT);
90 #endif
91 #ifdef SIGTERM
92  sigdelset(&StartupBlockSig, SIGTERM);
93 #endif
94 #ifdef SIGALRM
95  sigdelset(&StartupBlockSig, SIGALRM);
96 #endif
97 }
#define SIGQUIT
Definition: win32_port.h:155
#define SIGCONT
Definition: win32_port.h:163
#define SIGTRAP
Definition: win32_port.h:156
#define SIGABRT
Definition: win32_port.h:157
sigset_t UnBlockSig
Definition: pqsignal.c:22
sigset_t BlockSig
Definition: pqsignal.c:22
#define SIGALRM
Definition: win32_port.h:160
sigset_t StartupBlockSig
Definition: pqsignal.c:22

◆ pqsignal_pm()

pqsigfunc pqsignal_pm ( int  signo,
pqsigfunc  func 
)

Definition at line 118 of file pqsignal.c.

References BlockSig, pqsignal(), SIG_DFL, SIG_ERR, SIG_IGN, and SIGCHLD.

Referenced by PostmasterMain().

119 {
120 #ifndef WIN32
121  struct sigaction act,
122  oact;
123 
124  act.sa_handler = func;
125  if (func == SIG_IGN || func == SIG_DFL)
126  {
127  /* in these cases, act the same as pqsignal() */
128  sigemptyset(&act.sa_mask);
129  act.sa_flags = SA_RESTART;
130  }
131  else
132  {
133  act.sa_mask = BlockSig;
134  act.sa_flags = 0;
135  }
136 #ifdef SA_NOCLDSTOP
137  if (signo == SIGCHLD)
138  act.sa_flags |= SA_NOCLDSTOP;
139 #endif
140  if (sigaction(signo, &act, &oact) < 0)
141  return SIG_ERR;
142  return oact.sa_handler;
143 #else /* WIN32 */
144  return pqsignal(signo, func);
145 #endif
146 }
pqsigfunc pqsignal(int signo, pqsigfunc func)
Definition: pqsignal.c:40
#define SIGCHLD
Definition: win32_port.h:164
#define SIG_ERR
Definition: win32_port.h:150
#define SIG_IGN
Definition: win32_port.h:151
sigset_t BlockSig
Definition: pqsignal.c:22
#define SIG_DFL
Definition: win32_port.h:149

Variable Documentation

◆ BlockSig

◆ StartupBlockSig

sigset_t StartupBlockSig

Definition at line 22 of file pqsignal.c.

Referenced by BackendInitialize(), and pqinitmask().

◆ UnBlockSig