]> granicus.if.org Git - php/commitdiff
MFB
authorRasmus Lerdorf <rasmus@php.net>
Wed, 19 Mar 2008 16:37:49 +0000 (16:37 +0000)
committerRasmus Lerdorf <rasmus@php.net>
Wed, 19 Mar 2008 16:37:49 +0000 (16:37 +0000)
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.

30 files changed:
Zend/Zend.m4
Zend/zend.c
Zend/zend.h
Zend/zend_execute.h
Zend/zend_execute_API.c
Zend/zend_globals.h
main/SAPI.c
main/SAPI.h
main/main.c
main/php_globals.h
sapi/aolserver/aolserver.c
sapi/apache/mod_php.c
sapi/apache2filter/sapi_apache2.c
sapi/apache2handler/sapi_apache2.c
sapi/apache_hooks/mod_php5.c
sapi/caudium/caudium.c
sapi/cgi/cgi_main.c
sapi/cli/php_cli.c
sapi/continuity/capi.c
sapi/embed/php_embed.c
sapi/isapi/php5isapi.c
sapi/milter/php_milter.c
sapi/nsapi/nsapi.c
sapi/phttpd/phttpd.c
sapi/pi3web/pi3web_sapi.c
sapi/roxen/roxen.c
sapi/thttpd/thttpd.c
sapi/tux/php_tux.c
sapi/webjames/webjames.c
win32/build/config.w32.h.in

index 9c95754f33eb2d49ededc4cc65bbe5d168b8bfb1..fe0110e341b8928f0dbedd29ad51a4caae14f4e4 100644 (file)
@@ -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)
index 2c5c9a78c69d2fe537e0930bff4c5bb353882d5d..19007cf778df0e62d707f4112f9d4e137cba948e 100644 (file)
@@ -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()
index ea79ea996607d017a09f35776c4251a1d860563f..7c9eb2e310a6f017c15889f6af20c69a6d4ccf4c 100644 (file)
@@ -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;
index ad92cb2e13587d752f060f4b987272c4348ef87f..18bc0b6e9f96234eb80bc2af2443d18817988b81 100644 (file)
@@ -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);
index 09d4b1cf7cb4e93cec23ce9da5cbe1470b99d729..549209b655998377397c0f705c2c1ffa689bb3bf 100644 (file)
@@ -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
index 3feb64dd52dbf5623bc0f3e49be0247d02047235..e2f21e4284ed1991631fd945501af3c8a83994f5 100644 (file)
@@ -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;
index f4c8d7525ee959bad258b56521276ffca5312f16..1ee7971903f7fc8b8b2843a337b457a33ee0c903 100644 (file)
@@ -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
index b7e1366eb351eb0f3388bde286cdcf96051c25a7..ff89c31a0cad8c6a60719e906b128a35b2bd7916 100644 (file)
@@ -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;
 
index 18b03fde9e6f4c67aebaa7c55faf676fa8509291..e375464d404a7c7d8e2d6900898d54b0189c5fca 100644 (file)
@@ -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);
 
index b37ea5f3ab2bb15679ebd5cb04fe1b350a9a2927..5d7916a3fb07ca41187d92243c8af54bf48f581c 100644 (file)
@@ -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
index a3eeed35222a70569357377af8c2b3aadad79240..d0b84d3f86dcc513de5c36249b2f6295cc57e279 100644 (file)
@@ -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
 };
index 7947c8127ae2d5a13bf9a241ba8c0c328a002d86..937cac31596b3889f73c035d79fd50d2c7332571 100644 (file)
@@ -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 */
 
index 4427f1e334f26ce57fc5de083f9c1a61e5f4a035..10dc21555cc2ac6b83296c94e587159b2d21776c 100644 (file)
@@ -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
 };
index 171101250d21c716aed645652b8fb5c10f831d0b..9773c581f300802699d941f67315b5662cf24516 100644 (file)
@@ -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
 };
index bbbe70769b0637242de49a84798d5b9aba366bd8..3b180ef040dc2f69b5d8d04f0af2745deb3a31fa 100644 (file)
@@ -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 */
 
index 197448a43365f248ea0ee328816563f0ed411581..9bbd4190508a193db32486bde80084cfa70d72b5 100644 (file)
@@ -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
 };
index 75638d41e18a6e1d40d92e242c6ee1c60ffc538a..ad061490fdcaedc70086dc3669f4f65af6e4f8e0 100644 (file)
@@ -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
 };
index 05ee0cc05c9293a39e1018d0779772294cafe1c1..8aad625450dc157c12f54afd6df7f7e95ca23ef1 100644 (file)
@@ -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
 };
index 3908499b2736247f6bfc5a6673792b385b4b792b..a419e1b8966ad55e39e46433232fbdf357734125 100644 (file)
@@ -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 */
index dfd069e557320561860a0f9087f749a9579066f8..7e8eccbe40d3ae872294de7d48607dc021b9833c 100644 (file)
@@ -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
 };
index 0bfa51b4cb0e5e114ccdd45c68cd6de978cea205..959d85f48d45f48214b53cfae1619c0a1965b12f 100644 (file)
@@ -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
 };
index 966651e77208b18d5b1e16933649b31ac11af538..088922cdf5faa344995f433a25e1d00eb027bc83 100644 (file)
@@ -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 */
index fa116a72f57847fadc899e5fb15dd29b58187f9c..47ca41080c9e0eadad6fda79dcabcc6c15c0dbbc 100644 (file)
@@ -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 */
index ed4b3fd57f6b5af94b7f99c212659fa4a06cea20..c2a4166f2d56cd06bfb8f99bff6e4d4d23f86e63 100644 (file)
@@ -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
 };
index 6365f5ee0771336daabcf34f0f52ef296606d729..5c1f4ff99a49ba85d6731ba4479fb78b78c711e7 100644 (file)
@@ -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
 };
index 13155d49f46452ac49ed8a46f301292cc130f9f5..695262556ed29a6aff5f206b5eddeac07e32e161 100644 (file)
@@ -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
 };
index faa8f4f43fea11cba56d48f78140636c676f9a3b..32f81ab522fae73d497319cbd1a77100ed150c5a 100644 (file)
@@ -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 */
index 7d24367da6dd539697eaacf0bf508163225df8ee..68f0ce5d688ba94200e9f2d8b14b46d0a8b40e89 100644 (file)
@@ -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
 };
index f166eddfb8baa67fe71670d46120c256aaf7376c..2fb52f566191467eab33a03190ab8b03d7b511f8 100644 (file)
@@ -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
 };
index 91a4927321757a5450a0c2e82574ced594af3eca..8139d68dd093cd93c0e76bbbe92aa5d4ae1768f5 100644 (file)
@@ -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