PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 120 of file pqsignal.c.

121{
122#if !(defined(WIN32) && defined(FRONTEND))
123 struct sigaction act;
124#endif
125
126 Assert(signo < PG_NSIG);
127
128 if (func != SIG_IGN && func != SIG_DFL)
129 {
130 pqsignal_handlers[signo] = func; /* assumed atomic */
131 func = wrapper_handler;
132 }
133
134#if !(defined(WIN32) && defined(FRONTEND))
135 act.sa_handler = func;
136 sigemptyset(&act.sa_mask);
137 act.sa_flags = SA_RESTART;
138#ifdef SA_NOCLDSTOP
139 if (signo == SIGCHLD)
140 act.sa_flags |= SA_NOCLDSTOP;
141#endif
142 if (sigaction(signo, &act, NULL) < 0)
143 Assert(false); /* probably indicates coding error */
144#else
145 /* Forward to Windows native signal system. */
146 if (signal(signo, func) == SIG_ERR)
147 Assert(false); /* probably indicates coding error */
148#endif
149}
#define Assert(condition)
Definition: c.h:815
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#ifndef FRONTEND
91
92 /*
93 * We expect processes to set MyProcPid before calling pqsignal() or
94 * before accepting signals.
95 */
98
99 if (unlikely(MyProcPid != (int) getpid()))
100 {
101 pqsignal(postgres_signal_arg, SIG_DFL);
102 raise(postgres_signal_arg);
103 return;
104 }
105#endif
106
107 (*pqsignal_handlers[postgres_signal_arg]) (postgres_signal_arg);
108
109 errno = save_errno;
110}
#define unlikely(x)
Definition: c.h:333
pid_t PostmasterPid
Definition: globals.c:105
int MyProcPid
Definition: globals.c:46
bool IsUnderPostmaster
Definition: globals.c:119
void pqsignal(int signo, pqsigfunc func)
Definition: pqsignal.c:120

Variable Documentation

◆ pqsignal_handlers

volatile pqsigfunc pqsignal_handlers[PG_NSIG]
static

Definition at line 72 of file pqsignal.c.