1
1
diff --git a/src/backend/storage/ipc/procsignal.c b/src/backend/storage/ipc/procsignal.c
2
- indexb9302ac..95f7da2 100644
2
+ indexb0dd7d1..1f14b0d 100644
3
3
--- a/src/backend/storage/ipc/procsignal.c
4
4
+++ b/src/backend/storage/ipc/procsignal.c
5
- @@ -27,6 +27,7 @@
6
- #include "storage/shmem.h"
7
- #include "storage/sinval.h"
8
- #include "tcop/tcopprot.h"
9
- + #include "utils/memutils.h"
10
-
11
-
12
- /*
13
- @@ -60,12 +61,17 @@ typedef struct
5
+ @@ -60,12 +60,17 @@ typedef struct
14
6
*/
15
7
#define NumProcSignalSlots(MaxBackends + NUM_AUXPROCTYPES)
16
8
@@ -28,12 +20,12 @@ index b9302ac..95f7da2 100644
28
20
/*
29
21
* ProcSignalShmemSize
30
22
*Compute space needed for procsignal's shared memory
31
- @@ -166,6 +172 ,57 @@ CleanupProcSignalState(int status, Datum arg)
23
+ @@ -166,6 +171 ,57 @@ CleanupProcSignalState(int status, Datum arg)
32
24
}
33
25
34
26
/*
35
27
+ * RegisterCustomProcSignalHandler
36
- + * Assign specific handlerfor custom process signal with new ProcSignalReason key.
28
+ + * Assign specific handlerof custom process signal with new ProcSignalReason key.
37
29
+ * Return INVALID_PROCSIGNAL if all custom signals have been assigned.
38
30
+ */
39
31
+ ProcSignalReason
@@ -62,7 +54,7 @@ index b9302ac..95f7da2 100644
62
54
+ {
63
55
+ ProcSignalHandler_type old;
64
56
+
65
- + AssertArg (reason >= PROCSIG_CUSTOM_1 && reason <= PROCSIG_CUSTOM_N);
57
+ + Assert (reason >= PROCSIG_CUSTOM_1 && reason <= PROCSIG_CUSTOM_N);
66
58
+
67
59
+ old = CustomHandlers[reason - PROCSIG_CUSTOM_1];
68
60
+ CustomHandlers[reason - PROCSIG_CUSTOM_1] = handler;
@@ -77,7 +69,7 @@ index b9302ac..95f7da2 100644
77
69
+ ProcSignalHandler_type
78
70
+ GetCustomProcSignalHandler(ProcSignalReason reason)
79
71
+ {
80
- + AssertArg (reason >= PROCSIG_CUSTOM_1 && reason <= PROCSIG_CUSTOM_N);
72
+ + Assert (reason >= PROCSIG_CUSTOM_1 && reason <= PROCSIG_CUSTOM_N);
81
73
+
82
74
+ return CustomHandlers[reason - PROCSIG_CUSTOM_1];
83
75
+ }
@@ -86,7 +78,7 @@ index b9302ac..95f7da2 100644
86
78
* SendProcSignal
87
79
*Send a signal to a Postgres process
88
80
*
89
- @@ -260,7 +317 ,8 @@ CheckProcSignal(ProcSignalReason reason)
81
+ @@ -260,7 +316 ,8 @@ CheckProcSignal(ProcSignalReason reason)
90
82
void
91
83
procsignal_sigusr1_handler(SIGNAL_ARGS)
92
84
{
@@ -96,7 +88,7 @@ index b9302ac..95f7da2 100644
96
88
97
89
if (CheckProcSignal(PROCSIG_CATCHUP_INTERRUPT))
98
90
HandleCatchupInterrupt();
99
- @@ -292,9 +350,87 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
91
+ @@ -292,9 +349,55 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
100
92
if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN))
101
93
RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);
102
94
@@ -119,7 +111,7 @@ index b9302ac..95f7da2 100644
119
111
+ {
120
112
+ intsave_errno = errno;
121
113
+
122
- + AssertArg (reason >= PROCSIG_CUSTOM_1 && reason <= PROCSIG_CUSTOM_N);
114
+ + Assert (reason >= PROCSIG_CUSTOM_1 && reason <= PROCSIG_CUSTOM_N);
123
115
+
124
116
+ /* set interrupt flags */
125
117
+ InterruptPending = true;
@@ -140,31 +132,6 @@ index b9302ac..95f7da2 100644
140
132
+ CheckAndHandleCustomSignals(void)
141
133
+ {
142
134
+ int i;
143
- + MemoryContext oldcontext;
144
- +
145
- + static MemoryContext hcs_context = NULL;
146
- +
147
- + /*
148
- + * This is invoked from ProcessInterrupts(), and since some of the
149
- + * functions it calls contain CHECK_FOR_INTERRUPTS(), there is a potential
150
- + * for recursive calls if more signals are received while this runs, so
151
- + * let's block interrupts until done.
152
- + */
153
- + HOLD_INTERRUPTS();
154
- +
155
- + /*
156
- + * Moreover, CurrentMemoryContext might be pointing almost anywhere. We
157
- + * don't want to risk leaking data into long-lived contexts, so let's do
158
- + * our work here in a private context that we can reset on each use.
159
- + */
160
- + if (hcs_context == NULL)/* first time through? */
161
- + hcs_context = AllocSetContextCreate(TopMemoryContext,
162
- + "HandleCustomSignals",
163
- + ALLOCSET_DEFAULT_SIZES);
164
- + else
165
- + MemoryContextReset(hcs_context);
166
- +
167
- + oldcontext = MemoryContextSwitchTo(hcs_context);
168
135
+
169
136
+ for (i = 0; i < NUM_CUSTOM_PROCSIGNALS; i++)
170
137
+ if (CustomSignalPendings[i])
@@ -176,19 +143,12 @@ index b9302ac..95f7da2 100644
176
143
+ if (handler)
177
144
+ handler();
178
145
+ }
179
- +
180
- + MemoryContextSwitchTo(oldcontext);
181
- +
182
- + /* Might as well clear the context on our way out */
183
- + MemoryContextReset(hcs_context);
184
- +
185
- + RESUME_INTERRUPTS();
186
146
+ }
187
147
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
188
- index63a1994..0dfad33 100644
148
+ index7a9ada2..e9698e1 100644
189
149
--- a/src/backend/tcop/postgres.c
190
150
+++ b/src/backend/tcop/postgres.c
191
- @@ -3012 ,6 +3012 ,8 @@ ProcessInterrupts(void)
151
+ @@ -3053 ,6 +3053 ,8 @@ ProcessInterrupts(void)
192
152
193
153
if (ParallelMessagePending)
194
154
HandleParallelMessages();
@@ -198,19 +158,19 @@ index 63a1994..0dfad33 100644
198
158
199
159
200
160
diff --git a/src/include/storage/procsignal.h b/src/include/storage/procsignal.h
201
- index20bb05b..9b16eb3 100644
161
+ index6db0d69..ceadc09 100644
202
162
--- a/src/include/storage/procsignal.h
203
163
+++ b/src/include/storage/procsignal.h
204
- @@ -17,6 +17,8 @@
205
- #include "storage/backendid.h"
164
+ @@ -16,7 +16,7 @@
206
165
166
+ #include "storage/backendid.h"
207
167
168
+ -
208
169
+ #define NUM_CUSTOM_PROCSIGNALS 64
209
- +
210
170
/*
211
171
* Reasons for signalling a Postgres child process (a backend or an auxiliary
212
172
* process, like checkpointer). We can cope with concurrent signals for different
213
- @@ -29,6 +31 ,8 @@
173
+ @@ -29,6 +29 ,8 @@
214
174
*/
215
175
typedef enum
216
176
{
@@ -219,7 +179,7 @@ index 20bb05b..9b16eb3 100644
219
179
PROCSIG_CATCHUP_INTERRUPT,/* sinval catchup interrupt */
220
180
PROCSIG_NOTIFY_INTERRUPT,/* listen/notify interrupt */
221
181
PROCSIG_PARALLEL_MESSAGE,/* message from cooperating parallel backend */
222
- @@ -42,9 +46 ,20 @@ typedef enum
182
+ @@ -42,9 +44 ,20 @@ typedef enum
223
183
PROCSIG_RECOVERY_CONFLICT_BUFFERPIN,
224
184
PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK,
225
185
@@ -240,7 +200,7 @@ index 20bb05b..9b16eb3 100644
240
200
/*
241
201
* prototypes for functions in procsignal.c
242
202
*/
243
- @@ -52,9 +67 ,15 @@ extern Size ProcSignalShmemSize(void);
203
+ @@ -52,9 +65 ,15 @@ extern Size ProcSignalShmemSize(void);
244
204
extern void ProcSignalShmemInit(void);
245
205
246
206
extern void ProcSignalInit(int pss_idx);