Skip to content

Commit c59bfc8

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Revert the fix for GH-11498
2 parents 77417f8 + f7be15d commit c59bfc8

File tree

3 files changed

+17
-53
lines changed

3 files changed

+17
-53
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ PHP NEWS
3838
. Avoid adding an unnecessary read-lock when loading script from shm if
3939
restart is in progress. (mikhainin)
4040

41+
- PCNTL:
42+
. Revert behaviour of receiving SIGCHLD signals back to the behaviour
43+
before 8.1.22. (nielsdos)
44+
4145
- Standard:
4246
. Prevent int overflow on $decimals in number_format. (Marc Bennewitz)
4347

ext/pcntl/pcntl.c

+8-50
Original file line numberDiff line numberDiff line change
@@ -1048,68 +1048,26 @@ static void pcntl_signal_handler(int signo, siginfo_t *siginfo, void *context)
10481048
static void pcntl_signal_handler(int signo)
10491049
#endif
10501050
{
1051-
struct php_pcntl_pending_signal *psig_first = PCNTL_G(spares);
1052-
if (!psig_first) {
1051+
struct php_pcntl_pending_signal *psig = PCNTL_G(spares);
1052+
if (!psig) {
10531053
/* oops, too many signals for us to track, so we'll forget about this one */
10541054
return;
10551055
}
1056+
PCNTL_G(spares) = psig->next;
10561057

1057-
struct php_pcntl_pending_signal *psig = NULL;
1058-
1059-
/* Standard signals may be merged into a single one.
1060-
* POSIX specifies that SIGCHLD has the si_pid field (https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html),
1061-
* so we'll handle the merging for that signal.
1062-
* See also: https://www.gnu.org/software/libc/manual/html_node/Merged-Signals.html */
1063-
if (signo == SIGCHLD) {
1064-
/* Note: The first waitpid result is not necessarily the pid that was passed above!
1065-
* We therefore cannot avoid the first waitpid() call. */
1066-
int status;
1067-
pid_t pid;
1068-
while (true) {
1069-
do {
1070-
errno = 0;
1071-
/* Although Linux specifies that WNOHANG will never result in EINTR, POSIX doesn't say so:
1072-
* https://pubs.opengroup.org/onlinepubs/9699919799/functions/waitpid.html */
1073-
pid = waitpid(-1, &status, WNOHANG | WUNTRACED);
1074-
} while (pid <= 0 && errno == EINTR);
1075-
if (pid <= 0) {
1076-
if (UNEXPECTED(!psig)) {
1077-
/* The child might've been consumed by another thread and will be handled there. */
1078-
return;
1079-
}
1080-
break;
1081-
}
1082-
1083-
psig = psig ? psig->next : psig_first;
1084-
psig->signo = signo;
1085-
1086-
#ifdef HAVE_STRUCT_SIGINFO_T
1087-
psig->siginfo = *siginfo;
1088-
psig->siginfo.si_pid = pid;
1089-
#endif
1090-
1091-
if (UNEXPECTED(!psig->next)) {
1092-
break;
1093-
}
1094-
}
1095-
} else {
1096-
psig = psig_first;
1097-
psig->signo = signo;
1058+
psig->signo = signo;
1059+
psig->next = NULL;
10981060

10991061
#ifdef HAVE_STRUCT_SIGINFO_T
1100-
psig->siginfo = *siginfo;
1062+
psig->siginfo = *siginfo;
11011063
#endif
1102-
}
1103-
1104-
PCNTL_G(spares) = psig->next;
1105-
psig->next = NULL;
11061064

11071065
/* the head check is important, as the tick handler cannot atomically clear both
11081066
* the head and tail */
11091067
if (PCNTL_G(head) && PCNTL_G(tail)) {
1110-
PCNTL_G(tail)->next = psig_first;
1068+
PCNTL_G(tail)->next = psig;
11111069
} else {
1112-
PCNTL_G(head) = psig_first;
1070+
PCNTL_G(head) = psig;
11131071
}
11141072
PCNTL_G(tail) = psig;
11151073
PCNTL_G(pending_signals) = 1;

ext/pcntl/tests/gh11498.phpt renamed to ext/pcntl/tests/waiting_on_sigchild_pcntl_wait.phpt

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
GH-11498 (SIGCHLD is not always returned from proc_open)
2+
Waiting on SIGCHLD with a pcntl_wait() loop
33
--EXTENSIONS--
44
pcntl
55
--SKIPIF--
@@ -14,8 +14,10 @@ $processes = [];
1414

1515
pcntl_async_signals(true);
1616
pcntl_signal(SIGCHLD, function($sig, $info) use (&$processes) {
17-
echo "SIGCHLD\n";
18-
unset($processes[$info['pid']]);
17+
while (($pid = pcntl_wait($status, WUNTRACED | WNOHANG)) > 0) {
18+
echo "SIGCHLD\n";
19+
unset($processes[$pid]);
20+
}
1921
}, false);
2022

2123
for ($i = 0; $i <= 5; $i++) {

0 commit comments

Comments
 (0)