Skip to content

Fix bug #76895 #4461

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
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
21 changes: 16 additions & 5 deletions Zend/zend_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,35 +330,46 @@ void zend_signal_activate(void)

SIGG(active) = 1;
SIGG(depth) = 0;
SIGG(check) = ZEND_DEBUG;
} /* }}} */

/* {{{ zend_signal_deactivate
* */
void zend_signal_deactivate(void)
{

if (SIGG(check)) {
size_t x;
struct sigaction sa;

if (SIGG(depth) != 0) {
zend_error(E_CORE_WARNING, "zend_signal: shutdown with non-zero blocking depth (%d)", SIGG(depth));
}

/* did anyone steal our installed handler */
for (x = 0; x < sizeof(zend_sigs) / sizeof(*zend_sigs); x++) {
sigaction(zend_sigs[x], NULL, &sa);
if (sa.sa_sigaction != zend_signal_handler_defer) {
if (sa.sa_sigaction != zend_signal_handler_defer &&
sa.sa_sigaction != (void *) SIG_IGN) {
zend_error(E_CORE_WARNING, "zend_signal: handler was replaced for signal (%d) after startup", zend_sigs[x]);
}
}
}

SIGNAL_BEGIN_CRITICAL();
SIGG(active) = 0;
/* 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;

SIGG(running) = 0;
SIGG(blocked) = 0;
SIGG(depth) = 0;
SIGNAL_END_CRITICAL();

/* If there are any queued signals because of a missed unblock, drop them. */
if (SIGG(phead) && SIGG(ptail)) {
SIGG(ptail)->next = SIGG(pavail);
SIGG(pavail) = SIGG(phead);
SIGG(phead) = NULL;
SIGG(ptail) = NULL;
}
}
/* }}} */

Expand Down
11 changes: 10 additions & 1 deletion ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,9 @@ static zend_persistent_script *opcache_compile_file(zend_file_handle *file_handl

/* check blacklist right after ensuring that file was opened */
if (file_handle->opened_path && zend_accel_blacklist_is_blacklisted(&accel_blacklist, ZSTR_VAL(file_handle->opened_path))) {
SHM_UNPROTECT();
ZCSG(blacklist_misses)++;
SHM_PROTECT();
*op_array_p = accelerator_orig_compile_file(file_handle, type);
return NULL;
}
Expand Down Expand Up @@ -1601,7 +1603,9 @@ static zend_persistent_script *opcache_compile_file(zend_file_handle *file_handl
}

if (ZCG(accel_directives).max_file_size > 0 && size > (size_t)ZCG(accel_directives).max_file_size) {
SHM_UNPROTECT();
ZCSG(blacklist_misses)++;
SHM_PROTECT();
*op_array_p = accelerator_orig_compile_file(file_handle, type);
return NULL;
}
Expand Down Expand Up @@ -2003,11 +2007,16 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
return accelerator_orig_compile_file(file_handle, type);
}

SHM_PROTECT();
HANDLE_UNBLOCK_INTERRUPTIONS();
persistent_script = opcache_compile_file(file_handle, type, key, &op_array);
HANDLE_BLOCK_INTERRUPTIONS();
SHM_UNPROTECT();

/* Try and cache the script and assume that it is returned from_shared_memory.
* If it isn't compile_and_cache_file() changes the flag to 0
*/
from_shared_memory = 0;
persistent_script = opcache_compile_file(file_handle, type, key, &op_array);
if (persistent_script) {
persistent_script = cache_script_in_shared_memory(persistent_script, key, key ? key_length : 0, &from_shared_memory);
}
Expand Down
5 changes: 5 additions & 0 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,11 @@ void php_request_shutdown(void *dummy)
zend_unset_timeout();
} zend_end_try();

/* 17. Deactivate Zend signals */
#ifdef ZEND_SIGNALS
zend_signal_deactivate();
#endif

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, it's not a good idea to add several syscalls on each request. May be enable this only in DEBUG build?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just drop the SIGNAL_BEGIN_CRITICAL in zend_signal_deactivate? Then there shouldn't be any syscalls, and I don't see a reason why this needs to block signals during the reset, as long as active=0 is set first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

#ifdef PHP_WIN32
if (PG(com_initialized)) {
CoUninitialize();
Expand Down