Skip to content

Fix GH-8029: Restore previously registered signal handlers #9672

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 1 commit into from
Closed
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
18 changes: 18 additions & 0 deletions Zend/zend_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ void zend_signal_activate(void)
/* {{{ zend_signal_deactivate */
void zend_signal_deactivate(void)
{
int signo;
struct sigaction sa;

if (SIGG(check)) {
size_t x;
struct sigaction sa;
Expand All @@ -352,6 +355,21 @@ void zend_signal_deactivate(void)
}
}

/* Restore previously registered signal handlers from orig_handlers */
for (signo = 0; signo < NSIG; ++signo) {
if (sigaction(signo, NULL, &sa) == 0) {
if (sa.sa_flags & SA_SIGINFO) {
sa.sa_sigaction = global_orig_handlers[signo-1].handler;
} else {
sa.sa_handler = global_orig_handlers[signo-1].handler;
}
sa.sa_flags = global_orig_handlers[signo-1].flags;
if (sigaction(signo, &sa, NULL) < 0) {
zend_error(E_CORE_WARNING, "zend_signal: unable to restore handler for signal (%d) at shutdown", signo);
}
}
}

/* After active=0 is set, signal handlers will be called directly and other
* state that is reset below will not be accessed. */
*((volatile int *) &SIGG(active)) = 0;
Expand Down