mirror of
https://github.com/php/php-src.git
synced 2024-12-13 20:05:26 +08:00
MFB
Here are the signal changes from the 5.3 branch that optimizes signal handler registration and switches from longjmp to siglongjmp in order to make signal mask handling consistent across different UNIX operating systems.
This commit is contained in:
parent
c604a1933c
commit
b911467d1d
@ -110,7 +110,7 @@ dnl Checks for library functions.
|
||||
AC_FUNC_VPRINTF
|
||||
AC_FUNC_MEMCMP
|
||||
AC_FUNC_ALLOCA
|
||||
AC_CHECK_FUNCS(memcpy strdup getpid kill strtod strtol finite fpclass)
|
||||
AC_CHECK_FUNCS(memcpy strdup getpid kill strtod strtol finite fpclass sigsetjmp)
|
||||
AC_ZEND_BROKEN_SPRINTF
|
||||
|
||||
AC_CHECK_FUNCS(finite isfinite isinf isnan)
|
||||
|
@ -1273,7 +1273,7 @@ ZEND_API void _zend_bailout(char *filename, uint lineno) /* {{{ */
|
||||
CG(unclean_shutdown) = 1;
|
||||
CG(in_compilation) = EG(in_execution) = 0;
|
||||
EG(current_execute_data) = NULL;
|
||||
longjmp(*EG(bailout), FAILURE);
|
||||
LONGJMP(*EG(bailout), FAILURE);
|
||||
}
|
||||
/* }}} */
|
||||
END_EXTERN_C()
|
||||
|
16
Zend/zend.h
16
Zend/zend.h
@ -566,13 +566,23 @@ END_EXTERN_C()
|
||||
|
||||
#define zend_bailout() _zend_bailout(__FILE__, __LINE__)
|
||||
|
||||
#ifdef HAVE_SIGSETJMP
|
||||
# define SETJMP(a) sigsetjmp(a, 0)
|
||||
# define LONGJMP(a,b) siglongjmp(a, b)
|
||||
# define JMP_BUF sigjmp_buf
|
||||
#else
|
||||
# define SETJMP(a) setjmp(a)
|
||||
# define LONGJMP(a,b) longjmp(a, b)
|
||||
# define JMP_BUF jmp_buf
|
||||
#endif
|
||||
|
||||
#define zend_try \
|
||||
{ \
|
||||
jmp_buf *__orig_bailout = EG(bailout); \
|
||||
jmp_buf __bailout; \
|
||||
JMP_BUF *__orig_bailout = EG(bailout); \
|
||||
JMP_BUF __bailout; \
|
||||
\
|
||||
EG(bailout) = &__bailout; \
|
||||
if (setjmp(__bailout)==0) {
|
||||
if (SETJMP(__bailout)==0) {
|
||||
#define zend_catch \
|
||||
} else { \
|
||||
EG(bailout) = __orig_bailout;
|
||||
|
@ -317,7 +317,7 @@ ZEND_API char *zend_get_executed_filename(TSRMLS_D);
|
||||
ZEND_API uint zend_get_executed_lineno(TSRMLS_D);
|
||||
ZEND_API zend_bool zend_is_executing(TSRMLS_D);
|
||||
|
||||
ZEND_API void zend_set_timeout(long seconds);
|
||||
ZEND_API void zend_set_timeout(long seconds, int reset_signals);
|
||||
ZEND_API void zend_unset_timeout(TSRMLS_D);
|
||||
ZEND_API void zend_timeout(int dummy);
|
||||
ZEND_API zend_class_entry *zend_fetch_class(char *class_name, uint class_name_len, int fetch_type TSRMLS_DC);
|
||||
|
@ -1710,15 +1710,15 @@ void zend_shutdown_timeout_thread(void) /* {{{ */
|
||||
#define SIGPROF 27
|
||||
#endif
|
||||
|
||||
void zend_set_timeout(long seconds) /* {{{ */
|
||||
void zend_set_timeout(long seconds, int reset_signals) /* {{{ */
|
||||
{
|
||||
TSRMLS_FETCH();
|
||||
|
||||
EG(timeout_seconds) = seconds;
|
||||
#ifdef ZEND_WIN32
|
||||
if(!seconds) {
|
||||
return;
|
||||
}
|
||||
#ifdef ZEND_WIN32
|
||||
if (timeout_thread_initialized == 0 && InterlockedIncrement(&timeout_thread_initialized) == 1) {
|
||||
/* We start up this process-wide thread here and not in zend_startup(), because if Zend
|
||||
* is initialized inside a DllMain(), you're not supposed to start threads from it.
|
||||
@ -1731,22 +1731,30 @@ void zend_set_timeout(long seconds) /* {{{ */
|
||||
{
|
||||
struct itimerval t_r; /* timeout requested */
|
||||
sigset_t sigset;
|
||||
|
||||
t_r.it_value.tv_sec = seconds;
|
||||
t_r.it_value.tv_usec = t_r.it_interval.tv_sec = t_r.it_interval.tv_usec = 0;
|
||||
if(seconds) {
|
||||
t_r.it_value.tv_sec = seconds;
|
||||
t_r.it_value.tv_usec = t_r.it_interval.tv_sec = t_r.it_interval.tv_usec = 0;
|
||||
|
||||
# ifdef __CYGWIN__
|
||||
setitimer(ITIMER_REAL, &t_r, NULL);
|
||||
signal(SIGALRM, zend_timeout);
|
||||
sigemptyset(&sigset);
|
||||
sigaddset(&sigset, SIGALRM);
|
||||
setitimer(ITIMER_REAL, &t_r, NULL);
|
||||
}
|
||||
if(reset_signals) {
|
||||
signal(SIGALRM, zend_timeout);
|
||||
sigemptyset(&sigset);
|
||||
sigaddset(&sigset, SIGALRM);
|
||||
}
|
||||
# else
|
||||
setitimer(ITIMER_PROF, &t_r, NULL);
|
||||
signal(SIGPROF, zend_timeout);
|
||||
sigemptyset(&sigset);
|
||||
sigaddset(&sigset, SIGPROF);
|
||||
setitimer(ITIMER_PROF, &t_r, NULL);
|
||||
}
|
||||
if(reset_signals) {
|
||||
signal(SIGPROF, zend_timeout);
|
||||
sigemptyset(&sigset);
|
||||
sigaddset(&sigset, SIGPROF);
|
||||
}
|
||||
# endif
|
||||
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
|
||||
if(reset_signals) {
|
||||
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
@ -170,7 +170,7 @@ struct _zend_executor_globals {
|
||||
|
||||
HashTable included_files; /* files already included */
|
||||
|
||||
jmp_buf *bailout;
|
||||
JMP_BUF *bailout;
|
||||
|
||||
int error_reporting;
|
||||
int orig_error_reporting;
|
||||
|
@ -933,6 +933,12 @@ SAPI_API time_t sapi_get_request_time(TSRMLS_D)
|
||||
return SG(global_request_time);
|
||||
}
|
||||
|
||||
SAPI_API void sapi_terminate_process(TSRMLS_D) {
|
||||
if (sapi_module.terminate_process) {
|
||||
sapi_module.terminate_process(TSRMLS_C);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
|
@ -208,6 +208,7 @@ SAPI_API int sapi_force_http_10(TSRMLS_D);
|
||||
SAPI_API int sapi_get_target_uid(uid_t * TSRMLS_DC);
|
||||
SAPI_API int sapi_get_target_gid(gid_t * TSRMLS_DC);
|
||||
SAPI_API time_t sapi_get_request_time(TSRMLS_D);
|
||||
SAPI_API void sapi_terminate_process(TSRMLS_D);
|
||||
END_EXTERN_C()
|
||||
|
||||
struct _sapi_module_struct {
|
||||
@ -237,6 +238,7 @@ struct _sapi_module_struct {
|
||||
void (*register_server_variables)(zval *track_vars_array TSRMLS_DC);
|
||||
void (*log_message)(char *message);
|
||||
time_t (*get_request_time)(TSRMLS_D);
|
||||
void (*terminate_process)(TSRMLS_D);
|
||||
|
||||
char *php_ini_path_override;
|
||||
|
||||
|
14
main/main.c
14
main/main.c
@ -208,7 +208,7 @@ static PHP_INI_MH(OnUpdateTimeout)
|
||||
return SUCCESS;
|
||||
}
|
||||
zend_unset_timeout(TSRMLS_C);
|
||||
zend_set_timeout(EG(timeout_seconds));
|
||||
zend_set_timeout(EG(timeout_seconds), 0);
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
@ -554,6 +554,7 @@ PHP_INI_BEGIN()
|
||||
|
||||
STD_PHP_INI_ENTRY("user_ini.filename", ".user.ini", PHP_INI_SYSTEM, OnUpdateString, user_ini_filename, php_core_globals, core_globals)
|
||||
STD_PHP_INI_ENTRY("user_ini.cache_ttl", "300", PHP_INI_SYSTEM, OnUpdateLong, user_ini_cache_ttl, php_core_globals, core_globals)
|
||||
STD_PHP_INI_BOOLEAN("exit_on_timeout", "0", PHP_INI_ALL, OnUpdateBool, exit_on_timeout, php_core_globals, core_globals)
|
||||
PHP_INI_END()
|
||||
/* }}} */
|
||||
|
||||
@ -1309,7 +1310,8 @@ static void php_message_handler_for_zend(long message, void *data)
|
||||
void php_on_timeout(int seconds TSRMLS_DC) /* {{{ */
|
||||
{
|
||||
PG(connection_status) |= PHP_CONNECTION_TIMEOUT;
|
||||
zend_set_timeout(EG(timeout_seconds));
|
||||
zend_set_timeout(EG(timeout_seconds), 0);
|
||||
if(PG(exit_on_timeout)) sapi_terminate_process(TSRMLS_C);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -1340,7 +1342,7 @@ static int php_start_sapi(TSRMLS_D)
|
||||
PG(connection_status) = PHP_CONNECTION_NORMAL;
|
||||
|
||||
zend_activate(TSRMLS_C);
|
||||
zend_set_timeout(EG(timeout_seconds));
|
||||
zend_set_timeout(EG(timeout_seconds), 1);
|
||||
zend_activate_modules(TSRMLS_C);
|
||||
PG(modules_activated)=1;
|
||||
} zend_catch {
|
||||
@ -1384,9 +1386,9 @@ int php_request_startup(TSRMLS_D)
|
||||
sapi_activate(TSRMLS_C);
|
||||
|
||||
if (PG(max_input_time) == -1) {
|
||||
zend_set_timeout(EG(timeout_seconds));
|
||||
zend_set_timeout(EG(timeout_seconds), 1);
|
||||
} else {
|
||||
zend_set_timeout(PG(max_input_time));
|
||||
zend_set_timeout(PG(max_input_time), 1);
|
||||
}
|
||||
|
||||
/* Disable realpath cache if safe_mode or open_basedir are set */
|
||||
@ -2191,7 +2193,7 @@ PHPAPI int php_execute_script(zend_file_handle *primary_file TSRMLS_DC)
|
||||
#ifdef PHP_WIN32
|
||||
zend_unset_timeout(TSRMLS_C);
|
||||
#endif
|
||||
zend_set_timeout(INI_INT("max_execution_time"));
|
||||
zend_set_timeout(EG(timeout_seconds), 0);
|
||||
}
|
||||
retval = (zend_execute_scripts(ZEND_REQUIRE TSRMLS_CC, NULL, 3, prepend_file_p, primary_file, append_file_p) == SUCCESS);
|
||||
|
||||
|
@ -140,6 +140,7 @@ struct _php_core_globals {
|
||||
|
||||
char *disable_functions;
|
||||
char *disable_classes;
|
||||
zend_bool exit_on_timeout;
|
||||
#ifdef PHP_WIN32
|
||||
zend_bool com_initialized;
|
||||
#endif
|
||||
|
@ -386,6 +386,7 @@ static sapi_module_struct aolserver_sapi_module = {
|
||||
php_ns_sapi_register_variables,
|
||||
NULL, /* Log message */
|
||||
NULL, /* Get request time */
|
||||
NULL, /* child terminate */
|
||||
|
||||
STANDARD_SAPI_MODULE_PROPERTIES
|
||||
};
|
||||
|
@ -431,6 +431,14 @@ static time_t php_apache_get_request_time(TSRMLS_D)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ sapi_apache_child_terminate
|
||||
*/
|
||||
static void sapi_apache_child_terminate(TSRMLS_D)
|
||||
{
|
||||
ap_child_terminate((request_rec *)SG(server_context));
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ sapi_module_struct apache_sapi_module
|
||||
*/
|
||||
static sapi_module_struct apache_sapi_module = {
|
||||
@ -460,6 +468,7 @@ static sapi_module_struct apache_sapi_module = {
|
||||
sapi_apache_register_server_variables, /* register server variables */
|
||||
php_apache_log_message, /* Log message */
|
||||
php_apache_get_request_time, /* Get request time */
|
||||
sapi_apache_child_terminate,
|
||||
|
||||
NULL, /* php.ini path override */
|
||||
|
||||
|
@ -343,6 +343,7 @@ static sapi_module_struct apache2_sapi_module = {
|
||||
php_apache_sapi_register_variables,
|
||||
php_apache_sapi_log_message, /* Log message */
|
||||
php_apache_sapi_get_request_time, /* Get Request Time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
STANDARD_SAPI_MODULE_PROPERTIES
|
||||
};
|
||||
|
@ -343,6 +343,7 @@ static sapi_module_struct apache2_sapi_module = {
|
||||
php_apache_sapi_register_variables,
|
||||
php_apache_sapi_log_message, /* Log message */
|
||||
php_apache_sapi_get_request_time, /* Request Time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
STANDARD_SAPI_MODULE_PROPERTIES
|
||||
};
|
||||
|
@ -521,6 +521,7 @@ static sapi_module_struct apache_sapi_module = {
|
||||
sapi_apache_register_server_variables, /* register server variables */
|
||||
php_apache_log_message, /* Log message */
|
||||
NULL, /* Get request time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
NULL, /* php.ini path override */
|
||||
|
||||
|
@ -551,6 +551,7 @@ static sapi_module_struct caudium_sapi_module = {
|
||||
sapi_caudium_register_variables, /* register server variables */
|
||||
NULL, /* Log message */
|
||||
NULL, /* Get request time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
STANDARD_SAPI_MODULE_PROPERTIES
|
||||
};
|
||||
|
@ -806,6 +806,7 @@ static sapi_module_struct cgi_sapi_module = {
|
||||
sapi_cgi_register_variables, /* register server variables */
|
||||
sapi_cgi_log_message, /* Log message */
|
||||
NULL, /* Get request time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
STANDARD_SAPI_MODULE_PROPERTIES
|
||||
};
|
||||
|
@ -412,6 +412,7 @@ static sapi_module_struct cli_sapi_module = {
|
||||
sapi_cli_register_variables, /* register server variables */
|
||||
sapi_cli_log_message, /* Log message */
|
||||
NULL, /* Get request time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
STANDARD_SAPI_MODULE_PROPERTIES
|
||||
};
|
||||
|
@ -378,7 +378,8 @@ sapi_module_struct capi_sapi_module = {
|
||||
|
||||
sapi_capi_register_server_variables, /* register server variables */
|
||||
capi_log_message, /* Log message */
|
||||
NULL, /* Get request time */
|
||||
NULL, /* Get request time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
NULL, /* Block interruptions */
|
||||
NULL, /* Unblock interruptions */
|
||||
|
@ -135,6 +135,7 @@ sapi_module_struct php_embed_module = {
|
||||
php_embed_register_variables, /* register server variables */
|
||||
php_embed_log_message, /* Log message */
|
||||
NULL, /* Get request time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
STANDARD_SAPI_MODULE_PROPERTIES
|
||||
};
|
||||
|
@ -688,6 +688,7 @@ static sapi_module_struct isapi_sapi_module = {
|
||||
sapi_isapi_register_server_variables, /* register server variables */
|
||||
NULL, /* Log message */
|
||||
NULL, /* Get request time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
STANDARD_SAPI_MODULE_PROPERTIES
|
||||
};
|
||||
|
@ -869,6 +869,7 @@ static sapi_module_struct milter_sapi_module = {
|
||||
sapi_milter_register_variables, /* register server variables */
|
||||
NULL, /* Log message */
|
||||
NULL, /* Get request time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
NULL, /* Block interruptions */
|
||||
NULL, /* Unblock interruptions */
|
||||
|
@ -753,6 +753,7 @@ static sapi_module_struct nsapi_sapi_module = {
|
||||
sapi_nsapi_register_server_variables, /* register server variables */
|
||||
nsapi_log_message, /* Log message */
|
||||
sapi_nsapi_get_request_time, /* Get request time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
NULL, /* Block interruptions */
|
||||
NULL, /* Unblock interruptions */
|
||||
|
@ -180,6 +180,7 @@ static sapi_module_struct phttpd_sapi_module = {
|
||||
NULL, /* register server variables */
|
||||
NULL, /* Log message */
|
||||
NULL, /* Get request time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
STANDARD_SAPI_MODULE_PROPERTIES
|
||||
};
|
||||
|
@ -337,6 +337,7 @@ static sapi_module_struct pi3web_sapi_module = {
|
||||
sapi_pi3web_register_variables, /* register server variables */
|
||||
NULL, /* Log message */
|
||||
NULL, /* Get request time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
STANDARD_SAPI_MODULE_PROPERTIES
|
||||
};
|
||||
|
@ -502,6 +502,7 @@ static sapi_module_struct roxen_sapi_module = {
|
||||
NULL, /* register server variables */
|
||||
NULL, /* Log message */
|
||||
NULL, /* Get request time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
STANDARD_SAPI_MODULE_PROPERTIES
|
||||
};
|
||||
|
@ -394,6 +394,7 @@ static sapi_module_struct thttpd_sapi_module = {
|
||||
sapi_thttpd_register_variables,
|
||||
NULL, /* Log message */
|
||||
NULL, /* Get request time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
NULL, /* php.ini path override */
|
||||
NULL, /* Block interruptions */
|
||||
|
@ -288,6 +288,7 @@ static sapi_module_struct tux_sapi_module = {
|
||||
sapi_tux_register_variables,
|
||||
NULL, /* Log message */
|
||||
NULL, /* Get request time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
STANDARD_SAPI_MODULE_PROPERTIES
|
||||
};
|
||||
|
@ -301,6 +301,7 @@ static sapi_module_struct sapi_module = {
|
||||
sapi_webjames_register_variables, /* register server variables */
|
||||
NULL, /* Log message */
|
||||
NULL, /* Get request time */
|
||||
NULL, /* Child terminate */
|
||||
|
||||
STANDARD_SAPI_MODULE_PROPERTIES
|
||||
};
|
||||
|
@ -53,6 +53,7 @@
|
||||
#define NEED_ISBLANK 1
|
||||
#define DISCARD_PATH 0
|
||||
#undef HAVE_SETITIMER
|
||||
#undef HAVE_SIGSETJMP
|
||||
#undef HAVE_IODBC
|
||||
#define HAVE_LIBDL 1
|
||||
#define HAVE_GETTIMEOFDAY 1
|
||||
|
Loading…
Reference in New Issue
Block a user