rasmus Tue Mar 18 21:42:51 2008 UTC
Modified files: (Branch: PHP_5_3)
/ZendEngine2 zend_execute.h zend_execute_API.c
/php-src/main SAPI.c SAPI.h main.c php_globals.h
/php-src/sapi/apache mod_php5.c
Log:
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.
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_execute.h?r1=1.84.2.4.2.8.2.7&r2=1.84.2.4.2.8.2.8&diff_format=u
Index: ZendEngine2/zend_execute.h
diff -u ZendEngine2/zend_execute.h:1.84.2.4.2.8.2.7
ZendEngine2/zend_execute.h:1.84.2.4.2.8.2.8
--- ZendEngine2/zend_execute.h:1.84.2.4.2.8.2.7 Tue Mar 18 14:10:43 2008
+++ ZendEngine2/zend_execute.h Tue Mar 18 21:42:49 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_execute.h,v 1.84.2.4.2.8.2.7 2008/03/18 14:10:43 felipe Exp $ */
+/* $Id: zend_execute.h,v 1.84.2.4.2.8.2.8 2008/03/18 21:42:49 rasmus Exp $ */
#ifndef ZEND_EXECUTE_H
#define ZEND_EXECUTE_H
@@ -300,7 +300,7 @@
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(const char *class_name, uint
class_name_len, int fetch_type TSRMLS_DC);
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_execute_API.c?r1=1.331.2.20.2.24.2.30&r2=1.331.2.20.2.24.2.31&diff_format=u
Index: ZendEngine2/zend_execute_API.c
diff -u ZendEngine2/zend_execute_API.c:1.331.2.20.2.24.2.30
ZendEngine2/zend_execute_API.c:1.331.2.20.2.24.2.31
--- ZendEngine2/zend_execute_API.c:1.331.2.20.2.24.2.30 Tue Mar 18 14:10:43 2008
+++ ZendEngine2/zend_execute_API.c Tue Mar 18 21:42:50 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_execute_API.c,v 1.331.2.20.2.24.2.30 2008/03/18 14:10:43 felipe
Exp $ */
+/* $Id: zend_execute_API.c,v 1.331.2.20.2.24.2.31 2008/03/18 21:42:50 rasmus
Exp $ */
#include <stdio.h>
#include <signal.h>
@@ -1527,7 +1527,7 @@
#define SIGPROF 27
#endif
-void zend_set_timeout(long seconds) /* {{{ */
+void zend_set_timeout(long seconds, int reset_signals) /* {{{ */
{
TSRMLS_FETCH();
@@ -1554,16 +1554,22 @@
# ifdef __CYGWIN__
setitimer(ITIMER_REAL, &t_r, NULL);
- signal(SIGALRM, zend_timeout);
- sigemptyset(&sigset);
- sigaddset(&sigset, SIGALRM);
+ 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);
+ 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
http://cvs.php.net/viewvc.cgi/php-src/main/SAPI.c?r1=1.202.2.7.2.15.2.3&r2=1.202.2.7.2.15.2.4&diff_format=u
Index: php-src/main/SAPI.c
diff -u php-src/main/SAPI.c:1.202.2.7.2.15.2.3
php-src/main/SAPI.c:1.202.2.7.2.15.2.4
--- php-src/main/SAPI.c:1.202.2.7.2.15.2.3 Mon Jan 28 16:09:08 2008
+++ php-src/main/SAPI.c Tue Mar 18 21:42:50 2008
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: SAPI.c,v 1.202.2.7.2.15.2.3 2008/01/28 16:09:08 scottmac Exp $ */
+/* $Id: SAPI.c,v 1.202.2.7.2.15.2.4 2008/03/18 21:42:50 rasmus Exp $ */
#include <ctype.h>
#include <sys/stat.h>
@@ -1002,6 +1002,12 @@
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
http://cvs.php.net/viewvc.cgi/php-src/main/SAPI.h?r1=1.114.2.1.2.3.2.2&r2=1.114.2.1.2.3.2.3&diff_format=u
Index: php-src/main/SAPI.h
diff -u php-src/main/SAPI.h:1.114.2.1.2.3.2.2
php-src/main/SAPI.h:1.114.2.1.2.3.2.3
--- php-src/main/SAPI.h:1.114.2.1.2.3.2.2 Wed Jan 30 09:41:12 2008
+++ php-src/main/SAPI.h Tue Mar 18 21:42:50 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: SAPI.h,v 1.114.2.1.2.3.2.2 2008/01/30 09:41:12 dmitry Exp $ */
+/* $Id: SAPI.h,v 1.114.2.1.2.3.2.3 2008/03/18 21:42:50 rasmus Exp $ */
#ifndef SAPI_H
#define SAPI_H
@@ -207,6 +207,7 @@
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 @@
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;
http://cvs.php.net/viewvc.cgi/php-src/main/main.c?r1=1.640.2.23.2.57.2.16&r2=1.640.2.23.2.57.2.17&diff_format=u
Index: php-src/main/main.c
diff -u php-src/main/main.c:1.640.2.23.2.57.2.16
php-src/main/main.c:1.640.2.23.2.57.2.17
--- php-src/main/main.c:1.640.2.23.2.57.2.16 Tue Mar 18 14:10:45 2008
+++ php-src/main/main.c Tue Mar 18 21:42:50 2008
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: main.c,v 1.640.2.23.2.57.2.16 2008/03/18 14:10:45 felipe Exp $ */
+/* $Id: main.c,v 1.640.2.23.2.57.2.17 2008/03/18 21:42:50 rasmus Exp $ */
/* {{{ includes
*/
@@ -209,7 +209,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
#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);
http://cvs.php.net/viewvc.cgi/php-src/main/php_globals.h?r1=1.98.2.1.2.7.2.4&r2=1.98.2.1.2.7.2.5&diff_format=u
Index: php-src/main/php_globals.h
diff -u php-src/main/php_globals.h:1.98.2.1.2.7.2.4
php-src/main/php_globals.h:1.98.2.1.2.7.2.5
--- php-src/main/php_globals.h:1.98.2.1.2.7.2.4 Wed Mar 12 20:24:45 2008
+++ php-src/main/php_globals.h Tue Mar 18 21:42:50 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_globals.h,v 1.98.2.1.2.7.2.4 2008/03/12 20:24:45 stas Exp $ */
+/* $Id: php_globals.h,v 1.98.2.1.2.7.2.5 2008/03/18 21:42:50 rasmus Exp $ */
#ifndef PHP_GLOBALS_H
#define PHP_GLOBALS_H
@@ -154,6 +154,7 @@
char *disable_functions;
char *disable_classes;
zend_bool allow_url_include;
+ zend_bool exit_on_timeout;
#ifdef PHP_WIN32
zend_bool com_initialized;
#endif
http://cvs.php.net/viewvc.cgi/php-src/sapi/apache/mod_php5.c?r1=1.19.2.7.2.13.2.4&r2=1.19.2.7.2.13.2.5&diff_format=u
Index: php-src/sapi/apache/mod_php5.c
diff -u php-src/sapi/apache/mod_php5.c:1.19.2.7.2.13.2.4
php-src/sapi/apache/mod_php5.c:1.19.2.7.2.13.2.5
--- php-src/sapi/apache/mod_php5.c:1.19.2.7.2.13.2.4 Mon Mar 17 18:27:08 2008
+++ php-src/sapi/apache/mod_php5.c Tue Mar 18 21:42:50 2008
@@ -17,7 +17,7 @@
| PHP 4.0 patches by Zeev Suraski <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: mod_php5.c,v 1.19.2.7.2.13.2.4 2008/03/17 18:27:08 rasmus Exp $ */
+/* $Id: mod_php5.c,v 1.19.2.7.2.13.2.5 2008/03/18 21:42:50 rasmus Exp $ */
#include "php_apache_http.h"
#include "http_conf_globals.h"
@@ -434,6 +434,14 @@
}
/* }}} */
+/* {{{ 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 = {
@@ -463,6 +471,7 @@
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 */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php