worktable *table = (worktable *) main_arg;
StringInfoData buf;
+ /* Establish signal handlers before unblocking signals. */
+ pqsignal(SIGHUP, worker_spi_sighup);
+ pqsignal(SIGTERM, worker_spi_sigterm);
+
/* We're now ready to receive signals */
BackgroundWorkerUnblockSignals();
worker.bgw_start_time = BgWorkerStart_RecoveryFinished;
worker.bgw_restart_time = BGW_NEVER_RESTART;
worker.bgw_main = worker_spi_main;
- worker.bgw_sighup = worker_spi_sighup;
- worker.bgw_sigterm = worker_spi_sigterm;
/*
* Now fill in worker-specific data, and do the actual registrations.
The structure BackgroundWorker is defined thus:
typedef void (*bgworker_main_type)(void *main_arg);
-typedef void (*bgworker_sighdlr_type)(SIGNAL_ARGS);
typedef struct BackgroundWorker
{
char *bgw_name;
int bgw_restart_time; /* in seconds, or BGW_NEVER_RESTART */
bgworker_main_type bgw_main;
void *bgw_main_arg;
- bgworker_sighdlr_type bgw_sighup;
- bgworker_sighdlr_type bgw_sigterm;
} BackgroundWorker;
passed at registration time.
- bgw_sighup and bgw_sigterm> are
- pointers to functions that will be installed as signal handlers for the new
- process. If bgw_sighup> is NULL, then SIG_IGN>
- is used; if bgw_sigterm> is NULL, a handler is installed that
- will terminate the process after logging a suitable message.
-
-
Once running, the process can connect to a database by calling
BackgroundWorkerInitializeConnection(char *dbname, char *username).
This allows the process to run transactions and queries using the
Signals are initially blocked when control reaches the
bgw_main> function, and must be unblocked by it; this is to
- allow the process to further customize its signal handlers, if necessary.
+ allow the process to customize its signal handlers, if necessary.
Signals can be unblocked in the new process by calling
BackgroundWorkerUnblockSignals> and blocked by calling
BackgroundWorkerBlockSignals>.
pqsignal(SIGFPE, SIG_IGN);
}
- /* SIGTERM and SIGHUP are configurable */
- if (worker->bgw_sigterm)
- pqsignal(SIGTERM, worker->bgw_sigterm);
- else
- pqsignal(SIGTERM, bgworker_die);
-
- if (worker->bgw_sighup)
- pqsignal(SIGHUP, worker->bgw_sighup);
- else
- pqsignal(SIGHUP, SIG_IGN);
+ pqsignal(SIGTERM, bgworker_die);
+ pqsignal(SIGHUP, SIG_IGN);
pqsignal(SIGQUIT, bgworker_quickdie);
InitializeTimeouts(); /* establishes SIGALRM handler */
typedef void (*bgworker_main_type) (void *main_arg);
-typedef void (*bgworker_sighdlr_type) (SIGNAL_ARGS);
/*
* Points in time at which a bgworker can request to be started
int bgw_restart_time; /* in seconds, or BGW_NEVER_RESTART */
bgworker_main_type bgw_main;
void *bgw_main_arg;
- bgworker_sighdlr_type bgw_sighup;
- bgworker_sighdlr_type bgw_sigterm;
} BackgroundWorker;
/* Register a new bgworker */