Commit bcd6f67ebc5 for php.net

commit bcd6f67ebc50664b3b67eea89528223b5739d9fa
Author: David CARLIER <devnexen@gmail.com>
Date:   Wed Apr 8 18:43:10 2026 +0100

    ext/pcntl simplification. (#13975)

    assuming pcntl is an unix-only extension and they all support the siginfo_t type,
     we re using exclusively this more advanced api.

diff --git a/ext/pcntl/config.m4 b/ext/pcntl/config.m4
index cfe6e80ca11..553419114fd 100644
--- a/ext/pcntl/config.m4
+++ b/ext/pcntl/config.m4
@@ -68,9 +68,6 @@ int main(void) {
     [AC_DEFINE([HAVE_SCHED_GETCPU], [1],
       [Define to 1 if the 'sched_getcpu' function is properly supported.])])

-  AC_CHECK_TYPE([siginfo_t], [PCNTL_CFLAGS="-DHAVE_STRUCT_SIGINFO_T"],,
-    [#include <signal.h>])
-
   PHP_NEW_EXTENSION([pcntl],
     [pcntl.c php_signal.c],
     [$ext_shared],
diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c
index ab7b1499208..b4e21e55b6e 100644
--- a/ext/pcntl/pcntl.c
+++ b/ext/pcntl/pcntl.c
@@ -185,12 +185,8 @@ ZEND_GET_MODULE(pcntl)

 static void (*orig_interrupt_function)(zend_execute_data *execute_data);

-#ifdef HAVE_STRUCT_SIGINFO_T
 static void pcntl_signal_handler(int, siginfo_t*, void*);
 static void pcntl_siginfo_to_zval(int, siginfo_t*, zval*);
-#else
-static void pcntl_signal_handler(int);
-#endif
 static void pcntl_signal_dispatch(void);
 static void pcntl_signal_dispatch_tick_function(int dummy_int, void *dummy_pointer);
 static void pcntl_interrupt_function(zend_execute_data *execute_data);
@@ -240,7 +236,7 @@ PHP_RSHUTDOWN_FUNCTION(pcntl)
 	/* Reset all signals to their default disposition */
 	ZEND_HASH_FOREACH_NUM_KEY_VAL(&PCNTL_G(php_signal_table), signo, handle) {
 		if (Z_TYPE_P(handle) != IS_LONG || Z_LVAL_P(handle) != (zend_long)SIG_DFL) {
-			php_signal(signo, (Sigfunc *)(zend_long)SIG_DFL, 0);
+			php_signal(signo, (Sigfunc *)(zend_long)SIG_DFL, false);
 		}
 	} ZEND_HASH_FOREACH_END();

@@ -835,7 +831,7 @@ PHP_FUNCTION(pcntl_signal)
 			zend_argument_value_error(2, "must be either SIG_DFL or SIG_IGN when an integer value is given");
 			RETURN_THROWS();
 		}
-		if (php_signal(signo, (Sigfunc *) Z_LVAL_P(handle), (int) restart_syscalls) == (void *)SIG_ERR) {
+		if (php_signal(signo, (Sigfunc *) Z_LVAL_P(handle), restart_syscalls) == (void *)SIG_ERR) {
 			PCNTL_G(last_error) = errno;
 			php_error_docref(NULL, E_WARNING, "Error assigning signal");
 			RETURN_FALSE;
@@ -1007,8 +1003,7 @@ PHP_FUNCTION(pcntl_sigprocmask)
 /* }}} */
 #endif

-#ifdef HAVE_STRUCT_SIGINFO_T
-# ifdef HAVE_SIGWAITINFO
+#ifdef HAVE_SIGWAITINFO

 /* {{{ Synchronously wait for queued signals */
 PHP_FUNCTION(pcntl_sigwaitinfo)
@@ -1050,8 +1045,9 @@ PHP_FUNCTION(pcntl_sigwaitinfo)
 	RETURN_LONG(signal_no);
 }
 /* }}} */
-# endif
-# ifdef HAVE_SIGTIMEDWAIT
+#endif
+
+#ifdef HAVE_SIGTIMEDWAIT
 /* {{{ Wait for queued signals */
 PHP_FUNCTION(pcntl_sigtimedwait)
 {
@@ -1113,7 +1109,7 @@ PHP_FUNCTION(pcntl_sigtimedwait)
 	RETURN_LONG(signal_no);
 }
 /* }}} */
-# endif
+#endif

 static void pcntl_siginfo_to_zval(int signo, siginfo_t *siginfo, zval *user_siginfo) /* {{{ */
 {
@@ -1183,7 +1179,6 @@ static void pcntl_siginfo_to_zval(int signo, siginfo_t *siginfo, zval *user_sigi
 	}
 }
 /* }}} */
-#endif

 #ifdef HAVE_GETPRIORITY
 /* {{{ Get the priority of any process */
@@ -1325,11 +1320,7 @@ PHP_FUNCTION(pcntl_strerror)
 /* }}} */

 /* Our custom signal handler that calls the appropriate php_function */
-#ifdef HAVE_STRUCT_SIGINFO_T
 static void pcntl_signal_handler(int signo, siginfo_t *siginfo, void *context)
-#else
-static void pcntl_signal_handler(int signo)
-#endif
 {
 	struct php_pcntl_pending_signal *psig = PCNTL_G(spares);
 	if (!psig) {
@@ -1341,9 +1332,7 @@ static void pcntl_signal_handler(int signo)
 	psig->signo = signo;
 	psig->next = NULL;

-#ifdef HAVE_STRUCT_SIGINFO_T
 	psig->siginfo = *siginfo;
-#endif

 	/* the head check is important, as the tick handler cannot atomically clear both
 	 * the head and tail */
@@ -1395,19 +1384,14 @@ void pcntl_signal_dispatch(void)
 		if ((handle = zend_hash_index_find(&PCNTL_G(php_signal_table), queue->signo)) != NULL) {
 			if (Z_TYPE_P(handle) != IS_LONG) {
 				ZVAL_LONG(&params[0], queue->signo);
-#ifdef HAVE_STRUCT_SIGINFO_T
 				array_init(&params[1]);
 				pcntl_siginfo_to_zval(queue->signo, &queue->siginfo, &params[1]);
-#else
-				ZVAL_NULL(&params[1]);
-#endif

 				/* Call php signal handler - Note that we do not report errors, and we ignore the return value */
 				call_user_function(NULL, NULL, handle, &retval, 2, params);
 				zval_ptr_dtor(&retval);
-#ifdef HAVE_STRUCT_SIGINFO_T
 				zval_ptr_dtor(&params[1]);
-#endif
+
 				if (EG(exception)) {
 					break;
 				}
diff --git a/ext/pcntl/pcntl.stub.php b/ext/pcntl/pcntl.stub.php
index 2da540fa71e..4a4b8fe8693 100644
--- a/ext/pcntl/pcntl.stub.php
+++ b/ext/pcntl/pcntl.stub.php
@@ -1035,14 +1035,12 @@ function pcntl_signal_dispatch(): bool {}
     function pcntl_sigprocmask(int $mode, array $signals, &$old_signals = null): bool {}
 #endif

-#ifdef HAVE_STRUCT_SIGINFO_T
 #if (defined(HAVE_SIGWAITINFO) && defined(HAVE_SIGTIMEDWAIT))
     /** @param array $info */
     function pcntl_sigwaitinfo(array $signals, &$info = []): int|false {}

     /** @param array $info */
     function pcntl_sigtimedwait(array $signals, &$info = [], int $seconds = 0, int $nanoseconds = 0): int|false {}
-#endif
 #endif

     function pcntl_wifexited(int $status): bool {}
diff --git a/ext/pcntl/pcntl_arginfo.h b/ext/pcntl/pcntl_arginfo.h
index d9624a22605..2da7c8ad5db 100644
Binary files a/ext/pcntl/pcntl_arginfo.h and b/ext/pcntl/pcntl_arginfo.h differ
diff --git a/ext/pcntl/pcntl_decl.h b/ext/pcntl/pcntl_decl.h
index 1059485bc93..7f8e5172ced 100644
Binary files a/ext/pcntl/pcntl_decl.h and b/ext/pcntl/pcntl_decl.h differ
diff --git a/ext/pcntl/php_pcntl.h b/ext/pcntl/php_pcntl.h
index e02f93246e8..aed96af380e 100644
--- a/ext/pcntl/php_pcntl.h
+++ b/ext/pcntl/php_pcntl.h
@@ -38,9 +38,7 @@ PHP_MINFO_FUNCTION(pcntl);
 struct php_pcntl_pending_signal {
 	struct php_pcntl_pending_signal *next;
 	zend_long signo;
-#ifdef HAVE_STRUCT_SIGINFO_T
 	siginfo_t siginfo;
-#endif
 };

 ZEND_BEGIN_MODULE_GLOBALS(pcntl)
diff --git a/ext/pcntl/php_signal.c b/ext/pcntl/php_signal.c
index 14c169310e6..7f27ac33e45 100644
--- a/ext/pcntl/php_signal.c
+++ b/ext/pcntl/php_signal.c
@@ -21,24 +21,18 @@

 /* php_signal using sigaction is derived from Advanced Programming
  * in the Unix Environment by W. Richard Stevens p 298. */
-Sigfunc *php_signal4(int signo, Sigfunc *func, int restart, int mask_all)
+Sigfunc *php_signal4(int signo, Sigfunc *func, bool restart, bool mask_all)
 {
 	struct sigaction act,oact;

-#ifdef HAVE_STRUCT_SIGINFO_T
 	act.sa_sigaction = func;
-#else
-	act.sa_handler = func;
-#endif
 	if (mask_all) {
 		sigfillset(&act.sa_mask);
 	} else {
 		sigemptyset(&act.sa_mask);
 	}
 	act.sa_flags = SA_ONSTACK;
-#ifdef HAVE_STRUCT_SIGINFO_T
 	act.sa_flags |= SA_SIGINFO;
-#endif
 	if (!restart) {
 #ifdef SA_INTERRUPT
 		act.sa_flags |= SA_INTERRUPT; /* SunOS */
@@ -50,14 +44,10 @@ Sigfunc *php_signal4(int signo, Sigfunc *func, int restart, int mask_all)
 	}
 	zend_sigaction(signo, &act, &oact);

-#ifdef HAVE_STRUCT_SIGINFO_T
 	return oact.sa_sigaction;
-#else
-	return oact.sa_handler;
-#endif
 }

-Sigfunc *php_signal(int signo, Sigfunc *func, int restart)
+Sigfunc *php_signal(int signo, Sigfunc *func, bool restart)
 {
-	return php_signal4(signo, func, restart, 0);
+	return php_signal4(signo, func, restart, false);
 }
diff --git a/ext/pcntl/php_signal.h b/ext/pcntl/php_signal.h
index 256898e70ac..44cbd68999f 100644
--- a/ext/pcntl/php_signal.h
+++ b/ext/pcntl/php_signal.h
@@ -18,12 +18,9 @@
 #ifndef PHP_SIGNAL_H
 #define PHP_SIGNAL_H

-#ifdef HAVE_STRUCT_SIGINFO_T
 typedef void Sigfunc(int, siginfo_t*, void*);
-#else
-typedef void Sigfunc(int);
-#endif
-Sigfunc *php_signal(int signo, Sigfunc *func, int restart);
-Sigfunc *php_signal4(int signo, Sigfunc *func, int restart, int mask_all);
+
+Sigfunc *php_signal(int signo, Sigfunc *func, bool restart);
+Sigfunc *php_signal4(int signo, Sigfunc *func, bool restart, bool mask_all);

 #endif