Skip to content

Commit 295f9bb

Browse files
committed
Remove bgw_sighup and bgw_sigterm.
Per discussion on pgsql-hackers, these aren't really needed. Interim versions of the background worker patch had the worker starting with signals already unblocked, which would have made this necessary. But the final version does not, so we don't really need it; and it doesn't work well with the new facility for starting dynamic background workers, so just rip it out. Also per discussion on pgsql-hackers, back-patch this change to 9.3. It's best to get the API break out of the way before we do an official release of this facility, to avoid more pain for extension authors later.
1 parent 15b9bdf commit 295f9bb

File tree

4 files changed

+7
-27
lines changed

4 files changed

+7
-27
lines changed

contrib/worker_spi/worker_spi.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ worker_spi_main(void *main_arg)
159159
worktable *table = (worktable *) main_arg;
160160
StringInfoData buf;
161161

162+
/* Establish signal handlers before unblocking signals. */
163+
pqsignal(SIGHUP, worker_spi_sighup);
164+
pqsignal(SIGTERM, worker_spi_sigterm);
165+
162166
/* We're now ready to receive signals */
163167
BackgroundWorkerUnblockSignals();
164168

@@ -328,8 +332,6 @@ _PG_init(void)
328332
worker.bgw_start_time = BgWorkerStart_RecoveryFinished;
329333
worker.bgw_restart_time = BGW_NEVER_RESTART;
330334
worker.bgw_main = worker_spi_main;
331-
worker.bgw_sighup = worker_spi_sighup;
332-
worker.bgw_sigterm = worker_spi_sigterm;
333335

334336
/*
335337
* Now fill in worker-specific data, and do the actual registrations.

doc/src/sgml/bgworker.sgml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
The structure <structname>BackgroundWorker</structname> is defined thus:
3939
<programlisting>
4040
typedef void (*bgworker_main_type)(void *main_arg);
41-
typedef void (*bgworker_sighdlr_type)(SIGNAL_ARGS);
4241
typedef struct BackgroundWorker
4342
{
4443
char *bgw_name;
@@ -47,8 +46,6 @@ typedef struct BackgroundWorker
4746
int bgw_restart_time; /* in seconds, or BGW_NEVER_RESTART */
4847
bgworker_main_type bgw_main;
4948
void *bgw_main_arg;
50-
bgworker_sighdlr_type bgw_sighup;
51-
bgworker_sighdlr_type bgw_sigterm;
5249
} BackgroundWorker;
5350
</programlisting>
5451
</para>
@@ -104,14 +101,6 @@ typedef struct BackgroundWorker
104101
passed at registration time.
105102
</para>
106103

107-
<para>
108-
<structfield>bgw_sighup</structfield> and <structfield>bgw_sigterm</> are
109-
pointers to functions that will be installed as signal handlers for the new
110-
process. If <structfield>bgw_sighup</> is NULL, then <literal>SIG_IGN</>
111-
is used; if <structfield>bgw_sigterm</> is NULL, a handler is installed that
112-
will terminate the process after logging a suitable message.
113-
</para>
114-
115104
<para>Once running, the process can connect to a database by calling
116105
<function>BackgroundWorkerInitializeConnection(<parameter>char *dbname</parameter>, <parameter>char *username</parameter>)</function>.
117106
This allows the process to run transactions and queries using the
@@ -126,7 +115,7 @@ typedef struct BackgroundWorker
126115
<para>
127116
Signals are initially blocked when control reaches the
128117
<structfield>bgw_main</> function, and must be unblocked by it; this is to
129-
allow the process to further customize its signal handlers, if necessary.
118+
allow the process to customize its signal handlers, if necessary.
130119
Signals can be unblocked in the new process by calling
131120
<function>BackgroundWorkerUnblockSignals</> and blocked by calling
132121
<function>BackgroundWorkerBlockSignals</>.

src/backend/postmaster/postmaster.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5434,16 +5434,8 @@ do_start_bgworker(void)
54345434
pqsignal(SIGFPE, SIG_IGN);
54355435
}
54365436

5437-
/* SIGTERM and SIGHUP are configurable */
5438-
if (worker->bgw_sigterm)
5439-
pqsignal(SIGTERM, worker->bgw_sigterm);
5440-
else
5441-
pqsignal(SIGTERM, bgworker_die);
5442-
5443-
if (worker->bgw_sighup)
5444-
pqsignal(SIGHUP, worker->bgw_sighup);
5445-
else
5446-
pqsignal(SIGHUP, SIG_IGN);
5437+
pqsignal(SIGTERM, bgworker_die);
5438+
pqsignal(SIGHUP, SIG_IGN);
54475439

54485440
pqsignal(SIGQUIT, bgworker_quickdie);
54495441
InitializeTimeouts(); /* establishes SIGALRM handler */

src/include/postmaster/bgworker.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353

5454

5555
typedef void (*bgworker_main_type) (void *main_arg);
56-
typedef void (*bgworker_sighdlr_type) (SIGNAL_ARGS);
5756

5857
/*
5958
* Points in time at which a bgworker can request to be started
@@ -76,8 +75,6 @@ typedef struct BackgroundWorker
7675
int bgw_restart_time; /* in seconds, or BGW_NEVER_RESTART */
7776
bgworker_main_type bgw_main;
7877
void *bgw_main_arg;
79-
bgworker_sighdlr_type bgw_sighup;
80-
bgworker_sighdlr_type bgw_sigterm;
8178
} BackgroundWorker;
8279

8380
/* Register a new bgworker */

0 commit comments

Comments
 (0)