Skip to content

Commit ef848f4

Browse files
committed
Use standard SIGTERM signal handler die() in test_shm_mq worker.
Previously test_shm_mq worker used the stripped-down version of die() as the SIGTERM signal handler. This commit makes it use die(), instead, to simplify the code. In terms of the code, the difference between die() and the stripped-down version previously used is whether the signal handler directly may call ProcessInterrupts() or not. But this difference doesn't exist in a background worker because, in bgworker, DoingCommandRead flag will never be true and die() will never call ProcessInterrupts() directly. Therefore test_shm_mq worker can safely use die(), like other bgworker proceses (e.g., logical replication apply launcher or autoprewarm worker) currently do. Thanks to Craig Ringer for the report and investigation of the issue. Author: Bharath Rupireddy Reviewed-by: Fujii Masao Discussion: https://postgr.es/m/CAGRY4nxsAe_1k_9g5b47orA0S011iBoHsXHFMH7cg7HV0O1bwQ@mail.gmail.com
1 parent 2a08477 commit ef848f4

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

src/test/modules/test_shm_mq/worker.c

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
#include "storage/procarray.h"
2525
#include "storage/shm_mq.h"
2626
#include "storage/shm_toc.h"
27+
#include "tcop/tcopprot.h"
2728

2829
#include "test_shm_mq.h"
2930

30-
static void handle_sigterm(SIGNAL_ARGS);
3131
static void attach_to_queues(dsm_segment *seg, shm_toc *toc,
3232
int myworkernumber, shm_mq_handle **inqhp,
3333
shm_mq_handle **outqhp);
@@ -58,10 +58,9 @@ test_shm_mq_main(Datum main_arg)
5858
* Establish signal handlers.
5959
*
6060
* We want CHECK_FOR_INTERRUPTS() to kill off this worker process just as
61-
* it would a normal user backend. To make that happen, we establish a
62-
* signal handler that is a stripped-down version of die().
61+
* it would a normal user backend. To make that happen, we use die().
6362
*/
64-
pqsignal(SIGTERM, handle_sigterm);
63+
pqsignal(SIGTERM, die);
6564
BackgroundWorkerUnblockSignals();
6665

6766
/*
@@ -196,24 +195,3 @@ copy_messages(shm_mq_handle *inqh, shm_mq_handle *outqh)
196195
break;
197196
}
198197
}
199-
200-
/*
201-
* When we receive a SIGTERM, we set InterruptPending and ProcDiePending just
202-
* like a normal backend. The next CHECK_FOR_INTERRUPTS() will do the right
203-
* thing.
204-
*/
205-
static void
206-
handle_sigterm(SIGNAL_ARGS)
207-
{
208-
int save_errno = errno;
209-
210-
SetLatch(MyLatch);
211-
212-
if (!proc_exit_inprogress)
213-
{
214-
InterruptPending = true;
215-
ProcDiePending = true;
216-
}
217-
218-
errno = save_errno;
219-
}

0 commit comments

Comments
 (0)