Skip to content

Commit 0d3c3aa

Browse files
committed
Use procsignal_sigusr1_handler for auxiliary processes.
AuxiliaryProcessMain does ProcSignalInit, so one might expect that auxiliary processes would need to respond to SendProcSignal, but none of the auxiliary processes do that. Change them to use procsignal_sigusr1_handler instead of their own private handlers so that they do. Besides seeming more correct, this is also less code. It shouldn't make any functional difference right now because, as far as we know, there are no current cases where SendProcSignal targets an auxiliary process, but there are plans to change that in the future. Andres Freund Discussion: http://postgr.es/m/[email protected]
1 parent 9af34f3 commit 0d3c3aa

File tree

5 files changed

+11
-69
lines changed

5 files changed

+11
-69
lines changed

src/backend/postmaster/bgwriter.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "storage/ipc.h"
5252
#include "storage/lwlock.h"
5353
#include "storage/proc.h"
54+
#include "storage/procsignal.h"
5455
#include "storage/shmem.h"
5556
#include "storage/smgr.h"
5657
#include "storage/spin.h"
@@ -96,7 +97,6 @@ static volatile sig_atomic_t shutdown_requested = false;
9697
static void bg_quickdie(SIGNAL_ARGS);
9798
static void BgSigHupHandler(SIGNAL_ARGS);
9899
static void ReqShutdownHandler(SIGNAL_ARGS);
99-
static void bgwriter_sigusr1_handler(SIGNAL_ARGS);
100100

101101

102102
/*
@@ -114,18 +114,15 @@ BackgroundWriterMain(void)
114114
WritebackContext wb_context;
115115

116116
/*
117-
* Properly accept or ignore signals the postmaster might send us.
118-
*
119-
* bgwriter doesn't participate in ProcSignal signalling, but a SIGUSR1
120-
* handler is still needed for latch wakeups.
117+
* Properly accept or ignore signals that might be sent to us.
121118
*/
122119
pqsignal(SIGHUP, BgSigHupHandler); /* set flag to read config file */
123120
pqsignal(SIGINT, SIG_IGN);
124121
pqsignal(SIGTERM, ReqShutdownHandler); /* shutdown */
125122
pqsignal(SIGQUIT, bg_quickdie); /* hard crash time */
126123
pqsignal(SIGALRM, SIG_IGN);
127124
pqsignal(SIGPIPE, SIG_IGN);
128-
pqsignal(SIGUSR1, bgwriter_sigusr1_handler);
125+
pqsignal(SIGUSR1, procsignal_sigusr1_handler);
129126
pqsignal(SIGUSR2, SIG_IGN);
130127

131128
/*
@@ -427,14 +424,3 @@ ReqShutdownHandler(SIGNAL_ARGS)
427424

428425
errno = save_errno;
429426
}
430-
431-
/* SIGUSR1: used for latch wakeups */
432-
static void
433-
bgwriter_sigusr1_handler(SIGNAL_ARGS)
434-
{
435-
int save_errno = errno;
436-
437-
latch_sigusr1_handler();
438-
439-
errno = save_errno;
440-
}

src/backend/postmaster/checkpointer.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "storage/ipc.h"
5555
#include "storage/lwlock.h"
5656
#include "storage/proc.h"
57+
#include "storage/procsignal.h"
5758
#include "storage/shmem.h"
5859
#include "storage/smgr.h"
5960
#include "storage/spin.h"
@@ -179,7 +180,6 @@ static void UpdateSharedMemoryConfig(void);
179180
static void chkpt_quickdie(SIGNAL_ARGS);
180181
static void ChkptSigHupHandler(SIGNAL_ARGS);
181182
static void ReqCheckpointHandler(SIGNAL_ARGS);
182-
static void chkpt_sigusr1_handler(SIGNAL_ARGS);
183183
static void ReqShutdownHandler(SIGNAL_ARGS);
184184

185185

@@ -211,7 +211,7 @@ CheckpointerMain(void)
211211
pqsignal(SIGQUIT, chkpt_quickdie); /* hard crash time */
212212
pqsignal(SIGALRM, SIG_IGN);
213213
pqsignal(SIGPIPE, SIG_IGN);
214-
pqsignal(SIGUSR1, chkpt_sigusr1_handler);
214+
pqsignal(SIGUSR1, procsignal_sigusr1_handler);
215215
pqsignal(SIGUSR2, ReqShutdownHandler); /* request shutdown */
216216

217217
/*
@@ -853,17 +853,6 @@ ReqCheckpointHandler(SIGNAL_ARGS)
853853
errno = save_errno;
854854
}
855855

856-
/* SIGUSR1: used for latch wakeups */
857-
static void
858-
chkpt_sigusr1_handler(SIGNAL_ARGS)
859-
{
860-
int save_errno = errno;
861-
862-
latch_sigusr1_handler();
863-
864-
errno = save_errno;
865-
}
866-
867856
/* SIGUSR2: set flag to run a shutdown checkpoint and exit */
868857
static void
869858
ReqShutdownHandler(SIGNAL_ARGS)

src/backend/postmaster/startup.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "storage/ipc.h"
3131
#include "storage/latch.h"
3232
#include "storage/pmsignal.h"
33+
#include "storage/procsignal.h"
3334
#include "storage/standby.h"
3435
#include "utils/guc.h"
3536
#include "utils/timeout.h"
@@ -50,7 +51,6 @@ static volatile sig_atomic_t in_restore_command = false;
5051

5152
/* Signal handlers */
5253
static void startupproc_quickdie(SIGNAL_ARGS);
53-
static void StartupProcSigUsr1Handler(SIGNAL_ARGS);
5454
static void StartupProcTriggerHandler(SIGNAL_ARGS);
5555
static void StartupProcSigHupHandler(SIGNAL_ARGS);
5656

@@ -87,17 +87,6 @@ startupproc_quickdie(SIGNAL_ARGS)
8787
}
8888

8989

90-
/* SIGUSR1: let latch facility handle the signal */
91-
static void
92-
StartupProcSigUsr1Handler(SIGNAL_ARGS)
93-
{
94-
int save_errno = errno;
95-
96-
latch_sigusr1_handler();
97-
98-
errno = save_errno;
99-
}
100-
10190
/* SIGUSR2: set flag to finish recovery */
10291
static void
10392
StartupProcTriggerHandler(SIGNAL_ARGS)
@@ -181,7 +170,7 @@ StartupProcessMain(void)
181170
pqsignal(SIGQUIT, startupproc_quickdie); /* hard crash time */
182171
InitializeTimeouts(); /* establishes SIGALRM handler */
183172
pqsignal(SIGPIPE, SIG_IGN);
184-
pqsignal(SIGUSR1, StartupProcSigUsr1Handler);
173+
pqsignal(SIGUSR1, procsignal_sigusr1_handler);
185174
pqsignal(SIGUSR2, StartupProcTriggerHandler);
186175

187176
/*

src/backend/postmaster/walwriter.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "storage/ipc.h"
5656
#include "storage/lwlock.h"
5757
#include "storage/proc.h"
58+
#include "storage/procsignal.h"
5859
#include "storage/smgr.h"
5960
#include "utils/guc.h"
6061
#include "utils/hsearch.h"
@@ -86,7 +87,6 @@ static volatile sig_atomic_t shutdown_requested = false;
8687
static void wal_quickdie(SIGNAL_ARGS);
8788
static void WalSigHupHandler(SIGNAL_ARGS);
8889
static void WalShutdownHandler(SIGNAL_ARGS);
89-
static void walwriter_sigusr1_handler(SIGNAL_ARGS);
9090

9191
/*
9292
* Main entry point for walwriter process
@@ -114,7 +114,7 @@ WalWriterMain(void)
114114
pqsignal(SIGQUIT, wal_quickdie); /* hard crash time */
115115
pqsignal(SIGALRM, SIG_IGN);
116116
pqsignal(SIGPIPE, SIG_IGN);
117-
pqsignal(SIGUSR1, walwriter_sigusr1_handler);
117+
pqsignal(SIGUSR1, procsignal_sigusr1_handler);
118118
pqsignal(SIGUSR2, SIG_IGN); /* not used */
119119

120120
/*
@@ -337,14 +337,3 @@ WalShutdownHandler(SIGNAL_ARGS)
337337

338338
errno = save_errno;
339339
}
340-
341-
/* SIGUSR1: used for latch wakeups */
342-
static void
343-
walwriter_sigusr1_handler(SIGNAL_ARGS)
344-
{
345-
int save_errno = errno;
346-
347-
latch_sigusr1_handler();
348-
349-
errno = save_errno;
350-
}

src/backend/replication/walreceiver.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "storage/ipc.h"
6464
#include "storage/pmsignal.h"
6565
#include "storage/procarray.h"
66+
#include "storage/procsignal.h"
6667
#include "utils/builtins.h"
6768
#include "utils/guc.h"
6869
#include "utils/pg_lsn.h"
@@ -125,7 +126,6 @@ static void ProcessWalSndrMessage(XLogRecPtr walEnd, TimestampTz sendTime);
125126

126127
/* Signal handlers */
127128
static void WalRcvSigHupHandler(SIGNAL_ARGS);
128-
static void WalRcvSigUsr1Handler(SIGNAL_ARGS);
129129
static void WalRcvShutdownHandler(SIGNAL_ARGS);
130130
static void WalRcvQuickDieHandler(SIGNAL_ARGS);
131131

@@ -252,7 +252,7 @@ WalReceiverMain(void)
252252
pqsignal(SIGQUIT, WalRcvQuickDieHandler); /* hard crash time */
253253
pqsignal(SIGALRM, SIG_IGN);
254254
pqsignal(SIGPIPE, SIG_IGN);
255-
pqsignal(SIGUSR1, WalRcvSigUsr1Handler);
255+
pqsignal(SIGUSR1, procsignal_sigusr1_handler);
256256
pqsignal(SIGUSR2, SIG_IGN);
257257

258258
/* Reset some signals that are accepted by postmaster but not here */
@@ -766,17 +766,6 @@ WalRcvSigHupHandler(SIGNAL_ARGS)
766766
}
767767

768768

769-
/* SIGUSR1: used by latch mechanism */
770-
static void
771-
WalRcvSigUsr1Handler(SIGNAL_ARGS)
772-
{
773-
int save_errno = errno;
774-
775-
latch_sigusr1_handler();
776-
777-
errno = save_errno;
778-
}
779-
780769
/* SIGTERM: set flag for ProcessWalRcvInterrupts */
781770
static void
782771
WalRcvShutdownHandler(SIGNAL_ARGS)

0 commit comments

Comments
 (0)