Skip to content

Fix 73783 : pcntl_signal() not handling SIG_IGN correctly #2246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Zend/zend_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static void zend_signal_handler(int signo, siginfo_t *siginfo, void *context)
#endif
}
}
} else if (p_sig.handler != SIG_IGN) { /* ignore SIG_IGN */
} else {
if (p_sig.flags & SA_SIGINFO) {
if (p_sig.flags & SA_RESETHAND) {
SIGG(handlers)[signo-1].flags = 0;
Expand Down Expand Up @@ -234,9 +234,13 @@ ZEND_API int zend_sigaction(int signo, const struct sigaction *act, struct sigac
}

memset(&sa, 0, sizeof(sa));
sa.sa_flags = SA_SIGINFO | (act->sa_flags & SA_FLAGS_MASK);
sa.sa_sigaction = zend_signal_handler_defer;
sa.sa_mask = global_sigmask;
if (SIGG(handlers)[signo-1].handler == (void *) SIG_IGN) {
sa.sa_sigaction = (void *) SIG_IGN;
} else {
sa.sa_flags = SA_SIGINFO | (act->sa_flags & SA_FLAGS_MASK);
sa.sa_sigaction = zend_signal_handler_defer;
sa.sa_mask = global_sigmask;
}

if (sigaction(signo, &sa, NULL) < 0) {
zend_error_noreturn(E_ERROR, "Error installing signal handler for %d", signo);
Expand Down
28 changes: 28 additions & 0 deletions ext/pcntl/tests/bug73783.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
Bug #73783: (SIG_IGN needs to be set to prevent syscals from returning early)
--SKIPIF--
<?php
if (!extension_loaded('pcntl')) die('skip pcntl extension not available');
elseif (!extension_loaded('posix')) die('skip posix extension not available');
?>
--FILE--
<?php
pcntl_signal(SIGCHLD, SIG_IGN);

switch(pcntl_fork()) {
case 0:
exit;
break;
}

$before = time();
sleep(3);

if (time() - $before >= 2) {
echo "working\n";
} else {
echo "failed\n";
}
?>
--EXPECTF--
working