From: Andres Freund Date: Fri, 24 Jan 2025 22:00:10 +0000 (-0500) Subject: postmaster: Don't open-code TerminateChildren() in HandleChildCrash() X-Git-Tag: REL_18_BETA1~1014 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=d239c1a8e5b6ac467b3479bf3840e3d297a40bef;p=postgresql.git postmaster: Don't open-code TerminateChildren() in HandleChildCrash() After removing the duplication no user of sigquit_child() remains, therefore remove it. Reviewed-by: Bertrand Drouvot Discussion: https://postgr.es/m/kgng5nrvnlv335evmsuvpnh354rw7qyazl73kdysev2cr2v5zu@m3cfzxicm5kp --- diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 5488289a489..ea92fb56c80 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -243,6 +243,13 @@ bool enable_bonjour = false; char *bonjour_name; bool restart_after_crash = true; bool remove_temp_files_after_crash = true; + +/* + * When terminating child processes after fatal errors, like a crash of a + * child process, we normally send SIGQUIT -- and most other comments in this + * file are written on the assumption that we do -- but developers might + * prefer to use SIGABRT to collect per-child core dumps. + */ bool send_abort_for_crash = false; bool send_abort_for_kill = false; @@ -424,7 +431,6 @@ static int BackendStartup(ClientSocket *client_sock); static void report_fork_failure_to_client(ClientSocket *client_sock, int errnum); static CAC_state canAcceptConnections(BackendType backend_type); static void signal_child(PMChild *pmchild, int signal); -static void sigquit_child(PMChild *pmchild); static bool SignalChildren(int signal, BackendTypeMask targetMask); static void TerminateChildren(int signal); static int CountChildren(BackendTypeMask targetMask); @@ -2701,32 +2707,12 @@ HandleChildCrash(int pid, int exitstatus, const char *procname) /* * Signal all other child processes to exit. The crashed process has * already been removed from ActiveChildList. + * + * We could exclude dead-end children here, but at least when sending + * SIGABRT it seems better to include them. */ if (take_action) - { - dlist_iter iter; - - dlist_foreach(iter, &ActiveChildList) - { - PMChild *bp = dlist_container(PMChild, elem, iter.cur); - - /* We do NOT restart the syslogger */ - if (bp == SysLoggerPMChild) - continue; - - if (bp == StartupPMChild) - StartupStatus = STARTUP_SIGNALED; - - /* - * This backend is still alive. Unless we did so already, tell it - * to commit hara-kiri. - * - * We could exclude dead-end children here, but at least when - * sending SIGABRT it seems better to include them. - */ - sigquit_child(bp); - } - } + TerminateChildren(send_abort_for_crash ? SIGABRT : SIGQUIT); if (Shutdown != ImmediateShutdown) FatalError = true; @@ -3349,19 +3335,6 @@ signal_child(PMChild *pmchild, int signal) #endif } -/* - * Convenience function for killing a child process after a crash of some - * other child process. We apply send_abort_for_crash to decide which signal - * to send. Normally it's SIGQUIT -- and most other comments in this file are - * written on the assumption that it is -- but developers might prefer to use - * SIGABRT to collect per-child core dumps. - */ -static void -sigquit_child(PMChild *pmchild) -{ - signal_child(pmchild, (send_abort_for_crash ? SIGABRT : SIGQUIT)); -} - /* * Send a signal to the targeted children. */