Skip to content

Commit a3b1171

Browse files
committed
Don't use Zend signal handling in pcntl
The deferred signal delivery provided by Zend signal handling is not used anywhere now, so there is no need to go through `zend_sigaction` in pcntl. Since `zend_sigaction` did have the effect of unblocking the signal whose handler has been set, add that in pcntl to avoid changing behavior. The one thing which will change is that Zend signal handling ignored the signal mask provided by pcntl and used its own. Now the signal mask requested by pcntl will actually be used.
1 parent 5c27746 commit a3b1171

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

ext/pcntl/pcntl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ PHP_FUNCTION(pcntl_signal)
936936
php_error_docref(NULL, E_WARNING, "Invalid value for handle argument specified");
937937
RETURN_FALSE;
938938
}
939-
if (php_signal(signo, (Sigfunc *) Z_LVAL_P(handle), (int) restart_syscalls) == (void *)SIG_ERR) {
939+
if (php_signal(signo, (Sigfunc *) Z_LVAL_P(handle), (int) restart_syscalls) == FAILURE) {
940940
PCNTL_G(last_error) = errno;
941941
php_error_docref(NULL, E_WARNING, "Error assigning signal");
942942
RETURN_FALSE;
@@ -959,7 +959,7 @@ PHP_FUNCTION(pcntl_signal)
959959
handle = zend_hash_index_update(&PCNTL_G(php_signal_table), signo, handle);
960960
Z_TRY_ADDREF_P(handle);
961961

962-
if (php_signal4(signo, pcntl_signal_handler, (int) restart_syscalls, 1) == (void *)SIG_ERR) {
962+
if (php_signal4(signo, pcntl_signal_handler, (int) restart_syscalls, 1) == FAILURE) {
963963
PCNTL_G(last_error) = errno;
964964
php_error_docref(NULL, E_WARNING, "Error assigning signal");
965965
RETURN_FALSE;

ext/pcntl/php_signal.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@
1717
#include "TSRM.h"
1818
#include "php_signal.h"
1919
#include "Zend/zend.h"
20-
#include "Zend/zend_signal.h"
20+
21+
#ifdef ZTS
22+
# define php_sigprocmask(how, set, oldset) tsrm_sigmask((how), (set), (oldset))
23+
#else
24+
# define php_sigprocmask(how, set, oldset) sigprocmask((how), (set), (oldset))
25+
#endif
2126

2227
/* php_signal using sigaction is derived from Advanced Programming
2328
* in the Unix Environment by W. Richard Stevens p 298. */
24-
Sigfunc *php_signal4(int signo, Sigfunc *func, int restart, int mask_all)
29+
int php_signal4(int signo, Sigfunc *func, int restart, int mask_all)
2530
{
26-
struct sigaction act,oact;
31+
struct sigaction act;
32+
sigset_t sigset;
2733

2834
#ifdef HAVE_STRUCT_SIGINFO_T
2935
act.sa_sigaction = func;
@@ -48,18 +54,19 @@ Sigfunc *php_signal4(int signo, Sigfunc *func, int restart, int mask_all)
4854
act.sa_flags |= SA_RESTART; /* SVR4, 4.3+BSD */
4955
#endif
5056
}
51-
if (zend_sigaction(signo, &act, &oact) < 0) {
52-
return (void*)SIG_ERR;
57+
if (sigaction(signo, &act, NULL) < 0) {
58+
return FAILURE;
5359
}
5460

55-
#ifdef HAVE_STRUCT_SIGINFO_T
56-
return oact.sa_sigaction;
57-
#else
58-
return oact.sa_handler;
59-
#endif
61+
/* Ensure this signal is not blocked */
62+
sigemptyset(&sigset);
63+
sigaddset(&sigset, signo);
64+
php_sigprocmask(SIG_UNBLOCK, &sigset, NULL);
65+
66+
return SUCCESS;
6067
}
6168

62-
Sigfunc *php_signal(int signo, Sigfunc *func, int restart)
69+
int php_signal(int signo, Sigfunc *func, int restart)
6370
{
6471
return php_signal4(signo, func, restart, 0);
6572
}

ext/pcntl/php_signal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ typedef void Sigfunc(int, siginfo_t*, void*);
2323
#else
2424
typedef void Sigfunc(int);
2525
#endif
26-
Sigfunc *php_signal(int signo, Sigfunc *func, int restart);
27-
Sigfunc *php_signal4(int signo, Sigfunc *func, int restart, int mask_all);
26+
int php_signal(int signo, Sigfunc *func, int restart);
27+
int php_signal4(int signo, Sigfunc *func, int restart, int mask_all);
2828

2929
#endif

0 commit comments

Comments
 (0)