Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:17260 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85477 invoked by uid 1010); 14 Jul 2005 08:19:41 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 85461 invoked from network); 14 Jul 2005 08:19:41 -0000 Received: from unknown (HELO lerdorf.com) (127.0.0.1) by localhost with SMTP; 14 Jul 2005 08:19:41 -0000 X-Host-Fingerprint: 204.11.219.139 lerdorf.com Linux 2.4/2.6 Received: from ([204.11.219.139:40275] helo=colo.lerdorf.com) by pb1.pair.com (ecelerity 1.2 r(5656M)) with SMTP id BA/4C-23681-C1026D24 for ; Thu, 14 Jul 2005 04:19:41 -0400 Received: from [192.168.2.106] (c-24-6-1-160.hsd1.ca.comcast.net [24.6.1.160]) (authenticated bits=0) by colo.lerdorf.com (8.13.4/8.13.4/Debian-3) with ESMTP id j6E8Ja3e027864 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 14 Jul 2005 01:19:36 -0700 Message-ID: <42D62017.9010103@lerdorf.com> Date: Thu, 14 Jul 2005 01:19:35 -0700 User-Agent: Mozilla Thunderbird 1.0.2 (Macintosh/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: internals@lists.php.net CC: jorton@redhat.com X-Enigmail-Version: 0.91.0.0 Content-Type: multipart/mixed; boundary="------------070906020901030401030400" Subject: Apache2 patch sanity check From: rasmus@lerdorf.com (Rasmus Lerdorf) --------------070906020901030401030400 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit This patch is to fix http://bugs.php.net/33690 which is caused by the fact that php_handler() in sapi/apache2handler/sapi_apache.c calls apply_config() well before it has allocated SG(server_context) and set ctx->r to the current request_rec. Downstream from that any ini handler that needs something from SG(server_context) is thus out of luck. Following the chain up the backtrace in bug #33690 should make that very clear if you didn't follow my bad explanation. So, this patch simply moves the allocation of the context up before the call to apply_config(). It's not my sapi, and I still don't run Apache2 in anger anywhere, so I'd appreciate a quick sanity check. -Rasmus --------------070906020901030401030400 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="a2.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="a2.txt" ? o Index: sapi_apache2.c =================================================================== RCS file: /repository/php-src/sapi/apache2handler/sapi_apache2.c,v retrieving revision 1.1.2.40 diff -u -r1.1.2.40 sapi_apache2.c --- sapi_apache2.c 8 Apr 2005 20:35:02 -0000 1.1.2.40 +++ sapi_apache2.c 14 Jul 2005 08:08:58 -0000 @@ -276,6 +276,11 @@ } } +static time_t php_apache_sapi_get_request_time(TSRMLS_D) { + php_struct *ctx = SG(server_context); + return apr_time_sec(ctx->r->request_time); +} + static void php_apache_sapi_log_message_ex(char *msg, request_rec *r) { if (r) { @@ -321,7 +326,7 @@ php_apache_sapi_register_variables, php_apache_sapi_log_message, /* Log message */ - + php_apache_sapi_get_request_time, STANDARD_SAPI_MODULE_PROPERTIES }; @@ -454,6 +459,21 @@ TSRMLS_FETCH(); conf = ap_get_module_config(r->per_dir_config, &php4_module); + + /* apply_config() needs r in some cases, so allocate server_context early */ + ctx = SG(server_context); + if (ctx == NULL) { + ctx = SG(server_context) = apr_pcalloc(r->pool, sizeof(*ctx)); + /* register a cleanup so we clear out the SG(server_context) + * after each request. Note: We pass in the pointer to the + * server_context in case this is handled by a different thread. + */ + apr_pool_cleanup_register(r->pool, (void *)&SG(server_context), php_server_context_cleanup, apr_pool_cleanup_null); + ctx->r = r; + ctx = NULL; /* May look weird to null it here, but it is to catch the right case in the first_try later on */ + } else { + ctx->r = r; + } apply_config(conf); if (strcmp(r->handler, PHP_MAGIC_TYPE) && strcmp(r->handler, PHP_SOURCE_MAGIC_TYPE) && strcmp(r->handler, PHP_SCRIPT)) { @@ -511,17 +531,9 @@ zend_first_try { - ctx = SG(server_context); if (ctx == NULL) { - ctx = SG(server_context) = apr_pcalloc(r->pool, sizeof(*ctx)); - /* register a cleanup so we clear out the SG(server_context) - * after each request. Note: We pass in the pointer to the - * server_context in case this is handled by a different thread. - */ - apr_pool_cleanup_register(r->pool, (void *)&SG(server_context), php_server_context_cleanup, apr_pool_cleanup_null); - - ctx->r = r; brigade = apr_brigade_create(r->pool, r->connection->bucket_alloc); + ctx = SG(server_context); ctx->brigade = brigade; if (php_apache_request_ctor(r, ctx TSRMLS_CC)!=SUCCESS) { --------------070906020901030401030400--