@@ -1048,15 +1048,13 @@ static void pcntl_signal_handler(int signo, siginfo_t *siginfo, void *context)
1048
1048
static void pcntl_signal_handler (int signo )
1049
1049
#endif
1050
1050
{
1051
- struct php_pcntl_pending_signal * psig ;
1052
-
1053
- psig = PCNTL_G (spares );
1054
- if (!psig ) {
1051
+ struct php_pcntl_pending_signal * psig_first = PCNTL_G (spares );
1052
+ if (!psig_first ) {
1055
1053
/* oops, too many signals for us to track, so we'll forget about this one */
1056
1054
return ;
1057
1055
}
1058
1056
1059
- struct php_pcntl_pending_signal * psig_first = psig ;
1057
+ struct php_pcntl_pending_signal * psig = NULL ;
1060
1058
1061
1059
/* Standard signals may be merged into a single one.
1062
1060
* POSIX specifies that SIGCHLD has the si_pid field (https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html),
@@ -1075,28 +1073,27 @@ static void pcntl_signal_handler(int signo)
1075
1073
pid = waitpid (WAIT_ANY , & status , WNOHANG | WUNTRACED );
1076
1074
} while (pid <= 0 && errno == EINTR );
1077
1075
if (pid <= 0 ) {
1078
- if (UNEXPECTED (psig == psig_first )) {
1079
- /* Don't handle multiple, revert back to the single signal handling . */
1080
- goto single_signal ;
1076
+ if (UNEXPECTED (! psig )) {
1077
+ /* The child might've been consumed by another thread and will be handled there . */
1078
+ return ;
1081
1079
}
1082
1080
break ;
1083
1081
}
1084
1082
1083
+ psig = psig ? psig -> next : psig_first ;
1085
1084
psig -> signo = signo ;
1086
1085
1087
1086
#ifdef HAVE_STRUCT_SIGINFO_T
1088
1087
psig -> siginfo = * siginfo ;
1089
1088
psig -> siginfo .si_pid = pid ;
1090
1089
#endif
1091
1090
1092
- if (EXPECTED (psig -> next )) {
1093
- psig = psig -> next ;
1094
- } else {
1091
+ if (UNEXPECTED (!psig -> next )) {
1095
1092
break ;
1096
1093
}
1097
1094
}
1098
1095
} else {
1099
- single_signal : ;
1096
+ psig = psig_first ;
1100
1097
psig -> signo = signo ;
1101
1098
1102
1099
#ifdef HAVE_STRUCT_SIGINFO_T
0 commit comments