/* 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"
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;
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.
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, die);
/* We're now ready to receive signals */
BackgroundWorkerUnblockSignals();
table->name);
/*
- * Main loop: do this until the SIGTERM handler tells us to terminate
+ * Main loop: do this until SIGTERM is received and processed by
+ * ProcessInterrupts.
*/
- while (!got_sigterm)
+ for (;;)
{
int ret;
/*
* In case of a SIGHUP, just reload the configuration.
*/
- if (got_sighup)
+ if (ConfigReloadPending)
{
- got_sighup = false;
+ ConfigReloadPending = false;
ProcessConfigFile(PGC_SIGHUP);
}
pgstat_report_activity(STATE_IDLE, NULL);
}
- proc_exit(1);
+ /* Not reachable */
}
/*