Commit ef848f4a authored by Fujii Masao's avatar Fujii Masao

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
parent 2a084772
...@@ -24,10 +24,10 @@ ...@@ -24,10 +24,10 @@
#include "storage/procarray.h" #include "storage/procarray.h"
#include "storage/shm_mq.h" #include "storage/shm_mq.h"
#include "storage/shm_toc.h" #include "storage/shm_toc.h"
#include "tcop/tcopprot.h"
#include "test_shm_mq.h" #include "test_shm_mq.h"
static void handle_sigterm(SIGNAL_ARGS);
static void attach_to_queues(dsm_segment *seg, shm_toc *toc, static void attach_to_queues(dsm_segment *seg, shm_toc *toc,
int myworkernumber, shm_mq_handle **inqhp, int myworkernumber, shm_mq_handle **inqhp,
shm_mq_handle **outqhp); shm_mq_handle **outqhp);
...@@ -58,10 +58,9 @@ test_shm_mq_main(Datum main_arg) ...@@ -58,10 +58,9 @@ test_shm_mq_main(Datum main_arg)
* Establish signal handlers. * Establish signal handlers.
* *
* We want CHECK_FOR_INTERRUPTS() to kill off this worker process just as * We want CHECK_FOR_INTERRUPTS() to kill off this worker process just as
* it would a normal user backend. To make that happen, we establish a * it would a normal user backend. To make that happen, we use die().
* signal handler that is a stripped-down version of die().
*/ */
pqsignal(SIGTERM, handle_sigterm); pqsignal(SIGTERM, die);
BackgroundWorkerUnblockSignals(); BackgroundWorkerUnblockSignals();
/* /*
...@@ -196,24 +195,3 @@ copy_messages(shm_mq_handle *inqh, shm_mq_handle *outqh) ...@@ -196,24 +195,3 @@ copy_messages(shm_mq_handle *inqh, shm_mq_handle *outqh)
break; break;
} }
} }
/*
* When we receive a SIGTERM, we set InterruptPending and ProcDiePending just
* like a normal backend. The next CHECK_FOR_INTERRUPTS() will do the right
* thing.
*/
static void
handle_sigterm(SIGNAL_ARGS)
{
int save_errno = errno;
SetLatch(MyLatch);
if (!proc_exit_inprogress)
{
InterruptPending = true;
ProcDiePending = true;
}
errno = save_errno;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment