|
35 | 35 | #include "miscadmin.h"
|
36 | 36 | #include "pgstat.h"
|
37 | 37 | #include "postmaster/bgworker.h"
|
| 38 | +#include "postmaster/interrupt.h" |
38 | 39 | #include "storage/buf_internals.h"
|
39 | 40 | #include "storage/dsm.h"
|
40 | 41 | #include "storage/ipc.h"
|
@@ -94,12 +95,6 @@ static void apw_start_database_worker(void);
|
94 | 95 | static bool apw_init_shmem(void);
|
95 | 96 | static void apw_detach_shmem(int code, Datum arg);
|
96 | 97 | static int apw_compare_blockinfo(const void *p, const void *q);
|
97 |
| -static void apw_sigterm_handler(SIGNAL_ARGS); |
98 |
| -static void apw_sighup_handler(SIGNAL_ARGS); |
99 |
| - |
100 |
| -/* Flags set by signal handlers */ |
101 |
| -static volatile sig_atomic_t got_sigterm = false; |
102 |
| -static volatile sig_atomic_t got_sighup = false; |
103 | 98 |
|
104 | 99 | /* Pointer to shared-memory state. */
|
105 | 100 | static AutoPrewarmSharedState *apw_state = NULL;
|
@@ -161,8 +156,8 @@ autoprewarm_main(Datum main_arg)
|
161 | 156 | TimestampTz last_dump_time = 0;
|
162 | 157 |
|
163 | 158 | /* Establish signal handlers; once that's done, unblock signals. */
|
164 |
| - pqsignal(SIGTERM, apw_sigterm_handler); |
165 |
| - pqsignal(SIGHUP, apw_sighup_handler); |
| 159 | + pqsignal(SIGTERM, SignalHandlerForShutdownRequest); |
| 160 | + pqsignal(SIGHUP, SignalHandlerForConfigReload); |
166 | 161 | pqsignal(SIGUSR1, procsignal_sigusr1_handler);
|
167 | 162 | BackgroundWorkerUnblockSignals();
|
168 | 163 |
|
@@ -206,19 +201,19 @@ autoprewarm_main(Datum main_arg)
|
206 | 201 | }
|
207 | 202 |
|
208 | 203 | /* Periodically dump buffers until terminated. */
|
209 |
| - while (!got_sigterm) |
| 204 | + while (!ShutdownRequestPending) |
210 | 205 | {
|
211 | 206 | /* In case of a SIGHUP, just reload the configuration. */
|
212 |
| - if (got_sighup) |
| 207 | + if (ConfigReloadPending) |
213 | 208 | {
|
214 |
| - got_sighup = false; |
| 209 | + ConfigReloadPending = false; |
215 | 210 | ProcessConfigFile(PGC_SIGHUP);
|
216 | 211 | }
|
217 | 212 |
|
218 | 213 | if (autoprewarm_interval <= 0)
|
219 | 214 | {
|
220 | 215 | /* We're only dumping at shutdown, so just wait forever. */
|
221 |
| - (void) WaitLatch(&MyProc->procLatch, |
| 216 | + (void) WaitLatch(MyLatch, |
222 | 217 | WL_LATCH_SET | WL_EXIT_ON_PM_DEATH,
|
223 | 218 | -1L,
|
224 | 219 | PG_WAIT_EXTENSION);
|
@@ -247,14 +242,14 @@ autoprewarm_main(Datum main_arg)
|
247 | 242 | }
|
248 | 243 |
|
249 | 244 | /* Sleep until the next dump time. */
|
250 |
| - (void) WaitLatch(&MyProc->procLatch, |
| 245 | + (void) WaitLatch(MyLatch, |
251 | 246 | WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH,
|
252 | 247 | delay_in_ms,
|
253 | 248 | PG_WAIT_EXTENSION);
|
254 | 249 | }
|
255 | 250 |
|
256 | 251 | /* Reset the latch, loop. */
|
257 |
| - ResetLatch(&MyProc->procLatch); |
| 252 | + ResetLatch(MyLatch); |
258 | 253 | }
|
259 | 254 |
|
260 | 255 | /*
|
@@ -895,35 +890,3 @@ apw_compare_blockinfo(const void *p, const void *q)
|
895 | 890 |
|
896 | 891 | return 0;
|
897 | 892 | }
|
898 |
| - |
899 |
| -/* |
900 |
| - * Signal handler for SIGTERM |
901 |
| - */ |
902 |
| -static void |
903 |
| -apw_sigterm_handler(SIGNAL_ARGS) |
904 |
| -{ |
905 |
| - int save_errno = errno; |
906 |
| - |
907 |
| - got_sigterm = true; |
908 |
| - |
909 |
| - if (MyProc) |
910 |
| - SetLatch(&MyProc->procLatch); |
911 |
| - |
912 |
| - errno = save_errno; |
913 |
| -} |
914 |
| - |
915 |
| -/* |
916 |
| - * Signal handler for SIGHUP |
917 |
| - */ |
918 |
| -static void |
919 |
| -apw_sighup_handler(SIGNAL_ARGS) |
920 |
| -{ |
921 |
| - int save_errno = errno; |
922 |
| - |
923 |
| - got_sighup = true; |
924 |
| - |
925 |
| - if (MyProc) |
926 |
| - SetLatch(&MyProc->procLatch); |
927 |
| - |
928 |
| - errno = save_errno; |
929 |
| -} |
0 commit comments