1 /*-------------------------------------------------------------------------
2  *
3  * procsignal.c
4  *	  Routines for interprocess signaling
5  *
6  *
7  * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * IDENTIFICATION
11  *	  src/backend/storage/ipc/procsignal.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include <signal.h>
18 #include <unistd.h>
19 
20 #include "access/parallel.h"
21 #include "port/pg_bitutils.h"
22 #include "commands/async.h"
23 #include "miscadmin.h"
24 #include "pgstat.h"
25 #include "replication/walsender.h"
26 #include "storage/condition_variable.h"
27 #include "storage/ipc.h"
28 #include "storage/latch.h"
29 #include "storage/proc.h"
30 #include "storage/shmem.h"
31 #include "storage/sinval.h"
32 #include "tcop/tcopprot.h"
33 #include "utils/memutils.h"
34 
35 /*
36  * The SIGUSR1 signal is multiplexed to support signaling multiple event
37  * types. The specific reason is communicated via flags in shared memory.
38  * We keep a boolean flag for each possible "reason", so that different
39  * reasons can be signaled to a process concurrently.  (However, if the same
40  * reason is signaled more than once nearly simultaneously, the process may
41  * observe it only once.)
42  *
43  * Each process that wants to receive signals registers its process ID
44  * in the ProcSignalSlots array. The array is indexed by backend ID to make
45  * slot allocation simple, and to avoid having to search the array when you
46  * know the backend ID of the process you're signaling.  (We do support
47  * signaling without backend ID, but it's a bit less efficient.)
48  *
49  * The flags are actually declared as "volatile sig_atomic_t" for maximum
50  * portability.  This should ensure that loads and stores of the flag
51  * values are atomic, allowing us to dispense with any explicit locking.
52  *
53  * pss_signalFlags are intended to be set in cases where we don't need to
54  * keep track of whether or not the target process has handled the signal,
55  * but sometimes we need confirmation, as when making a global state change
56  * that cannot be considered complete until all backends have taken notice
57  * of it. For such use cases, we set a bit in pss_barrierCheckMask and then
58  * increment the current "barrier generation"; when the new barrier generation
59  * (or greater) appears in the pss_barrierGeneration flag of every process,
60  * we know that the message has been received everywhere.
61  */
62 typedef struct
63 {
64 	volatile pid_t pss_pid;
65 	volatile sig_atomic_t pss_signalFlags[NUM_PROCSIGNALS];
66 	pg_atomic_uint64 pss_barrierGeneration;
67 	pg_atomic_uint32 pss_barrierCheckMask;
68 	ConditionVariable pss_barrierCV;
69 } ProcSignalSlot;
70 
71 /*
72  * Information that is global to the entire ProcSignal system can be stored
73  * here.
74  *
75  * psh_barrierGeneration is the highest barrier generation in existence.
76  */
77 typedef struct
78 {
79 	pg_atomic_uint64 psh_barrierGeneration;
80 	ProcSignalSlot psh_slot[FLEXIBLE_ARRAY_MEMBER];
81 } ProcSignalHeader;
82 
83 /*
84  * We reserve a slot for each possible BackendId, plus one for each
85  * possible auxiliary process type.  (This scheme assumes there is not
86  * more than one of any auxiliary process type at a time.)
87  */
88 #define NumProcSignalSlots	(MaxBackends + NUM_AUXPROCTYPES)
89 
90 /* Check whether the relevant type bit is set in the flags. */
91 #define BARRIER_SHOULD_CHECK(flags, type) \
92 	(((flags) & (((uint32) 1) << (uint32) (type))) != 0)
93 
94 /* Clear the relevant type bit from the flags. */
95 #define BARRIER_CLEAR_BIT(flags, type) \
96 	((flags) &= ~(((uint32) 1) << (uint32) (type)))
97 
98 static ProcSignalHeader *ProcSignal = NULL;
99 static ProcSignalSlot *MyProcSignalSlot = NULL;
100 
101 static bool CheckProcSignal(ProcSignalReason reason);
102 static void CleanupProcSignalState(int status, Datum arg);
103 static void ResetProcSignalBarrierBits(uint32 flags);
104 static bool ProcessBarrierPlaceholder(void);
105 
106 /*
107  * ProcSignalShmemSize
108  *		Compute space needed for procsignal's shared memory
109  */
110 Size
ProcSignalShmemSize(void)111 ProcSignalShmemSize(void)
112 {
113 	Size		size;
114 
115 	size = mul_size(NumProcSignalSlots, sizeof(ProcSignalSlot));
116 	size = add_size(size, offsetof(ProcSignalHeader, psh_slot));
117 	return size;
118 }
119 
120 /*
121  * ProcSignalShmemInit
122  *		Allocate and initialize procsignal's shared memory
123  */
124 void
ProcSignalShmemInit(void)125 ProcSignalShmemInit(void)
126 {
127 	Size		size = ProcSignalShmemSize();
128 	bool		found;
129 
130 	ProcSignal = (ProcSignalHeader *)
131 		ShmemInitStruct("ProcSignal", size, &found);
132 
133 	/* If we're first, initialize. */
134 	if (!found)
135 	{
136 		int			i;
137 
138 		pg_atomic_init_u64(&ProcSignal->psh_barrierGeneration, 0);
139 
140 		for (i = 0; i < NumProcSignalSlots; ++i)
141 		{
142 			ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
143 
144 			slot->pss_pid = 0;
145 			MemSet(slot->pss_signalFlags, 0, sizeof(slot->pss_signalFlags));
146 			pg_atomic_init_u64(&slot->pss_barrierGeneration, PG_UINT64_MAX);
147 			pg_atomic_init_u32(&slot->pss_barrierCheckMask, 0);
148 			ConditionVariableInit(&slot->pss_barrierCV);
149 		}
150 	}
151 }
152 
153 /*
154  * ProcSignalInit
155  *		Register the current process in the procsignal array
156  *
157  * The passed index should be my BackendId if the process has one,
158  * or MaxBackends + aux process type if not.
159  */
160 void
ProcSignalInit(int pss_idx)161 ProcSignalInit(int pss_idx)
162 {
163 	ProcSignalSlot *slot;
164 	uint64		barrier_generation;
165 
166 	Assert(pss_idx >= 1 && pss_idx <= NumProcSignalSlots);
167 
168 	slot = &ProcSignal->psh_slot[pss_idx - 1];
169 
170 	/* sanity check */
171 	if (slot->pss_pid != 0)
172 		elog(LOG, "process %d taking over ProcSignal slot %d, but it's not empty",
173 			 MyProcPid, pss_idx);
174 
175 	/* Clear out any leftover signal reasons */
176 	MemSet(slot->pss_signalFlags, 0, NUM_PROCSIGNALS * sizeof(sig_atomic_t));
177 
178 	/*
179 	 * Initialize barrier state. Since we're a brand-new process, there
180 	 * shouldn't be any leftover backend-private state that needs to be
181 	 * updated. Therefore, we can broadcast the latest barrier generation and
182 	 * disregard any previously-set check bits.
183 	 *
184 	 * NB: This only works if this initialization happens early enough in the
185 	 * startup sequence that we haven't yet cached any state that might need
186 	 * to be invalidated. That's also why we have a memory barrier here, to be
187 	 * sure that any later reads of memory happen strictly after this.
188 	 */
189 	pg_atomic_write_u32(&slot->pss_barrierCheckMask, 0);
190 	barrier_generation =
191 		pg_atomic_read_u64(&ProcSignal->psh_barrierGeneration);
192 	pg_atomic_write_u64(&slot->pss_barrierGeneration, barrier_generation);
193 	pg_memory_barrier();
194 
195 	/* Mark slot with my PID */
196 	slot->pss_pid = MyProcPid;
197 
198 	/* Remember slot location for CheckProcSignal */
199 	MyProcSignalSlot = slot;
200 
201 	/* Set up to release the slot on process exit */
202 	on_shmem_exit(CleanupProcSignalState, Int32GetDatum(pss_idx));
203 }
204 
205 /*
206  * CleanupProcSignalState
207  *		Remove current process from ProcSignal mechanism
208  *
209  * This function is called via on_shmem_exit() during backend shutdown.
210  */
211 static void
CleanupProcSignalState(int status,Datum arg)212 CleanupProcSignalState(int status, Datum arg)
213 {
214 	int			pss_idx = DatumGetInt32(arg);
215 	ProcSignalSlot *slot;
216 
217 	slot = &ProcSignal->psh_slot[pss_idx - 1];
218 	Assert(slot == MyProcSignalSlot);
219 
220 	/*
221 	 * Clear MyProcSignalSlot, so that a SIGUSR1 received after this point
222 	 * won't try to access it after it's no longer ours (and perhaps even
223 	 * after we've unmapped the shared memory segment).
224 	 */
225 	MyProcSignalSlot = NULL;
226 
227 	/* sanity check */
228 	if (slot->pss_pid != MyProcPid)
229 	{
230 		/*
231 		 * don't ERROR here. We're exiting anyway, and don't want to get into
232 		 * infinite loop trying to exit
233 		 */
234 		elog(LOG, "process %d releasing ProcSignal slot %d, but it contains %d",
235 			 MyProcPid, pss_idx, (int) slot->pss_pid);
236 		return;					/* XXX better to zero the slot anyway? */
237 	}
238 
239 	/*
240 	 * Make this slot look like it's absorbed all possible barriers, so that
241 	 * no barrier waits block on it.
242 	 */
243 	pg_atomic_write_u64(&slot->pss_barrierGeneration, PG_UINT64_MAX);
244 	ConditionVariableBroadcast(&slot->pss_barrierCV);
245 
246 	slot->pss_pid = 0;
247 }
248 
249 /*
250  * SendProcSignal
251  *		Send a signal to a Postgres process
252  *
253  * Providing backendId is optional, but it will speed up the operation.
254  *
255  * On success (a signal was sent), zero is returned.
256  * On error, -1 is returned, and errno is set (typically to ESRCH or EPERM).
257  *
258  * Not to be confused with ProcSendSignal
259  */
260 int
SendProcSignal(pid_t pid,ProcSignalReason reason,BackendId backendId)261 SendProcSignal(pid_t pid, ProcSignalReason reason, BackendId backendId)
262 {
263 	volatile ProcSignalSlot *slot;
264 
265 	if (backendId != InvalidBackendId)
266 	{
267 		slot = &ProcSignal->psh_slot[backendId - 1];
268 
269 		/*
270 		 * Note: Since there's no locking, it's possible that the target
271 		 * process detaches from shared memory and exits right after this
272 		 * test, before we set the flag and send signal. And the signal slot
273 		 * might even be recycled by a new process, so it's remotely possible
274 		 * that we set a flag for a wrong process. That's OK, all the signals
275 		 * are such that no harm is done if they're mistakenly fired.
276 		 */
277 		if (slot->pss_pid == pid)
278 		{
279 			/* Atomically set the proper flag */
280 			slot->pss_signalFlags[reason] = true;
281 			/* Send signal */
282 			return kill(pid, SIGUSR1);
283 		}
284 	}
285 	else
286 	{
287 		/*
288 		 * BackendId not provided, so search the array using pid.  We search
289 		 * the array back to front so as to reduce search overhead.  Passing
290 		 * InvalidBackendId means that the target is most likely an auxiliary
291 		 * process, which will have a slot near the end of the array.
292 		 */
293 		int			i;
294 
295 		for (i = NumProcSignalSlots - 1; i >= 0; i--)
296 		{
297 			slot = &ProcSignal->psh_slot[i];
298 
299 			if (slot->pss_pid == pid)
300 			{
301 				/* the above note about race conditions applies here too */
302 
303 				/* Atomically set the proper flag */
304 				slot->pss_signalFlags[reason] = true;
305 				/* Send signal */
306 				return kill(pid, SIGUSR1);
307 			}
308 		}
309 	}
310 
311 	errno = ESRCH;
312 	return -1;
313 }
314 
315 /*
316  * EmitProcSignalBarrier
317  *		Send a signal to every Postgres process
318  *
319  * The return value of this function is the barrier "generation" created
320  * by this operation. This value can be passed to WaitForProcSignalBarrier
321  * to wait until it is known that every participant in the ProcSignal
322  * mechanism has absorbed the signal (or started afterwards).
323  *
324  * Note that it would be a bad idea to use this for anything that happens
325  * frequently, as interrupting every backend could cause a noticeable
326  * performance hit.
327  *
328  * Callers are entitled to assume that this function will not throw ERROR
329  * or FATAL.
330  */
331 uint64
EmitProcSignalBarrier(ProcSignalBarrierType type)332 EmitProcSignalBarrier(ProcSignalBarrierType type)
333 {
334 	uint32		flagbit = 1 << (uint32) type;
335 	uint64		generation;
336 
337 	/*
338 	 * Set all the flags.
339 	 *
340 	 * Note that pg_atomic_fetch_or_u32 has full barrier semantics, so this is
341 	 * totally ordered with respect to anything the caller did before, and
342 	 * anything that we do afterwards. (This is also true of the later call to
343 	 * pg_atomic_add_fetch_u64.)
344 	 */
345 	for (int i = 0; i < NumProcSignalSlots; i++)
346 	{
347 		volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
348 
349 		pg_atomic_fetch_or_u32(&slot->pss_barrierCheckMask, flagbit);
350 	}
351 
352 	/*
353 	 * Increment the generation counter.
354 	 */
355 	generation =
356 		pg_atomic_add_fetch_u64(&ProcSignal->psh_barrierGeneration, 1);
357 
358 	/*
359 	 * Signal all the processes, so that they update their advertised barrier
360 	 * generation.
361 	 *
362 	 * Concurrency is not a problem here. Backends that have exited don't
363 	 * matter, and new backends that have joined since we entered this
364 	 * function must already have current state, since the caller is
365 	 * responsible for making sure that the relevant state is entirely visible
366 	 * before calling this function in the first place. We still have to wake
367 	 * them up - because we can't distinguish between such backends and older
368 	 * backends that need to update state - but they won't actually need to
369 	 * change any state.
370 	 */
371 	for (int i = NumProcSignalSlots - 1; i >= 0; i--)
372 	{
373 		volatile ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
374 		pid_t		pid = slot->pss_pid;
375 
376 		if (pid != 0)
377 		{
378 			/* see SendProcSignal for details */
379 			slot->pss_signalFlags[PROCSIG_BARRIER] = true;
380 			kill(pid, SIGUSR1);
381 		}
382 	}
383 
384 	return generation;
385 }
386 
387 /*
388  * WaitForProcSignalBarrier - wait until it is guaranteed that all changes
389  * requested by a specific call to EmitProcSignalBarrier() have taken effect.
390  */
391 void
WaitForProcSignalBarrier(uint64 generation)392 WaitForProcSignalBarrier(uint64 generation)
393 {
394 	Assert(generation <= pg_atomic_read_u64(&ProcSignal->psh_barrierGeneration));
395 
396 	for (int i = NumProcSignalSlots - 1; i >= 0; i--)
397 	{
398 		ProcSignalSlot *slot = &ProcSignal->psh_slot[i];
399 		uint64		oldval;
400 
401 		/*
402 		 * It's important that we check only pss_barrierGeneration here and
403 		 * not pss_barrierCheckMask. Bits in pss_barrierCheckMask get cleared
404 		 * before the barrier is actually absorbed, but pss_barrierGeneration
405 		 * is updated only afterward.
406 		 */
407 		oldval = pg_atomic_read_u64(&slot->pss_barrierGeneration);
408 		while (oldval < generation)
409 		{
410 			ConditionVariableSleep(&slot->pss_barrierCV,
411 								   WAIT_EVENT_PROC_SIGNAL_BARRIER);
412 			oldval = pg_atomic_read_u64(&slot->pss_barrierGeneration);
413 		}
414 		ConditionVariableCancelSleep();
415 	}
416 
417 	/*
418 	 * The caller is probably calling this function because it wants to read
419 	 * the shared state or perform further writes to shared state once all
420 	 * backends are known to have absorbed the barrier. However, the read of
421 	 * pss_barrierGeneration was performed unlocked; insert a memory barrier
422 	 * to separate it from whatever follows.
423 	 */
424 	pg_memory_barrier();
425 }
426 
427 /*
428  * Handle receipt of an interrupt indicating a global barrier event.
429  *
430  * All the actual work is deferred to ProcessProcSignalBarrier(), because we
431  * cannot safely access the barrier generation inside the signal handler as
432  * 64bit atomics might use spinlock based emulation, even for reads. As this
433  * routine only gets called when PROCSIG_BARRIER is sent that won't cause a
434  * lot of unnecessary work.
435  */
436 static void
HandleProcSignalBarrierInterrupt(void)437 HandleProcSignalBarrierInterrupt(void)
438 {
439 	InterruptPending = true;
440 	ProcSignalBarrierPending = true;
441 	/* latch will be set by procsignal_sigusr1_handler */
442 }
443 
444 /*
445  * Perform global barrier related interrupt checking.
446  *
447  * Any backend that participates in ProcSignal signaling must arrange to
448  * call this function periodically. It is called from CHECK_FOR_INTERRUPTS(),
449  * which is enough for normal backends, but not necessarily for all types of
450  * background processes.
451  */
452 void
ProcessProcSignalBarrier(void)453 ProcessProcSignalBarrier(void)
454 {
455 	uint64		local_gen;
456 	uint64		shared_gen;
457 	volatile uint32 flags;
458 
459 	Assert(MyProcSignalSlot);
460 
461 	/* Exit quickly if there's no work to do. */
462 	if (!ProcSignalBarrierPending)
463 		return;
464 	ProcSignalBarrierPending = false;
465 
466 	/*
467 	 * It's not unlikely to process multiple barriers at once, before the
468 	 * signals for all the barriers have arrived. To avoid unnecessary work in
469 	 * response to subsequent signals, exit early if we already have processed
470 	 * all of them.
471 	 */
472 	local_gen = pg_atomic_read_u64(&MyProcSignalSlot->pss_barrierGeneration);
473 	shared_gen = pg_atomic_read_u64(&ProcSignal->psh_barrierGeneration);
474 
475 	Assert(local_gen <= shared_gen);
476 
477 	if (local_gen == shared_gen)
478 		return;
479 
480 	/*
481 	 * Get and clear the flags that are set for this backend. Note that
482 	 * pg_atomic_exchange_u32 is a full barrier, so we're guaranteed that the
483 	 * read of the barrier generation above happens before we atomically
484 	 * extract the flags, and that any subsequent state changes happen
485 	 * afterward.
486 	 *
487 	 * NB: In order to avoid race conditions, we must zero
488 	 * pss_barrierCheckMask first and only afterwards try to do barrier
489 	 * processing. If we did it in the other order, someone could send us
490 	 * another barrier of some type right after we called the
491 	 * barrier-processing function but before we cleared the bit. We would
492 	 * have no way of knowing that the bit needs to stay set in that case, so
493 	 * the need to call the barrier-processing function again would just get
494 	 * forgotten. So instead, we tentatively clear all the bits and then put
495 	 * back any for which we don't manage to successfully absorb the barrier.
496 	 */
497 	flags = pg_atomic_exchange_u32(&MyProcSignalSlot->pss_barrierCheckMask, 0);
498 
499 	/*
500 	 * If there are no flags set, then we can skip doing any real work.
501 	 * Otherwise, establish a PG_TRY block, so that we don't lose track of
502 	 * which types of barrier processing are needed if an ERROR occurs.
503 	 */
504 	if (flags != 0)
505 	{
506 		bool		success = true;
507 
508 		PG_TRY();
509 		{
510 			/*
511 			 * Process each type of barrier. The barrier-processing functions
512 			 * should normally return true, but may return false if the
513 			 * barrier can't be absorbed at the current time. This should be
514 			 * rare, because it's pretty expensive.  Every single
515 			 * CHECK_FOR_INTERRUPTS() will return here until we manage to
516 			 * absorb the barrier, and that cost will add up in a hurry.
517 			 *
518 			 * NB: It ought to be OK to call the barrier-processing functions
519 			 * unconditionally, but it's more efficient to call only the ones
520 			 * that might need us to do something based on the flags.
521 			 */
522 			while (flags != 0)
523 			{
524 				ProcSignalBarrierType type;
525 				bool		processed = true;
526 
527 				type = (ProcSignalBarrierType) pg_rightmost_one_pos32(flags);
528 				switch (type)
529 				{
530 					case PROCSIGNAL_BARRIER_PLACEHOLDER:
531 						processed = ProcessBarrierPlaceholder();
532 						break;
533 				}
534 
535 				/*
536 				 * To avoid an infinite loop, we must always unset the bit in
537 				 * flags.
538 				 */
539 				BARRIER_CLEAR_BIT(flags, type);
540 
541 				/*
542 				 * If we failed to process the barrier, reset the shared bit
543 				 * so we try again later, and set a flag so that we don't bump
544 				 * our generation.
545 				 */
546 				if (!processed)
547 				{
548 					ResetProcSignalBarrierBits(((uint32) 1) << type);
549 					success = false;
550 				}
551 			}
552 		}
553 		PG_CATCH();
554 		{
555 			/*
556 			 * If an ERROR occurred, we'll need to try again later to handle
557 			 * that barrier type and any others that haven't been handled yet
558 			 * or weren't successfully absorbed.
559 			 */
560 			ResetProcSignalBarrierBits(flags);
561 			PG_RE_THROW();
562 		}
563 		PG_END_TRY();
564 
565 		/*
566 		 * If some barrier types were not successfully absorbed, we will have
567 		 * to try again later.
568 		 */
569 		if (!success)
570 			return;
571 	}
572 
573 	/*
574 	 * State changes related to all types of barriers that might have been
575 	 * emitted have now been handled, so we can update our notion of the
576 	 * generation to the one we observed before beginning the updates. If
577 	 * things have changed further, it'll get fixed up when this function is
578 	 * next called.
579 	 */
580 	pg_atomic_write_u64(&MyProcSignalSlot->pss_barrierGeneration, shared_gen);
581 	ConditionVariableBroadcast(&MyProcSignalSlot->pss_barrierCV);
582 }
583 
584 /*
585  * If it turns out that we couldn't absorb one or more barrier types, either
586  * because the barrier-processing functions returned false or due to an error,
587  * arrange for processing to be retried later.
588  */
589 static void
ResetProcSignalBarrierBits(uint32 flags)590 ResetProcSignalBarrierBits(uint32 flags)
591 {
592 	pg_atomic_fetch_or_u32(&MyProcSignalSlot->pss_barrierCheckMask, flags);
593 	ProcSignalBarrierPending = true;
594 	InterruptPending = true;
595 }
596 
597 static bool
ProcessBarrierPlaceholder(void)598 ProcessBarrierPlaceholder(void)
599 {
600 	/*
601 	 * XXX. This is just a placeholder until the first real user of this
602 	 * machinery gets committed. Rename PROCSIGNAL_BARRIER_PLACEHOLDER to
603 	 * PROCSIGNAL_BARRIER_SOMETHING_ELSE where SOMETHING_ELSE is something
604 	 * appropriately descriptive. Get rid of this function and instead have
605 	 * ProcessBarrierSomethingElse. Most likely, that function should live in
606 	 * the file pertaining to that subsystem, rather than here.
607 	 *
608 	 * The return value should be 'true' if the barrier was successfully
609 	 * absorbed and 'false' if not. Note that returning 'false' can lead to
610 	 * very frequent retries, so try hard to make that an uncommon case.
611 	 */
612 	return true;
613 }
614 
615 /*
616  * CheckProcSignal - check to see if a particular reason has been
617  * signaled, and clear the signal flag.  Should be called after receiving
618  * SIGUSR1.
619  */
620 static bool
CheckProcSignal(ProcSignalReason reason)621 CheckProcSignal(ProcSignalReason reason)
622 {
623 	volatile ProcSignalSlot *slot = MyProcSignalSlot;
624 
625 	if (slot != NULL)
626 	{
627 		/* Careful here --- don't clear flag if we haven't seen it set */
628 		if (slot->pss_signalFlags[reason])
629 		{
630 			slot->pss_signalFlags[reason] = false;
631 			return true;
632 		}
633 	}
634 
635 	return false;
636 }
637 
638 /*
639  * procsignal_sigusr1_handler - handle SIGUSR1 signal.
640  */
641 void
procsignal_sigusr1_handler(SIGNAL_ARGS)642 procsignal_sigusr1_handler(SIGNAL_ARGS)
643 {
644 	int			save_errno = errno;
645 
646 	if (CheckProcSignal(PROCSIG_CATCHUP_INTERRUPT))
647 		HandleCatchupInterrupt();
648 
649 	if (CheckProcSignal(PROCSIG_NOTIFY_INTERRUPT))
650 		HandleNotifyInterrupt();
651 
652 	if (CheckProcSignal(PROCSIG_PARALLEL_MESSAGE))
653 		HandleParallelMessageInterrupt();
654 
655 	if (CheckProcSignal(PROCSIG_WALSND_INIT_STOPPING))
656 		HandleWalSndInitStopping();
657 
658 	if (CheckProcSignal(PROCSIG_BARRIER))
659 		HandleProcSignalBarrierInterrupt();
660 
661 	if (CheckProcSignal(PROCSIG_LOG_MEMORY_CONTEXT))
662 		HandleLogMemoryContextInterrupt();
663 
664 	if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_DATABASE))
665 		RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_DATABASE);
666 
667 	if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_TABLESPACE))
668 		RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_TABLESPACE);
669 
670 	if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_LOCK))
671 		RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_LOCK);
672 
673 	if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_SNAPSHOT))
674 		RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_SNAPSHOT);
675 
676 	if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK))
677 		RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_STARTUP_DEADLOCK);
678 
679 	if (CheckProcSignal(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN))
680 		RecoveryConflictInterrupt(PROCSIG_RECOVERY_CONFLICT_BUFFERPIN);
681 
682 	SetLatch(MyLatch);
683 
684 	errno = save_errno;
685 }
686