PostgreSQL Source Code git master
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 */
 

Functions

 StaticAssertDecl (SIGUSR2< PG_NSIG, "SIGUSR2 >= PG_NSIG")
 
static void wrapper_handler (SIGNAL_ARGS)
 
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.

Function Documentation

◆ pqsignal()

void pqsignal ( int  signo,
pqsigfunc  func 
)

Definition at line 123 of file pqsignal.c.

124{
125#if !(defined(WIN32) && defined(FRONTEND))
126 struct sigaction act;
127#endif
128
129 Assert(signo > 0);
130 Assert(signo < PG_NSIG);
131
132 if (func != SIG_IGN && func != SIG_DFL)
133 {
134 pqsignal_handlers[signo] = func; /* assumed atomic */
135 func = wrapper_handler;
136 }
137
138#if !(defined(WIN32) && defined(FRONTEND))
139 act.sa_handler = func;
140 sigemptyset(&act.sa_mask);
141 act.sa_flags = SA_RESTART;
142#ifdef SA_NOCLDSTOP
143 if (signo == SIGCHLD)
144 act.sa_flags |= SA_NOCLDSTOP;
145#endif
146 if (sigaction(signo, &act, NULL) < 0)
147 Assert(false); /* probably indicates coding error */
148#else
149 /* Forward to Windows native signal system. */
150 if (signal(signo, func) == SIG_ERR)
151 Assert(false); /* probably indicates coding error */
152#endif
153}
Assert(PointerIsAligned(start, uint64))
static void wrapper_handler(SIGNAL_ARGS)
Definition: pqsignal.c:86
static volatile pqsigfunc pqsignal_handlers[PG_NSIG]
Definition: pqsignal.c:72
#define PG_NSIG
Definition: pqsignal.c:63
#define SIGCHLD
Definition: win32_port.h:168

References SIGALRM, and SIGCHLD.

◆ StaticAssertDecl()

StaticAssertDecl ( )

◆ wrapper_handler()

static void wrapper_handler ( SIGNAL_ARGS  )
static

Definition at line 86 of file pqsignal.c.

87{
88 int save_errno = errno;
89
90 Assert(postgres_signal_arg > 0);
91 Assert(postgres_signal_arg < PG_NSIG);
92
93#ifndef FRONTEND
94
95 /*
96 * We expect processes to set MyProcPid before calling pqsignal() or
97 * before accepting signals.
98 */
101
102 if (unlikely(MyProcPid != (int) getpid()))
103 {
104 pqsignal(postgres_signal_arg, SIG_DFL);
105 raise(postgres_signal_arg);
106 return;
107 }
108#endif
109
110 (*pqsignal_handlers[postgres_signal_arg]) (postgres_signal_arg);
111
112 errno = save_errno;
113}
#define unlikely(x)
Definition: c.h:347
pid_t PostmasterPid
Definition: globals.c:107
int MyProcPid
Definition: globals.c:48
bool IsUnderPostmaster
Definition: globals.c:121
void pqsignal(int signo, pqsigfunc func)
Definition: pqsignal.c:123

Variable Documentation

◆ pqsignal_handlers

volatile pqsigfunc pqsignal_handlers[PG_NSIG]
static

Definition at line 72 of file pqsignal.c.