From 6cde926037917c13735f3ff88a5e62acf9ccf045 Mon Sep 17 00:00:00 2001
From: Zsolt Parragi <zsolt.parragi@percona.com>
Date: Thu, 12 Nov 2026 00:00:22 +0000
Subject: [PATCH v14 1/9] Reset SIGCHLD in standalone backends too

Commit 2e2751e6976 moved resetting SIGCHLD from PostgresMain() to
InitPostmasterChild().  But the reset in PostgresMain() also ran in
single-user mode, which doesn't call InitPostmasterChild().  If the
standalone backend was started with SIGCHLD ignored, children are now
reaped automatically, and e.g. COPY TO PROGRAM fails with "could not
close pipe to external command: No child processes".

To fix, reset it in InitStandaloneProcess() as well.

Author: Zsolt Parragi <zsolt.parragi@percona.com>
Discussion: https://postgr.es/m/CAN4CZFOHfK1dpJijJwH4j8yMEHS5xier=9UAhB2BU_vWZ9x3qQ@mail.gmail.com
---
 src/backend/utils/init/miscinit.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index 27bafafcd86..e9c923df861 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -210,6 +210,12 @@ InitStandaloneProcess(const char *argv0)
 	pqinitmask();
 	sigprocmask(SIG_SETMASK, &BlockSig, NULL);
 
+	/*
+	 * Reset SIGCHLD, in case we were started with it ignored.  See
+	 * InitPostmasterChild.
+	 */
+	pqsignal(SIGCHLD, PG_SIG_DFL);
+
 	/* Compute paths, no postmaster to inherit from */
 	if (my_exec_path[0] == '\0')
 	{

base-commit: 4483697be0e0d22b9b4fd847e8bf2d998c56a741
-- 
2.54.0

