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 */
 

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);
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}
#define Assert(condition)
Definition c.h:873
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
static int fb(int x)
#define SIGCHLD
Definition win32_port.h:168

References fb(), 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
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 {
106 return;
107 }
108#endif
109
111
113}
#define unlikely(x)
Definition c.h:412
pid_t PostmasterPid
Definition globals.c:106
int MyProcPid
Definition globals.c:47
bool IsUnderPostmaster
Definition globals.c:120
#define pqsignal
Definition port.h:547

Variable Documentation

◆ pqsignal_handlers

volatile pqsigfunc pqsignal_handlers[PG_NSIG]
static

Definition at line 72 of file pqsignal.c.