Commit 6a1bde5d385 for php.net

commit 6a1bde5d385762ee9e13be9d8d928ece5c00ccfe
Author: David Carlier <devnexen@gmail.com>
Date:   Sat Feb 21 03:52:49 2026 +0000

    ext/pcntl: Fix signal table updated before php_signal4 succeeds in pcntl_signal

    Move the signal table update after the php_signal4 call, mirroring
    what is already done in the SIG_DFL/SIG_IGN (integer) code path.
    This prevents a stale entry in the table if sigaction fails.

    close GH-21270

diff --git a/NEWS b/NEWS
index d31c2d16042..1affbb7f8a3 100644
--- a/NEWS
+++ b/NEWS
@@ -43,9 +43,11 @@ PHP                                                                        NEWS

 - PCNTL:
   . Fixed pcntl_setns() internal errors handling regarding errnos.
-    (David Carlier)
+    (David Carlier/ndossche)
   . Fixed cpuset leak in pcntl_setcpuaffinity on out-of-range CPU ID
     on NetBSD/Solaris platforms. (David Carlier)
+  . Fixed pcntl_signal() signal table registering the callback first
+    OS-wise before the internal list. (David Carlier)

 - PDO_PGSQL:
   . Fixed bug GH-21055 (connection attribute status typo for GSS negotiation).
diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c
index e3b4a9c4c69..de8d7dfecfd 100644
--- a/ext/pcntl/pcntl.c
+++ b/ext/pcntl/pcntl.c
@@ -798,15 +798,16 @@ PHP_FUNCTION(pcntl_signal)
 		RETURN_THROWS();
 	}

-	/* Add the function name to our signal table */
-	handle = zend_hash_index_update(&PCNTL_G(php_signal_table), signo, handle);
-	Z_TRY_ADDREF_P(handle);
-
+	/* Register with the OS first so that on failure we don't record a handler that was never installed */
 	if (php_signal4(signo, pcntl_signal_handler, (int) restart_syscalls, 1) == (void *)SIG_ERR) {
 		PCNTL_G(last_error) = errno;
 		php_error_docref(NULL, E_WARNING, "Error assigning signal");
 		RETURN_FALSE;
 	}
+
+	/* Add the function name to our signal table */
+	handle = zend_hash_index_update(&PCNTL_G(php_signal_table), signo, handle);
+	Z_TRY_ADDREF_P(handle);
 	RETURN_TRUE;
 }
 /* }}} */