NON_EXEC_STATIC void AutoVacLauncherMain(int argc, char *argv[]) pg_attribute_noreturn();
 
 static Oid do_start_worker(void);
+static void HandleAutoVacLauncherInterrupts(void);
+static void AutoVacLauncherShutdown() pg_attribute_noreturn();
 static void launcher_determine_sleep(bool canlaunch, bool recursing,
                                     struct timeval *nap);
 static void launch_worker(TimestampTz now);
 
        /* if in shutdown mode, no need for anything further; just go away */
        if (got_SIGTERM)
-           goto shutdown;
+           AutoVacLauncherShutdown();
 
        /*
         * Sleep at least 1 second after any error.  We don't want to be
 
        ResetLatch(MyLatch);
 
-       /* Process sinval catchup interrupts that happened while sleeping */
-       ProcessCatchupInterrupt();
-
-       /* the normal shutdown case */
-       if (got_SIGTERM)
-           break;
-
-       if (got_SIGHUP)
-       {
-           got_SIGHUP = false;
-           ProcessConfigFile(PGC_SIGHUP);
-
-           /* shutdown requested in config file? */
-           if (!AutoVacuumingActive())
-               break;
-
-           /* rebalance in case the default cost parameters changed */
-           LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
-           autovac_balance_cost();
-           LWLockRelease(AutovacuumLock);
-
-           /* rebuild the list in case the naptime changed */
-           rebuild_database_list(InvalidOid);
-       }
+       HandleAutoVacLauncherInterrupts();
 
        /*
         * a worker finished, or postmaster signalled failure to start a
        }
    }
 
-   /* Normal exit from the autovac launcher is here */
-shutdown:
+   AutoVacLauncherShutdown();
+}
+
+/*
+ * Process any new interrupts.
+ */
+static void
+HandleAutoVacLauncherInterrupts(void)
+{
+   /* the normal shutdown case */
+   if (got_SIGTERM)
+       AutoVacLauncherShutdown();
+
+   if (got_SIGHUP)
+   {
+       got_SIGHUP = false;
+       ProcessConfigFile(PGC_SIGHUP);
+
+       /* shutdown requested in config file? */
+       if (!AutoVacuumingActive())
+           AutoVacLauncherShutdown();
+
+       /* rebalance in case the default cost parameters changed */
+       LWLockAcquire(AutovacuumLock, LW_EXCLUSIVE);
+       autovac_balance_cost();
+       LWLockRelease(AutovacuumLock);
+
+       /* rebuild the list in case the naptime changed */
+       rebuild_database_list(InvalidOid);
+   }
+
+   /* Process sinval catchup interrupts that happened while sleeping */
+   ProcessCatchupInterrupt();
+}
+
+/*
+ * Perform a normal exit from the autovac launcher.
+ */
+static void
+AutoVacLauncherShutdown()
+{
    ereport(DEBUG1,
            (errmsg("autovacuum launcher shutting down")));
    AutoVacuumShmem->av_launcherpid = 0;
 
 static volatile sig_atomic_t got_SIGHUP = false;
 static volatile sig_atomic_t shutdown_requested = false;
 
+static void HandleBackgroundWriterInterrupts(void);
+
 /* Signal handlers */
 
 static void bg_quickdie(SIGNAL_ARGS);
        /* Clear any already-pending wakeups */
        ResetLatch(MyLatch);
 
-       if (got_SIGHUP)
-       {
-           got_SIGHUP = false;
-           ProcessConfigFile(PGC_SIGHUP);
-       }
-       if (shutdown_requested)
-       {
-           /*
-            * From here on, elog(ERROR) should end with exit(1), not send
-            * control back to the sigsetjmp block above
-            */
-           ExitOnAnyError = true;
-           /* Normal exit from the bgwriter is here */
-           proc_exit(0);       /* done */
-       }
+       HandleBackgroundWriterInterrupts();
 
        /*
         * Do one cycle of dirty-buffer writing.
    }
 }
 
+/*
+ * Process any new interrupts.
+ */
+static void
+HandleBackgroundWriterInterrupts(void)
+{
+   if (got_SIGHUP)
+   {
+       got_SIGHUP = false;
+       ProcessConfigFile(PGC_SIGHUP);
+   }
+
+   if (shutdown_requested)
+   {
+       /*
+        * From here on, elog(ERROR) should end with exit(1), not send
+        * control back to the sigsetjmp block above
+        */
+       ExitOnAnyError = true;
+       /* Normal exit from the bgwriter is here */
+       proc_exit(0);       /* done */
+   }
+}
+
 
 /* --------------------------------
  *     signal handler routines
 
 
 /* Prototypes for private functions */
 
+static void HandleCheckpointerInterrupts();
 static void CheckArchiveTimeout(void);
 static bool IsCheckpointOnSchedule(double progress);
 static bool ImmediateCheckpointRequested(void);
         * Process any requests or signals received recently.
         */
        AbsorbSyncRequests();
-
-       if (got_SIGHUP)
-       {
-           got_SIGHUP = false;
-           ProcessConfigFile(PGC_SIGHUP);
-
-           /*
-            * Checkpointer is the last process to shut down, so we ask it to
-            * hold the keys for a range of other tasks required most of which
-            * have nothing to do with checkpointing at all.
-            *
-            * For various reasons, some config values can change dynamically
-            * so the primary copy of them is held in shared memory to make
-            * sure all backends see the same value.  We make Checkpointer
-            * responsible for updating the shared memory copy if the
-            * parameter setting changes because of SIGHUP.
-            */
-           UpdateSharedMemoryConfig();
-       }
-       if (shutdown_requested)
-       {
-           /*
-            * From here on, elog(ERROR) should end with exit(1), not send
-            * control back to the sigsetjmp block above
-            */
-           ExitOnAnyError = true;
-           /* Close down the database */
-           ShutdownXLOG(0, 0);
-           /* Normal exit from the checkpointer is here */
-           proc_exit(0);       /* done */
-       }
+       HandleCheckpointerInterrupts();
 
        /*
         * Detect a pending checkpoint request by checking whether the flags
    }
 }
 
+/*
+ * Process any new interrupts.
+ */
+static void
+HandleCheckpointerInterrupts(void)
+{
+   if (got_SIGHUP)
+   {
+       got_SIGHUP = false;
+       ProcessConfigFile(PGC_SIGHUP);
+
+       /*
+        * Checkpointer is the last process to shut down, so we ask it to
+        * hold the keys for a range of other tasks required most of which
+        * have nothing to do with checkpointing at all.
+        *
+        * For various reasons, some config values can change dynamically
+        * so the primary copy of them is held in shared memory to make
+        * sure all backends see the same value.  We make Checkpointer
+        * responsible for updating the shared memory copy if the
+        * parameter setting changes because of SIGHUP.
+        */
+       UpdateSharedMemoryConfig();
+   }
+   if (shutdown_requested)
+   {
+       /*
+        * From here on, elog(ERROR) should end with exit(1), not send
+        * control back to the sigsetjmp block above
+        */
+       ExitOnAnyError = true;
+       /* Close down the database */
+       ShutdownXLOG(0, 0);
+       /* Normal exit from the checkpointer is here */
+       proc_exit(0);       /* done */
+   }
+}
+
 /*
  * CheckArchiveTimeout -- check for archive_timeout and switch xlog files
  *
 
 static volatile sig_atomic_t got_SIGHUP = false;
 static volatile sig_atomic_t shutdown_requested = false;
 
+static void HandleWalWriterInterrupts(void);
+
 /* Signal handlers */
 static void wal_quickdie(SIGNAL_ARGS);
 static void WalSigHupHandler(SIGNAL_ARGS);
        /* Clear any already-pending wakeups */
        ResetLatch(MyLatch);
 
-       /*
-        * Process any requests or signals received recently.
-        */
-       if (got_SIGHUP)
-       {
-           got_SIGHUP = false;
-           ProcessConfigFile(PGC_SIGHUP);
-       }
-       if (shutdown_requested)
-       {
-           /* Normal exit from the walwriter is here */
-           proc_exit(0);       /* done */
-       }
+       HandleWalWriterInterrupts();
 
        /*
         * Do what we're here for; then, if XLogBackgroundFlush() found useful
    }
 }
 
+/*
+ * Process any new interrupts.
+ */
+static void
+HandleWalWriterInterrupts(void)
+{
+   if (got_SIGHUP)
+   {
+       got_SIGHUP = false;
+       ProcessConfigFile(PGC_SIGHUP);
+   }
+   if (shutdown_requested)
+   {
+       /* Normal exit from the walwriter is here */
+       proc_exit(0);       /* done */
+   }
+}
+
 
 /* --------------------------------
  *     signal handler routines