Browse Source

fixed #281: changing zend_error may left unclean set up when timeout occur; zend_error is not thread local

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@903 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
3.0
Xuefer 9 years ago
parent
commit
a8046018da
  1. 58
      utils.c
  2. 4
      utils.h
  3. 2
      xcache.c

58
utils.c

@ -26,6 +26,16 @@
zval_dtor(&Z_OP_CONSTANT(op)); \
} while(0)
#endif
static void (*old_zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args) = NULL;
static void call_old_zend_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, ...) /* {{{ */
{
va_list args;
va_start(args, format);
old_zend_error_cb(type, error_filename, error_lineno, format, args);
}
/* }}} */
xc_compile_result_t *xc_compile_result_init(xc_compile_result_t *cr, /* {{{ */
zend_op_array *op_array,
HashTable *function_table,
@ -586,7 +596,11 @@ static void xc_sandbox_error_cb(int type, const char *error_filename, const uint
TSRMLS_FETCH();
sandbox = (xc_sandbox_t *) XG(sandbox);
assert(sandbox != NULL);
if (!sandbox) {
old_zend_error_cb(type, error_filename, error_lineno, format, args);
return;
}
switch (type) {
#ifdef E_STRICT
case E_STRICT:
@ -613,18 +627,23 @@ static void xc_sandbox_error_cb(int type, const char *error_filename, const uint
default: {
/* give up, and user handler is not supported in this case */
zend_uint i;
zend_uint orig_lineno = CG(zend_lineno);
zend_error_cb = sandbox->orig_zend_error_cb;
zend_uint old_lineno = CG(zend_lineno);
for (i = 0; i < sandbox->compilererror_cnt; i ++) {
compilererror = &sandbox->compilererrors[i];
CG(zend_lineno) = compilererror->lineno;
zend_error(compilererror->type, "%s", compilererror->error);
call_old_zend_error_cb(compilererror->type, error_filename, error_lineno, "%s", compilererror->error);
efree(compilererror->error);
}
if (sandbox->compilererrors) {
efree(sandbox->compilererrors);
sandbox->compilererrors = NULL;
}
CG(zend_lineno) = orig_lineno;
sandbox->compilererror_cnt = 0;
sandbox->compilererror_cnt = 0;
sandbox->compilererror_size = 0;
sandbox->orig_zend_error_cb(type, error_filename, error_lineno, format, args);
CG(zend_lineno) = old_lineno;
old_zend_error_cb(type, error_filename, error_lineno, format, args);
break;
}
}
@ -790,8 +809,6 @@ xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, ZEND_24(NOTHING, const) cha
sandbox->compilererror_cnt = 0;
sandbox->compilererror_size = 0;
sandbox->orig_zend_error_cb = zend_error_cb;
zend_error_cb = xc_sandbox_error_cb;
#endif
#ifdef ZEND_COMPILE_IGNORE_INTERNAL_CLASSES
@ -891,7 +908,6 @@ void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_D
XG(sandbox) = NULL;
#ifdef XCACHE_ERROR_CACHING
EG(user_error_handler_error_reporting) = sandbox->orig_user_error_handler_error_reporting;
zend_error_cb = sandbox->orig_zend_error_cb;
#endif
/* restore first first install function/class */
@ -1015,3 +1031,25 @@ long xc_atol(const char *str, int str_len) /* {{{ */
/* }}} */
#endif
/* init/destroy */
int xc_util_init(int module_number TSRMLS_DC) /* {{{ */
{
#ifdef XCACHE_ERROR_CACHING
old_zend_error_cb = zend_error_cb;
zend_error_cb = xc_sandbox_error_cb;
#endif
return SUCCESS;
}
/* }}} */
void xc_util_destroy() /* {{{ */
{
#ifdef XCACHE_ERROR_CACHING
if (zend_error_cb == xc_sandbox_error_cb) {
zend_error_cb = old_zend_error_cb;
}
#endif
}
/* }}} */

4
utils.h

@ -40,6 +40,9 @@ static inline int TRACE_DUMMY(const char *fmt, ...)
#endif /* XCACHE_DEBUG */
#include <assert.h>
int xc_util_init(int module_number TSRMLS_DC);
void xc_util_destroy();
typedef struct {
int alloc;
zend_op_array *op_array;
@ -103,7 +106,6 @@ typedef struct {
#ifdef XCACHE_ERROR_CACHING
int orig_user_error_handler_error_reporting;
void (*orig_zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
zend_uint compilererror_cnt;
zend_uint compilererror_size;
xc_compilererror_t *compilererrors;

2
xcache.c

@ -3734,6 +3734,7 @@ static PHP_MINIT_FUNCTION(xcache)
#endif
}
xc_util_init(module_number TSRMLS_CC);
#ifdef HAVE_XCACHE_COVERAGER
xc_coverager_init(module_number TSRMLS_CC);
#endif
@ -3762,6 +3763,7 @@ static PHP_MSHUTDOWN_FUNCTION(xcache)
#ifdef HAVE_XCACHE_COVERAGER
xc_coverager_destroy();
#endif
xc_util_destroy();
if (xc_coredump_dir && xc_coredump_dir[0]) {
xcache_restore_signal_handler();

Loading…
Cancel
Save