Skip to content

Commit

Permalink
Revert the fix for phpGH-11498
Browse files Browse the repository at this point in the history
People relied on manually waiting for children, but the fix for phpGH-11498
broke this. Fixing this in PHP is fundamentally incompatible with doing
the wait loop in userland. This reverts to the old behaviour.
  • Loading branch information
nielsdos committed Aug 2, 2023
1 parent 94127c5 commit 3e817a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 90 deletions.
55 changes: 8 additions & 47 deletions ext/pcntl/pcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1338,68 +1338,29 @@ static void pcntl_signal_handler(int signo, siginfo_t *siginfo, void *context)
static void pcntl_signal_handler(int signo)
#endif
{
struct php_pcntl_pending_signal *psig_first = PCNTL_G(spares);
if (!psig_first) {
struct php_pcntl_pending_signal *psig = PCNTL_G(spares);
if (!psig) {
/* oops, too many signals for us to track, so we'll forget about this one */
return;
}
PCNTL_G(spares) = psig->next;

struct php_pcntl_pending_signal *psig = NULL;

/* Standard signals may be merged into a single one.
* POSIX specifies that SIGCHLD has the si_pid field (https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html),
* so we'll handle the merging for that signal.
* See also: https://www.gnu.org/software/libc/manual/html_node/Merged-Signals.html */
if (signo == SIGCHLD) {
/* Note: The first waitpid result is not necessarily the pid that was passed above!
* We therefore cannot avoid the first waitpid() call. */
int status;
pid_t pid;
while (true) {
do {
errno = 0;
/* Although Linux specifies that WNOHANG will never result in EINTR, POSIX doesn't say so:
* https://pubs.opengroup.org/onlinepubs/9699919799/functions/waitpid.html */
pid = waitpid(-1, &status, WNOHANG | WUNTRACED);
} while (pid <= 0 && errno == EINTR);
if (pid <= 0) {
if (UNEXPECTED(!psig)) {
/* The child might've been consumed by another thread and will be handled there. */
return;
}
break;
}

psig = psig ? psig->next : psig_first;
psig->signo = signo;

#ifdef HAVE_STRUCT_SIGINFO_T
psig->siginfo = *siginfo;
psig->siginfo.si_pid = pid;
#endif

if (UNEXPECTED(!psig->next)) {
break;
}
}
} else {
psig = psig_first;
psig->signo = signo;
psig->signo = signo;
psig->next = NULL;

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

PCNTL_G(spares) = psig->next;
psig->next = NULL;

/* the head check is important, as the tick handler cannot atomically clear both
* the head and tail */
if (PCNTL_G(head) && PCNTL_G(tail)) {
PCNTL_G(tail)->next = psig_first;
PCNTL_G(tail)->next = psig;
} else {
PCNTL_G(head) = psig_first;
PCNTL_G(head) = psig;
}
PCNTL_G(tail) = psig;
PCNTL_G(pending_signals) = 1;
Expand Down
43 changes: 0 additions & 43 deletions ext/pcntl/tests/gh11498.phpt

This file was deleted.

0 comments on commit 3e817a6

Please sign in to comment.