PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pqsignal.c File Reference
#include "c.h"
#include <signal.h>
#include <unistd.h>
#include "libpq/pqsignal.h"
#include "miscadmin.h"
Include dependency graph for pqsignal.c:

Go to the source code of this file.

Macros

#define PG_NSIG   (64) /* XXX: wild guess */
 
#define USE_SIGACTION
 

Functions

 StaticAssertDecl (SIGUSR2< PG_NSIG, "SIGUSR2 >= PG_NSIG")
 
static void wrapper_handler (int postgres_signal_arg)
 
void pqsignal (int signo, pqsigfunc func)
 

Variables

static volatile pqsigfunc pqsignal_handlers [PG_NSIG]
 

Macro Definition Documentation

◆ PG_NSIG

#define PG_NSIG   (64) /* XXX: wild guess */

Definition at line 63 of file pqsignal.c.

◆ USE_SIGACTION

#define USE_SIGACTION

Definition at line 67 of file pqsignal.c.

Function Documentation

◆ pqsignal()

void pqsignal ( int  signo,
pqsigfunc  func 
)

Definition at line 156 of file pqsignal.c.

157{
158#ifdef USE_SIGACTION
159 struct sigaction act;
160#else
162#endif
163 bool is_ign = func == PG_SIG_IGN;
164 bool is_dfl = func == PG_SIG_DFL;
165
166 Assert(signo > 0);
168
169 /* set up indirection handler */
170 if (!(is_ign || is_dfl))
171 {
172 pqsignal_handlers[signo] = func; /* assumed atomic */
173 }
174
175 /*
176 * Configure system to either ignore/reset the signal handler, or to
177 * forward it to wrapper_handler.
178 */
179#ifdef USE_SIGACTION
180 sigemptyset(&act.sa_mask);
181 act.sa_flags = SA_RESTART;
182
183 if (is_ign)
184 act.sa_handler = SIG_IGN;
185 else if (is_dfl)
186 act.sa_handler = SIG_DFL;
187#ifdef USE_SIGINFO
188 else
189 {
190 act.sa_sigaction = wrapper_handler;
191 act.sa_flags |= SA_SIGINFO;
192 }
193#else
194 else
195 act.sa_handler = wrapper_handler;
196#endif
197
198#ifdef SA_NOCLDSTOP
199 if (signo == SIGCHLD)
200 act.sa_flags |= SA_NOCLDSTOP;
201#endif
202 if (sigaction(signo, &act, NULL) < 0)
203 Assert(false); /* probably indicates coding error */
204#else /* no USE_SIGACTION */
205
206 /*
207 * Forward to Windows native signal system, we need to send this though
208 * wrapper handler as it it needs to take single argument only.
209 */
210 if (is_ign)
212 else if (is_dfl)
214 else
216
218 Assert(false); /* probably indicates coding error */
219#endif
220}
#define Assert(condition)
Definition c.h:943
static void wrapper_handler(int postgres_signal_arg)
Definition pqsignal.c:98
static volatile pqsigfunc pqsignal_handlers[PG_NSIG]
Definition pqsignal.c:80
#define PG_NSIG
Definition pqsignal.c:63
#define PG_SIG_IGN
Definition port.h:551
#define PG_SIG_DFL
Definition port.h:550
static int fb(int x)
#define SIGCHLD
Definition win32_port.h:168

◆ StaticAssertDecl()

StaticAssertDecl ( )

◆ wrapper_handler()

static void wrapper_handler ( int  postgres_signal_arg)
static

Definition at line 98 of file pqsignal.c.

100{
101 int save_errno = errno;
103
106
107#ifndef FRONTEND
108
109 /*
110 * We expect processes to set MyProcPid before calling pqsignal() or
111 * before accepting signals.
112 */
115
116 if (unlikely(MyProcPid != (int) getpid()))
117 {
120 return;
121 }
122#endif
123
124#ifdef HAVE_SA_SIGINFO
125
126 /*
127 * If supported by the system, forward interesting information from the
128 * system's extended signal information to our platform independent
129 * format.
130 */
131 pg_info.pid = info->si_pid;
132 pg_info.uid = info->si_uid;
133#else
134
135 /*
136 * Otherwise forward values indicating that we do not have the
137 * information.
138 */
139 pg_info.pid = 0;
140 pg_info.uid = 0;
141#endif
142
144
146}
#define unlikely(x)
Definition c.h:438
pid_t PostmasterPid
Definition globals.c:108
int MyProcPid
Definition globals.c:49
bool IsUnderPostmaster
Definition globals.c:122
#define pqsignal
Definition port.h:547

Variable Documentation

◆ pqsignal_handlers

volatile pqsigfunc pqsignal_handlers[PG_NSIG]
static

Definition at line 80 of file pqsignal.c.