mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Partially deduplicate interrupt handling for background processes.
Where possible, share signal handler code and main loop interrupt checking. This saves quite a bit of code and should simplify maintenance, too. This commit intends not to change the way anything works, even though that might allow more code to be unified. It does unify a bunch of individual variables into a ShutdownRequestPending flag that has is now used by a bunch of different process types, though. Patch by me, reviewed by Andres Freund and Daniel Gustafsson. Discussion: http://postgr.es/m/CA+TgmoZwDk=BguVDVa+qdA6SBKef=PKbaKDQALTC_9qoz1mJqg@mail.gmail.com
This commit is contained in:
@ -19,13 +19,11 @@
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "access/xlog.h"
|
||||
#include "libpq/pqsignal.h"
|
||||
#include "miscadmin.h"
|
||||
#include "pgstat.h"
|
||||
#include "postmaster/interrupt.h"
|
||||
#include "postmaster/startup.h"
|
||||
#include "storage/ipc.h"
|
||||
#include "storage/latch.h"
|
||||
@ -50,7 +48,6 @@ static volatile sig_atomic_t promote_triggered = false;
|
||||
static volatile sig_atomic_t in_restore_command = false;
|
||||
|
||||
/* Signal handlers */
|
||||
static void startupproc_quickdie(SIGNAL_ARGS);
|
||||
static void StartupProcTriggerHandler(SIGNAL_ARGS);
|
||||
static void StartupProcSigHupHandler(SIGNAL_ARGS);
|
||||
|
||||
@ -60,33 +57,6 @@ static void StartupProcSigHupHandler(SIGNAL_ARGS);
|
||||
* --------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* startupproc_quickdie() occurs when signalled SIGQUIT by the postmaster.
|
||||
*
|
||||
* Some backend has bought the farm,
|
||||
* so we need to stop what we're doing and exit.
|
||||
*/
|
||||
static void
|
||||
startupproc_quickdie(SIGNAL_ARGS)
|
||||
{
|
||||
/*
|
||||
* We DO NOT want to run proc_exit() or atexit() callbacks -- we're here
|
||||
* because shared memory may be corrupted, so we don't want to try to
|
||||
* clean up our transaction. Just nail the windows shut and get out of
|
||||
* town. The callbacks wouldn't be safe to run from a signal handler,
|
||||
* anyway.
|
||||
*
|
||||
* Note we do _exit(2) not _exit(0). This is to force the postmaster into
|
||||
* a system reset cycle if someone sends a manual SIGQUIT to a random
|
||||
* backend. This is necessary precisely because we don't clean up our
|
||||
* shared memory state. (The "dead man switch" mechanism in pmsignal.c
|
||||
* should ensure the postmaster sees this as a crash, too, but no harm in
|
||||
* being doubly sure.)
|
||||
*/
|
||||
_exit(2);
|
||||
}
|
||||
|
||||
|
||||
/* SIGUSR2: set flag to finish recovery */
|
||||
static void
|
||||
StartupProcTriggerHandler(SIGNAL_ARGS)
|
||||
@ -167,7 +137,7 @@ StartupProcessMain(void)
|
||||
pqsignal(SIGHUP, StartupProcSigHupHandler); /* reload config file */
|
||||
pqsignal(SIGINT, SIG_IGN); /* ignore query cancel */
|
||||
pqsignal(SIGTERM, StartupProcShutdownHandler); /* request shutdown */
|
||||
pqsignal(SIGQUIT, startupproc_quickdie); /* hard crash time */
|
||||
pqsignal(SIGQUIT, SignalHandlerForCrashExit);
|
||||
InitializeTimeouts(); /* establishes SIGALRM handler */
|
||||
pqsignal(SIGPIPE, SIG_IGN);
|
||||
pqsignal(SIGUSR1, procsignal_sigusr1_handler);
|
||||
|
Reference in New Issue
Block a user