Skip to content

Commit 1e53fe0

Browse files
committed
Use PostgresSigHupHandler in more places.
There seems to be no reason for every background process to have its own flag indicating that a config-file reload is needed. Instead, let's just use ConfigFilePending for that purpose everywhere. Patch by me, reviewed by Andres Freund and Daniel Gustafsson. Discussion: http://postgr.es/m/CA+TgmoZwDk=BguVDVa+qdA6SBKef=PKbaKDQALTC_9qoz1mJqg@mail.gmail.com
1 parent 5910d6c commit 1e53fe0

File tree

8 files changed

+37
-156
lines changed

8 files changed

+37
-156
lines changed

src/backend/postmaster/autovacuum.c

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ static bool am_autovacuum_launcher = false;
138138
static bool am_autovacuum_worker = false;
139139

140140
/* Flags set by signal handlers */
141-
static volatile sig_atomic_t got_SIGHUP = false;
142141
static volatile sig_atomic_t got_SIGUSR2 = false;
143142
static volatile sig_atomic_t got_SIGTERM = false;
144143

@@ -344,7 +343,6 @@ static void perform_work_item(AutoVacuumWorkItem *workitem);
344343
static void autovac_report_activity(autovac_table *tab);
345344
static void autovac_report_workitem(AutoVacuumWorkItem *workitem,
346345
const char *nspname, const char *relname);
347-
static void av_sighup_handler(SIGNAL_ARGS);
348346
static void avl_sigusr2_handler(SIGNAL_ARGS);
349347
static void avl_sigterm_handler(SIGNAL_ARGS);
350348
static void autovac_refresh_stats(void);
@@ -452,7 +450,7 @@ AutoVacLauncherMain(int argc, char *argv[])
452450
* backend, so we use the same signal handling. See equivalent code in
453451
* tcop/postgres.c.
454452
*/
455-
pqsignal(SIGHUP, av_sighup_handler);
453+
pqsignal(SIGHUP, PostgresSigHupHandler);
456454
pqsignal(SIGINT, StatementCancelHandler);
457455
pqsignal(SIGTERM, avl_sigterm_handler);
458456

@@ -805,9 +803,9 @@ HandleAutoVacLauncherInterrupts(void)
805803
if (got_SIGTERM)
806804
AutoVacLauncherShutdown();
807805

808-
if (got_SIGHUP)
806+
if (ConfigReloadPending)
809807
{
810-
got_SIGHUP = false;
808+
ConfigReloadPending = false;
811809
ProcessConfigFile(PGC_SIGHUP);
812810

813811
/* shutdown requested in config file? */
@@ -1405,18 +1403,6 @@ AutoVacWorkerFailed(void)
14051403
AutoVacuumShmem->av_signal[AutoVacForkFailed] = true;
14061404
}
14071405

1408-
/* SIGHUP: set flag to re-read config file at next convenient time */
1409-
static void
1410-
av_sighup_handler(SIGNAL_ARGS)
1411-
{
1412-
int save_errno = errno;
1413-
1414-
got_SIGHUP = true;
1415-
SetLatch(MyLatch);
1416-
1417-
errno = save_errno;
1418-
}
1419-
14201406
/* SIGUSR2: a worker is up and running, or just finished, or failed to fork */
14211407
static void
14221408
avl_sigusr2_handler(SIGNAL_ARGS)
@@ -1539,7 +1525,7 @@ AutoVacWorkerMain(int argc, char *argv[])
15391525
* backend, so we use the same signal handling. See equivalent code in
15401526
* tcop/postgres.c.
15411527
*/
1542-
pqsignal(SIGHUP, av_sighup_handler);
1528+
pqsignal(SIGHUP, PostgresSigHupHandler);
15431529

15441530
/*
15451531
* SIGINT is used to signal canceling the current table's vacuum; SIGTERM
@@ -2332,9 +2318,9 @@ do_autovacuum(void)
23322318
/*
23332319
* Check for config changes before processing each collected table.
23342320
*/
2335-
if (got_SIGHUP)
2321+
if (ConfigReloadPending)
23362322
{
2337-
got_SIGHUP = false;
2323+
ConfigReloadPending = false;
23382324
ProcessConfigFile(PGC_SIGHUP);
23392325

23402326
/*
@@ -2580,9 +2566,9 @@ do_autovacuum(void)
25802566
* Check for config changes before acquiring lock for further jobs.
25812567
*/
25822568
CHECK_FOR_INTERRUPTS();
2583-
if (got_SIGHUP)
2569+
if (ConfigReloadPending)
25842570
{
2585-
got_SIGHUP = false;
2571+
ConfigReloadPending = false;
25862572
ProcessConfigFile(PGC_SIGHUP);
25872573
}
25882574

src/backend/postmaster/bgwriter.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,13 @@ static XLogRecPtr last_snapshot_lsn = InvalidXLogRecPtr;
8989
/*
9090
* Flags set by interrupt handlers for later service in the main loop.
9191
*/
92-
static volatile sig_atomic_t got_SIGHUP = false;
9392
static volatile sig_atomic_t shutdown_requested = false;
9493

9594
static void HandleBackgroundWriterInterrupts(void);
9695

9796
/* Signal handlers */
9897

9998
static void bg_quickdie(SIGNAL_ARGS);
100-
static void BgSigHupHandler(SIGNAL_ARGS);
10199
static void ReqShutdownHandler(SIGNAL_ARGS);
102100

103101

@@ -118,7 +116,7 @@ BackgroundWriterMain(void)
118116
/*
119117
* Properly accept or ignore signals that might be sent to us.
120118
*/
121-
pqsignal(SIGHUP, BgSigHupHandler); /* set flag to read config file */
119+
pqsignal(SIGHUP, PostgresSigHupHandler); /* set flag to read config file */
122120
pqsignal(SIGINT, SIG_IGN);
123121
pqsignal(SIGTERM, ReqShutdownHandler); /* shutdown */
124122
pqsignal(SIGQUIT, bg_quickdie); /* hard crash time */
@@ -363,9 +361,9 @@ BackgroundWriterMain(void)
363361
static void
364362
HandleBackgroundWriterInterrupts(void)
365363
{
366-
if (got_SIGHUP)
364+
if (ConfigReloadPending)
367365
{
368-
got_SIGHUP = false;
366+
ConfigReloadPending = false;
369367
ProcessConfigFile(PGC_SIGHUP);
370368
}
371369

@@ -413,18 +411,6 @@ bg_quickdie(SIGNAL_ARGS)
413411
_exit(2);
414412
}
415413

416-
/* SIGHUP: set flag to re-read config file at next convenient time */
417-
static void
418-
BgSigHupHandler(SIGNAL_ARGS)
419-
{
420-
int save_errno = errno;
421-
422-
got_SIGHUP = true;
423-
SetLatch(MyLatch);
424-
425-
errno = save_errno;
426-
}
427-
428414
/* SIGTERM: set flag to shutdown and exit */
429415
static void
430416
ReqShutdownHandler(SIGNAL_ARGS)

src/backend/postmaster/checkpointer.c

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ double CheckPointCompletionTarget = 0.5;
151151
/*
152152
* Flags set by interrupt handlers for later service in the main loop.
153153
*/
154-
static volatile sig_atomic_t got_SIGHUP = false;
155154
static volatile sig_atomic_t shutdown_requested = false;
156155

157156
/*
@@ -179,7 +178,6 @@ static void UpdateSharedMemoryConfig(void);
179178
/* Signal handlers */
180179

181180
static void chkpt_quickdie(SIGNAL_ARGS);
182-
static void ChkptSigHupHandler(SIGNAL_ARGS);
183181
static void ReqCheckpointHandler(SIGNAL_ARGS);
184182
static void ReqShutdownHandler(SIGNAL_ARGS);
185183

@@ -206,7 +204,7 @@ CheckpointerMain(void)
206204
* want to wait for the backends to exit, whereupon the postmaster will
207205
* tell us it's okay to shut down (via SIGUSR2).
208206
*/
209-
pqsignal(SIGHUP, ChkptSigHupHandler); /* set flag to read config file */
207+
pqsignal(SIGHUP, PostgresSigHupHandler); /* set flag to read config file */
210208
pqsignal(SIGINT, ReqCheckpointHandler); /* request checkpoint */
211209
pqsignal(SIGTERM, SIG_IGN); /* ignore SIGTERM */
212210
pqsignal(SIGQUIT, chkpt_quickdie); /* hard crash time */
@@ -535,9 +533,9 @@ CheckpointerMain(void)
535533
static void
536534
HandleCheckpointerInterrupts(void)
537535
{
538-
if (got_SIGHUP)
536+
if (ConfigReloadPending)
539537
{
540-
got_SIGHUP = false;
538+
ConfigReloadPending = false;
541539
ProcessConfigFile(PGC_SIGHUP);
542540

543541
/*
@@ -685,9 +683,9 @@ CheckpointWriteDelay(int flags, double progress)
685683
!ImmediateCheckpointRequested() &&
686684
IsCheckpointOnSchedule(progress))
687685
{
688-
if (got_SIGHUP)
686+
if (ConfigReloadPending)
689687
{
690-
got_SIGHUP = false;
688+
ConfigReloadPending = false;
691689
ProcessConfigFile(PGC_SIGHUP);
692690
/* update shmem copies of config variables */
693691
UpdateSharedMemoryConfig();
@@ -835,18 +833,6 @@ chkpt_quickdie(SIGNAL_ARGS)
835833
_exit(2);
836834
}
837835

838-
/* SIGHUP: set flag to re-read config file at next convenient time */
839-
static void
840-
ChkptSigHupHandler(SIGNAL_ARGS)
841-
{
842-
int save_errno = errno;
843-
844-
got_SIGHUP = true;
845-
SetLatch(MyLatch);
846-
847-
errno = save_errno;
848-
}
849-
850836
/* SIGINT: set flag to run a normal checkpoint right away */
851837
static void
852838
ReqCheckpointHandler(SIGNAL_ARGS)

src/backend/postmaster/pgarch.c

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ static time_t last_sigterm_time = 0;
8383
/*
8484
* Flags set by interrupt handlers for later service in the main loop.
8585
*/
86-
static volatile sig_atomic_t got_SIGHUP = false;
8786
static volatile sig_atomic_t got_SIGTERM = false;
8887
static volatile sig_atomic_t wakened = false;
8988
static volatile sig_atomic_t ready_to_stop = false;
@@ -98,7 +97,6 @@ static pid_t pgarch_forkexec(void);
9897

9998
NON_EXEC_STATIC void PgArchiverMain(int argc, char *argv[]) pg_attribute_noreturn();
10099
static void pgarch_exit(SIGNAL_ARGS);
101-
static void ArchSigHupHandler(SIGNAL_ARGS);
102100
static void ArchSigTermHandler(SIGNAL_ARGS);
103101
static void pgarch_waken(SIGNAL_ARGS);
104102
static void pgarch_waken_stop(SIGNAL_ARGS);
@@ -229,7 +227,7 @@ PgArchiverMain(int argc, char *argv[])
229227
* Ignore all signals usually bound to some action in the postmaster,
230228
* except for SIGHUP, SIGTERM, SIGUSR1, SIGUSR2, and SIGQUIT.
231229
*/
232-
pqsignal(SIGHUP, ArchSigHupHandler);
230+
pqsignal(SIGHUP, PostgresSigHupHandler);
233231
pqsignal(SIGINT, SIG_IGN);
234232
pqsignal(SIGTERM, ArchSigTermHandler);
235233
pqsignal(SIGQUIT, pgarch_exit);
@@ -259,19 +257,6 @@ pgarch_exit(SIGNAL_ARGS)
259257
exit(1);
260258
}
261259

262-
/* SIGHUP signal handler for archiver process */
263-
static void
264-
ArchSigHupHandler(SIGNAL_ARGS)
265-
{
266-
int save_errno = errno;
267-
268-
/* set flag to re-read config file at next convenient time */
269-
got_SIGHUP = true;
270-
SetLatch(MyLatch);
271-
272-
errno = save_errno;
273-
}
274-
275260
/* SIGTERM signal handler for archiver process */
276261
static void
277262
ArchSigTermHandler(SIGNAL_ARGS)
@@ -348,9 +333,9 @@ pgarch_MainLoop(void)
348333
time_to_stop = ready_to_stop;
349334

350335
/* Check for config update */
351-
if (got_SIGHUP)
336+
if (ConfigReloadPending)
352337
{
353-
got_SIGHUP = false;
338+
ConfigReloadPending = false;
354339
ProcessConfigFile(PGC_SIGHUP);
355340
}
356341

@@ -457,9 +442,9 @@ pgarch_ArchiverCopyLoop(void)
457442
* setting for archive_command as soon as possible, even if there
458443
* is a backlog of files to be archived.
459444
*/
460-
if (got_SIGHUP)
445+
if (ConfigReloadPending)
461446
{
462-
got_SIGHUP = false;
447+
ConfigReloadPending = false;
463448
ProcessConfigFile(PGC_SIGHUP);
464449
}
465450

src/backend/postmaster/pgstat.c

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ static List *pending_write_requests = NIL;
264264

265265
/* Signal handler flags */
266266
static volatile bool need_exit = false;
267-
static volatile bool got_SIGHUP = false;
268267

269268
/*
270269
* Total time charged to functions so far in the current backend.
@@ -285,7 +284,6 @@ static pid_t pgstat_forkexec(void);
285284
NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]) pg_attribute_noreturn();
286285
static void pgstat_exit(SIGNAL_ARGS);
287286
static void pgstat_beshutdown_hook(int code, Datum arg);
288-
static void pgstat_sighup_handler(SIGNAL_ARGS);
289287

290288
static PgStat_StatDBEntry *pgstat_get_db_entry(Oid databaseid, bool create);
291289
static PgStat_StatTabEntry *pgstat_get_tab_entry(PgStat_StatDBEntry *dbentry,
@@ -4434,7 +4432,7 @@ PgstatCollectorMain(int argc, char *argv[])
44344432
* except SIGHUP and SIGQUIT. Note we don't need a SIGUSR1 handler to
44354433
* support latch operations, because we only use a local latch.
44364434
*/
4437-
pqsignal(SIGHUP, pgstat_sighup_handler);
4435+
pqsignal(SIGHUP, PostgresSigHupHandler);
44384436
pqsignal(SIGINT, SIG_IGN);
44394437
pqsignal(SIGTERM, SIG_IGN);
44404438
pqsignal(SIGQUIT, pgstat_exit);
@@ -4466,10 +4464,10 @@ PgstatCollectorMain(int argc, char *argv[])
44664464
* message. (This effectively means that if backends are sending us stuff
44674465
* like mad, we won't notice postmaster death until things slack off a
44684466
* bit; which seems fine.) To do that, we have an inner loop that
4469-
* iterates as long as recv() succeeds. We do recognize got_SIGHUP inside
4470-
* the inner loop, which means that such interrupts will get serviced but
4471-
* the latch won't get cleared until next time there is a break in the
4472-
* action.
4467+
* iterates as long as recv() succeeds. We do check ConfigReloadPending
4468+
* inside the inner loop, which means that such interrupts will get
4469+
* serviced but the latch won't get cleared until next time there is a
4470+
* break in the action.
44734471
*/
44744472
for (;;)
44754473
{
@@ -4491,9 +4489,9 @@ PgstatCollectorMain(int argc, char *argv[])
44914489
/*
44924490
* Reload configuration if we got SIGHUP from the postmaster.
44934491
*/
4494-
if (got_SIGHUP)
4492+
if (ConfigReloadPending)
44954493
{
4496-
got_SIGHUP = false;
4494+
ConfigReloadPending = false;
44974495
ProcessConfigFile(PGC_SIGHUP);
44984496
}
44994497

@@ -4691,18 +4689,6 @@ pgstat_exit(SIGNAL_ARGS)
46914689
errno = save_errno;
46924690
}
46934691

4694-
/* SIGHUP handler for collector process */
4695-
static void
4696-
pgstat_sighup_handler(SIGNAL_ARGS)
4697-
{
4698-
int save_errno = errno;
4699-
4700-
got_SIGHUP = true;
4701-
SetLatch(MyLatch);
4702-
4703-
errno = save_errno;
4704-
}
4705-
47064692
/*
47074693
* Subroutine to clear stats in a database entry
47084694
*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy