cvs: pecl /apc apc_main.c
| From: | Rasmus Lerdorf | Date: | Tue, 03 Aug 2004 20:54:26 +0000 |
| Subject: | cvs: pecl /apc apc_main.c | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-1623@lists.php.net to get a copy of this message | ||
rasmus Tue Aug 3 16:54:26 2004 EDT
Modified files:
/pecl/apc apc_main.c
Log:
This patch fixes a shutdown crash which happens when script execution is
interrupted and APC is asked to shut down before hitting the request
shutdown function. The common way for this to happen is when a busy
server is shut down hard using apachectl stop, for example. This sends a
SIGTERM to Apache which in turn tells APC to shut down right away by
calling apc_module_shutdown(). Before this patch function and class
pointers were left on the global function and class tables but the
associated memory was blown away in the module shutdown function which
ended up causing a crash when PHP tried to clean these later.
This patch causes apc_module_shutdown to walk through the current cache
entries on the stack and remove any function/class pointers from the
global tables before freeing all the memory. It also delays popping
cache entries off of the stack until request shutdown to make sure that
any entries who opcode scope may be done, but who may still have function
or class pointers in the global tables will be seen by this cleanup
function.
http://cvs.php.net/diff.php/pecl/apc/apc_main.c?r1=3.11&r2=3.12&ty=u
Index: pecl/apc/apc_main.c
diff -u pecl/apc/apc_main.c:3.11 pecl/apc/apc_main.c:3.12
--- pecl/apc/apc_main.c:3.11 Fri Jul 9 03:52:23 2004
+++ pecl/apc/apc_main.c Tue Aug 3 16:54:26 2004
@@ -14,7 +14,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: apc_main.c,v 3.11 2004/07/09 07:52:23 derick Exp $ */
+/* $Id: apc_main.c,v 3.12 2004/08/03 20:54:26 rasmus Exp $ */
#include "apc_php.h"
#include "apc_main.h"
@@ -201,6 +201,17 @@
{
old_execute(op_array TSRMLS_CC);
+/* Delaying the pop and release here to keep the cache entries on
+ * the stack in case we get interrupted before request shutdown.
+ * In the case of an interruption our module shutdown function may
+ * need to clean everything up, and in order for it to remove the
+ * function and class entries we may have added over the course of
+ * this request we need to keep all our cache entries around.
+ * This should mean we don't even need to override zend_execute with
+ * this function anymore, so if this works well this entire function
+ * should just go away. -Rasmus
+ */
+#if 0
if (apc_stack_size(APCG(cache_stack)) > 0) {
apc_cache_entry_t* cache_entry =
(apc_cache_entry_t*) apc_stack_top(APCG(cache_stack));
@@ -211,6 +222,7 @@
apc_cache_release(APCG(cache), cache_entry);
}
}
+#endif
}
/* }}} */
@@ -257,6 +269,32 @@
/* restore compilation */
zend_compile_file = old_compile_file;
+
+ /*
+ * In case we got interrupted by a SIGTERM or something else during execution
+ * we may have cache entries left on the stack that we need to check to make
+ * sure that any functions or classes these may have added to the global function
+ * and class tables are removed before we blow away the memory that hold them
+ */
+ while (apc_stack_size(APCG(cache_stack)) > 0) {
+ int i;
+ apc_cache_entry_t* cache_entry = (apc_cache_entry_t*) apc_stack_pop(APCG(cache_stack));
+ if (cache_entry->functions) {
+ for (i = 0; cache_entry->functions[i].function != NULL; i++) {
+ zend_hash_del(EG(function_table),
+ cache_entry->functions[i].name,
+ cache_entry->functions[i].name_len+1);
+ }
+ }
+ if (cache_entry->classes) {
+ for (i = 0; cache_entry->classes[i].class_entry != NULL; i++) {
+ zend_hash_del(EG(class_table),
+ cache_entry->classes[i].name,
+ cache_entry->classes[i].name_len+1);
+ }
+ }
+ apc_cache_free_entry(cache_entry);
+ }
/* apc cleanup */
apc_stack_destroy(APCG(cache_stack));