diff options
| author | Rasmus Lerdorf <rasmus@php.net> | 2008-03-18 21:42:50 +0000 |
|---|---|---|
| committer | Rasmus Lerdorf <rasmus@php.net> | 2008-03-18 21:42:50 +0000 |
| commit | 6c158374ba57792b0e283053e0a22944a42ef25b (patch) | |
| tree | 2a45ed6760070254817be81a96ae26f3ed491b86 /main | |
| parent | 10afe5d96bc3d562958e905102de1db44188ac2b (diff) | |
| download | php-git-6c158374ba57792b0e283053e0a22944a42ef25b.tar.gz | |
exit_on_timeout patch
After the sigsetjmp change, this is patch #2 in an effort to get some
sanity restored to signal handling in PHP.
This patch does two things. First, it makes it possible to reset the
timeout without resetting the signal handlers. This is important for
cases where an extension may have deferred signals in its MINIT in order
to implement critical sections. It also lays the groundwork for cleaning
up our signal handling and perhaps eventually implementing our own
signal deferring mechanism so we can have true critical sections.
The second thing this does is to make it possible to terminate the current
child process (only for Apache1 at the moment) on a timeout. There are
a number of extensions that are unhappy about being longjmp'ed out of
and when this happens on a timeout they are left in an inconsistent state.
By turning on exit_on_timeout you can now force the process to terminate
on a timeout which will clean up any hanging locks and/or memory left
hanging after the longjmp.
Diffstat (limited to 'main')
| -rw-r--r-- | main/SAPI.c | 6 | ||||
| -rw-r--r-- | main/SAPI.h | 2 | ||||
| -rw-r--r-- | main/main.c | 14 | ||||
| -rw-r--r-- | main/php_globals.h | 1 |
4 files changed, 17 insertions, 6 deletions
diff --git a/main/SAPI.c b/main/SAPI.c index a5699252b1..feabcef549 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -1002,6 +1002,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 diff --git a/main/SAPI.h b/main/SAPI.h index 39a9a85b26..d4a558e3e7 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -207,6 +207,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 { @@ -236,6 +237,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; diff --git a/main/main.c b/main/main.c index 5b8e334ed8..e86ca796b3 100644 --- a/main/main.c +++ b/main/main.c @@ -209,7 +209,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; } /* }}} */ @@ -461,6 +461,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() /* }}} */ @@ -1229,7 +1230,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); } #if PHP_SIGCHILD @@ -1259,7 +1261,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 { @@ -1303,9 +1305,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 */ @@ -2070,7 +2072,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); diff --git a/main/php_globals.h b/main/php_globals.h index 0c9ccff5df..53863104c6 100644 --- a/main/php_globals.h +++ b/main/php_globals.h @@ -154,6 +154,7 @@ struct _php_core_globals { char *disable_functions; char *disable_classes; zend_bool allow_url_include; + zend_bool exit_on_timeout; #ifdef PHP_WIN32 zend_bool com_initialized; #endif |
