Skip to content

Commit 8977a98

Browse files
committed
Don't use Zend signal handling in phpdbg
One difference between `zend_signal`, etc. and the underlying platform APIs like `signal` is that the Zend versions did automatically unblock the signals for which a handler is set. But looking at phpdbg, I don't think it is really the intention to unblock SIGIO or SIGSEGV when installing handlers for them. There is no good reason why all these signals would be blocked anyways.
1 parent a3b1171 commit 8977a98

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

sapi/phpdbg/phpdbg.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ void phpdbg_signal_handler(int sig, siginfo_t *info, void *context) /* {{{ */
12421242
if (PHPDBG_G(sigsegv_bailout)) {
12431243
LONGJMP(*PHPDBG_G(sigsegv_bailout), FAILURE);
12441244
}
1245-
zend_sigaction(sig, &PHPDBG_G(old_sigsegv_signal), NULL);
1245+
sigaction(sig, &PHPDBG_G(old_sigsegv_signal), NULL);
12461246
}
12471247
break;
12481248
}
@@ -1371,8 +1371,6 @@ int main(int argc, char **argv) /* {{{ */
13711371
# endif
13721372
#endif
13731373

1374-
zend_signal_startup();
1375-
13761374
ini_entries = NULL;
13771375
ini_entries_len = 0;
13781376
ini_ignore = 0;
@@ -1669,10 +1667,6 @@ int main(int argc, char **argv) /* {{{ */
16691667
goto free_and_return;
16701668
}
16711669

1672-
zend_try {
1673-
zend_signal_activate();
1674-
} zend_end_try();
1675-
16761670
/* setup remote server if necessary */
16771671
if (cleaning <= 0 && listen > 0) {
16781672
server = phpdbg_open_socket(address, listen);
@@ -1681,15 +1675,15 @@ int main(int argc, char **argv) /* {{{ */
16811675
}
16821676

16831677
#ifndef _WIN32
1684-
zend_sigaction(SIGIO, &sigio_struct, NULL);
1678+
sigaction(SIGIO, &sigio_struct, NULL);
16851679
#endif
16861680

16871681
/* set remote flag to stop service shutting down upon quit */
16881682
remote = 1;
16891683
#ifndef _WIN32
16901684
} else {
16911685

1692-
zend_signal(SIGHUP, phpdbg_sighup_handler);
1686+
signal(SIGHUP, phpdbg_sighup_handler);
16931687
#endif
16941688
}
16951689

@@ -1758,23 +1752,23 @@ int main(int argc, char **argv) /* {{{ */
17581752
}
17591753

17601754
#ifndef _WIN32
1761-
zend_try { zend_sigaction(SIGSEGV, &signal_struct, &PHPDBG_G(old_sigsegv_signal)); } zend_end_try();
1762-
zend_try { zend_sigaction(SIGBUS, &signal_struct, &PHPDBG_G(old_sigsegv_signal)); } zend_end_try();
1755+
sigaction(SIGSEGV, &signal_struct, &PHPDBG_G(old_sigsegv_signal));
1756+
sigaction(SIGBUS, &signal_struct, &PHPDBG_G(old_sigsegv_signal));
17631757
#endif
17641758

17651759
/* do not install sigint handlers for remote consoles */
17661760
/* sending SIGINT then provides a decent way of shutting down the server */
17671761
#ifndef _WIN32
17681762
if (listen < 0) {
17691763
#endif
1770-
zend_try { zend_signal(SIGINT, phpdbg_sigint_handler); } zend_end_try();
1764+
signal(SIGINT, phpdbg_sigint_handler);
17711765
#ifndef _WIN32
17721766
}
17731767

17741768
/* setup io here */
17751769
if (remote) {
17761770
PHPDBG_G(flags) |= PHPDBG_IS_REMOTE;
1777-
zend_signal(SIGPIPE, SIG_IGN);
1771+
signal(SIGPIPE, SIG_IGN);
17781772
}
17791773
PHPDBG_G(io)[PHPDBG_STDIN].ptr = stdin;
17801774
PHPDBG_G(io)[PHPDBG_STDIN].fd = fileno(stdin);
@@ -2107,7 +2101,7 @@ int main(int argc, char **argv) /* {{{ */
21072101
}
21082102

21092103
#ifndef _WIN32
2110-
/* force override (no zend_signals) to prevent crashes due to signal recursion in SIGSEGV/SIGBUS handlers */
2104+
/* restore default SIGSEGV/SIGBUS handlers */
21112105
signal(SIGSEGV, SIG_DFL);
21122106
signal(SIGBUS, SIG_DFL);
21132107

sapi/phpdbg/phpdbg.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include "zend_globals.h"
4444
#include "zend_ini_scanner.h"
4545
#include "zend_stream.h"
46-
#include "zend_signal.h"
4746
#if !defined(_WIN32) && !defined(ZEND_SIGNALS)
4847
# include <signal.h>
4948
#elif defined(PHP_WIN32)

0 commit comments

Comments
 (0)