public inbox for [email protected]
help / color / mirror / Atom feedFrom: Bharath Rupireddy <[email protected]>
To: Fujii Masao <[email protected]>
Cc: Kyotaro Horiguchi <[email protected]>
Cc: PostgreSQL-development <[email protected]>
Subject: Re: Use standard SIGHUP and SIGTERM handlers in autoprewarm module
Date: Tue, 10 Nov 2020 18:41:12 +0530
Message-ID: <CALj2ACXDEZhAFOTDcqO9cFSRvrFLyYOnPKrcA1UG4uZn9hUAVg@mail.gmail.com> (raw)
In-Reply-To: <CALj2ACXPEW6wpx+-s5dqcDV2Y+G0U-wu79ZHr7mPRF8G_YwB-Q@mail.gmail.com>
References: <[email protected]>
<[email protected]>
<CALj2ACWz1R+gRt2zJCSsWZeCgQhnM6-E-4XFotqqUwbyYk7ZEA@mail.gmail.com>
<[email protected]>
<[email protected]>
<CALj2ACXPEW6wpx+-s5dqcDV2Y+G0U-wu79ZHr7mPRF8G_YwB-Q@mail.gmail.com>
Hi,
Attaching a patch that replaces custom signal handlers for SIGHUP and
SIGTERM in worker_spi.c.
Thoughts?
With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com
Attachments:
[application/x-patch] v1-0001-Use-standard-SIGHUP-SIGTERM-handlers-in-worker_sp.patch (2.8K, ../CALj2ACXDEZhAFOTDcqO9cFSRvrFLyYOnPKrcA1UG4uZn9hUAVg@mail.gmail.com/2-v1-0001-Use-standard-SIGHUP-SIGTERM-handlers-in-worker_sp.patch)
download | inline diff:
From a212163b64bc3ab4b8d4493e6d53f32979e3e9bf Mon Sep 17 00:00:00 2001
From: Bharath Rupireddy <[email protected]>
Date: Tue, 10 Nov 2020 18:27:00 +0530
Subject: [PATCH v1] Use-standard-SIGHUP-SIGTERM-handlers-in-worker_spi.c
---
src/test/modules/worker_spi/worker_spi.c | 47 +++---------------------
1 file changed, 6 insertions(+), 41 deletions(-)
diff --git a/src/test/modules/worker_spi/worker_spi.c b/src/test/modules/worker_spi/worker_spi.c
index 258237f9bf..5598d2e850 100644
--- a/src/test/modules/worker_spi/worker_spi.c
+++ b/src/test/modules/worker_spi/worker_spi.c
@@ -25,6 +25,7 @@
/* These are always necessary for a bgworker */
#include "miscadmin.h"
#include "postmaster/bgworker.h"
+#include "postmaster/interrupt.h"
#include "storage/ipc.h"
#include "storage/latch.h"
#include "storage/lwlock.h"
@@ -48,10 +49,6 @@ PG_FUNCTION_INFO_V1(worker_spi_launch);
void _PG_init(void);
void worker_spi_main(Datum) pg_attribute_noreturn();
-/* flags set by signal handlers */
-static volatile sig_atomic_t got_sighup = false;
-static volatile sig_atomic_t got_sigterm = false;
-
/* GUC variables */
static int worker_spi_naptime = 10;
static int worker_spi_total_workers = 2;
@@ -64,38 +61,6 @@ typedef struct worktable
const char *name;
} worktable;
-/*
- * Signal handler for SIGTERM
- * Set a flag to let the main loop to terminate, and set our latch to wake
- * it up.
- */
-static void
-worker_spi_sigterm(SIGNAL_ARGS)
-{
- int save_errno = errno;
-
- got_sigterm = true;
- SetLatch(MyLatch);
-
- errno = save_errno;
-}
-
-/*
- * Signal handler for SIGHUP
- * Set a flag to tell the main loop to reread the config file, and set
- * our latch to wake it up.
- */
-static void
-worker_spi_sighup(SIGNAL_ARGS)
-{
- int save_errno = errno;
-
- got_sighup = true;
- SetLatch(MyLatch);
-
- errno = save_errno;
-}
-
/*
* Initialize workspace for a worker process: create the schema if it doesn't
* already exist.
@@ -179,8 +144,8 @@ worker_spi_main(Datum main_arg)
table->name = pstrdup("counted");
/* Establish signal handlers before unblocking signals. */
- pqsignal(SIGHUP, worker_spi_sighup);
- pqsignal(SIGTERM, worker_spi_sigterm);
+ pqsignal(SIGHUP, SignalHandlerForConfigReload);
+ pqsignal(SIGTERM, SignalHandlerForShutdownRequest);
/* We're now ready to receive signals */
BackgroundWorkerUnblockSignals();
@@ -221,7 +186,7 @@ worker_spi_main(Datum main_arg)
/*
* Main loop: do this until the SIGTERM handler tells us to terminate
*/
- while (!got_sigterm)
+ while (!ShutdownRequestPending)
{
int ret;
@@ -242,9 +207,9 @@ worker_spi_main(Datum main_arg)
/*
* In case of a SIGHUP, just reload the configuration.
*/
- if (got_sighup)
+ if (ConfigReloadPending)
{
- got_sighup = false;
+ ConfigReloadPending = false;
ProcessConfigFile(PGC_SIGHUP);
}
--
2.25.1
view thread (38+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Use standard SIGHUP and SIGTERM handlers in autoprewarm module
In-Reply-To: <CALj2ACXDEZhAFOTDcqO9cFSRvrFLyYOnPKrcA1UG4uZn9hUAVg@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox