dmitry                                   Mon, 05 Oct 2009 13:56:49 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=289214

Log:
Fixed bug #49627 (error_log to specified file does not log time according to 
date.timezone)

Bug: http://bugs.php.net/49627 (Assigned) error_log to specified file does not 
log time according to date.timezone
      
Changed paths:
    U   php/php-src/branches/PHP_5_2/NEWS
    U   php/php-src/branches/PHP_5_2/ext/date/php_date.c
    U   php/php-src/branches/PHP_5_2/main/main.c
    U   php/php-src/branches/PHP_5_2/main/php_globals.h
    U   php/php-src/branches/PHP_5_3/ext/date/php_date.c
    U   php/php-src/branches/PHP_5_3/main/main.c
    U   php/php-src/branches/PHP_5_3/main/php_globals.h
    U   php/php-src/trunk/ext/date/php_date.c
    U   php/php-src/trunk/main/main.c
    U   php/php-src/trunk/main/php_globals.h

Modified: php/php-src/branches/PHP_5_2/NEWS
===================================================================
--- php/php-src/branches/PHP_5_2/NEWS	2009-10-05 13:00:29 UTC (rev 289213)
+++ php/php-src/branches/PHP_5_2/NEWS	2009-10-05 13:56:49 UTC (rev 289214)
@@ -8,6 +8,8 @@
 - Fixed bug #49698 (Unexpected change in strnatcasecmp()). (Rasmus)
 - Fixed bug #49647 (DOMUserData does not exist). (Rob)
 - Fixed bug #49630 (imap_listscan function missing). (Felipe)
+- Fixed bug #49627 (error_log to specified file does not log time according
+  to date.timezone). (Dmitry)
 - Fixed bug #49578 (make install-pear fails). (Hannes)
 - Fixed bug #49536 (mb_detect_encoding() returns incorrect results when
   mbstring.strict_mode is turned on). (Moriyoshi)

Modified: php/php-src/branches/PHP_5_2/ext/date/php_date.c
===================================================================
--- php/php-src/branches/PHP_5_2/ext/date/php_date.c	2009-10-05 13:00:29 UTC (rev 289213)
+++ php/php-src/branches/PHP_5_2/ext/date/php_date.c	2009-10-05 13:56:49 UTC (rev 289214)
@@ -596,7 +596,17 @@
 		return env;
 	}
 	/* Check config setting for default timezone */
-	if (DATEG(default_timezone) && (strlen(DATEG(default_timezone)) > 0) && timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) {
+	if (!DATEG(default_timezone)) {
+		/* Special case: ext/date wasn't initialized yet */
+		zval ztz;
+
+		if (SUCCESS == zend_get_configuration_directive("date.timezone", sizeof("date.timezone"), &ztz) &&
+		    Z_TYPE(ztz) == IS_STRING &&
+		    Z_STRLEN(ztz) > 0 &&
+		    timelib_timezone_id_is_valid(Z_STRVAL(ztz), tzdb)) {
+			return Z_STRVAL(ztz);
+		}
+	} else if (*DATEG(default_timezone) && timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) {
 		return DATEG(default_timezone);
 	}
 #if HAVE_TM_ZONE

Modified: php/php-src/branches/PHP_5_2/main/main.c
===================================================================
--- php/php-src/branches/PHP_5_2/main/main.c	2009-10-05 13:00:29 UTC (rev 289213)
+++ php/php-src/branches/PHP_5_2/main/main.c	2009-10-05 13:56:49 UTC (rev 289214)
@@ -489,11 +489,18 @@
 	int fd = -1;
 	time_t error_time;

+	if (PG(in_error_log)) {
+		/* prevent recursive invocation */
+		return;
+	}
+	PG(in_error_log) = 1;
+
 	/* Try to use the specified logging location. */
 	if (PG(error_log) != NULL) {
 #ifdef HAVE_SYSLOG_H
 		if (!strcmp(PG(error_log), "syslog")) {
 			php_syslog(LOG_NOTICE, "%.500s", log_message);
+			PG(in_error_log) = 0;
 			return;
 		}
 #endif
@@ -504,7 +511,7 @@
 			char *error_time_str;

 			time(&error_time);
-			error_time_str = php_format_date("d-M-Y H:i:s", 11, error_time, php_during_module_startup() TSRMLS_CC);
+			error_time_str = php_format_date("d-M-Y H:i:s", 11, error_time, 1 TSRMLS_CC);
 			len = spprintf(&tmp, 0, "[%s] %s%s", error_time_str, log_message, PHP_EOL);
 #ifdef PHP_WIN32
 			php_flock(fd, 2);
@@ -513,6 +520,7 @@
 			efree(tmp);
 			efree(error_time_str);
 			close(fd);
+			PG(in_error_log) = 0;
 			return;
 		}
 	}
@@ -522,6 +530,7 @@
 	if (sapi_module.log_message) {
 		sapi_module.log_message(log_message);
 	}
+	PG(in_error_log) = 0;
 }
 /* }}} */

@@ -1255,6 +1264,7 @@
 #endif

 	zend_try {
+		PG(in_error_log) = 0;
 		PG(during_request_startup) = 1;

 		php_output_activate(TSRMLS_C);

Modified: php/php-src/branches/PHP_5_2/main/php_globals.h
===================================================================
--- php/php-src/branches/PHP_5_2/main/php_globals.h	2009-10-05 13:00:29 UTC (rev 289213)
+++ php/php-src/branches/PHP_5_2/main/php_globals.h	2009-10-05 13:56:49 UTC (rev 289214)
@@ -161,6 +161,7 @@
 #endif
 	long max_input_nesting_level;
 	zend_bool in_user_include;
+	zend_bool in_error_log;
 };



Modified: php/php-src/branches/PHP_5_3/ext/date/php_date.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/date/php_date.c	2009-10-05 13:00:29 UTC (rev 289213)
+++ php/php-src/branches/PHP_5_3/ext/date/php_date.c	2009-10-05 13:56:49 UTC (rev 289214)
@@ -849,7 +849,17 @@
 		return env;
 	}
 	/* Check config setting for default timezone */
-	if (DATEG(default_timezone) && (strlen(DATEG(default_timezone)) > 0) && timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) {
+	if (!DATEG(default_timezone)) {
+		/* Special case: ext/date wasn't initialized yet */
+		zval ztz;
+
+		if (SUCCESS == zend_get_configuration_directive("date.timezone", sizeof("date.timezone"), &ztz) &&
+		    Z_TYPE(ztz) == IS_STRING &&
+		    Z_STRLEN(ztz) > 0 &&
+		    timelib_timezone_id_is_valid(Z_STRVAL(ztz), tzdb)) {
+			return Z_STRVAL(ztz);
+		}
+	} else if (*DATEG(default_timezone) && timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) {
 		return DATEG(default_timezone);
 	}
 #if HAVE_TM_ZONE

Modified: php/php-src/branches/PHP_5_3/main/main.c
===================================================================
--- php/php-src/branches/PHP_5_3/main/main.c	2009-10-05 13:00:29 UTC (rev 289213)
+++ php/php-src/branches/PHP_5_3/main/main.c	2009-10-05 13:56:49 UTC (rev 289214)
@@ -556,11 +556,18 @@
 	int fd = -1;
 	time_t error_time;

+	if (PG(in_error_log)) {
+		/* prevent recursive invocation */
+		return;
+	}
+	PG(in_error_log) = 1;
+
 	/* Try to use the specified logging location. */
 	if (PG(error_log) != NULL) {
 #ifdef HAVE_SYSLOG_H
 		if (!strcmp(PG(error_log), "syslog")) {
 			php_syslog(LOG_NOTICE, "%.500s", log_message);
+			PG(in_error_log) = 0;
 			return;
 		}
 #endif
@@ -571,7 +578,7 @@
 			char *error_time_str;

 			time(&error_time);
-			error_time_str = php_format_date("d-M-Y H:i:s", 11, error_time, php_during_module_startup() TSRMLS_CC);
+			error_time_str = php_format_date("d-M-Y H:i:s", 11, error_time, 1 TSRMLS_CC);
 			len = spprintf(&tmp, 0, "[%s] %s%s", error_time_str, log_message, PHP_EOL);
 #ifdef PHP_WIN32
 			php_flock(fd, 2);
@@ -580,6 +587,7 @@
 			efree(tmp);
 			efree(error_time_str);
 			close(fd);
+			PG(in_error_log) = 0;
 			return;
 		}
 	}
@@ -589,6 +597,7 @@
 	if (sapi_module.log_message) {
 		sapi_module.log_message(log_message);
 	}
+	PG(in_error_log) = 0;
 }
 /* }}} */

@@ -1352,6 +1361,7 @@
 #endif

 	zend_try {
+		PG(in_error_log) = 0;
 		PG(during_request_startup) = 1;

 		php_output_activate(TSRMLS_C);

Modified: php/php-src/branches/PHP_5_3/main/php_globals.h
===================================================================
--- php/php-src/branches/PHP_5_3/main/php_globals.h	2009-10-05 13:00:29 UTC (rev 289213)
+++ php/php-src/branches/PHP_5_3/main/php_globals.h	2009-10-05 13:56:49 UTC (rev 289214)
@@ -168,6 +168,8 @@

 	zend_bool mail_x_header;
 	char *mail_log;
+
+	zend_bool in_error_log;
 };



Modified: php/php-src/trunk/ext/date/php_date.c
===================================================================
--- php/php-src/trunk/ext/date/php_date.c	2009-10-05 13:00:29 UTC (rev 289213)
+++ php/php-src/trunk/ext/date/php_date.c	2009-10-05 13:56:49 UTC (rev 289214)
@@ -845,7 +845,17 @@
 		return DATEG(timezone);
 	}
 	/* Check config setting for default timezone */
-	if (DATEG(default_timezone) && (strlen(DATEG(default_timezone)) > 0) && timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) {
+	if (!DATEG(default_timezone)) {
+		/* Special case: ext/date wasn't initialized yet */
+		zval ztz;
+
+		if (SUCCESS == zend_get_configuration_directive("date.timezone", sizeof("date.timezone"), &ztz) &&
+		    Z_TYPE(ztz) == IS_STRING &&
+		    Z_STRLEN(ztz) > 0 &&
+		    timelib_timezone_id_is_valid(Z_STRVAL(ztz), tzdb)) {
+			return Z_STRVAL(ztz);
+		}
+	} else if (*DATEG(default_timezone) && timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) {
 		return DATEG(default_timezone);
 	}
 #if HAVE_TM_ZONE

Modified: php/php-src/trunk/main/main.c
===================================================================
--- php/php-src/trunk/main/main.c	2009-10-05 13:00:29 UTC (rev 289213)
+++ php/php-src/trunk/main/main.c	2009-10-05 13:56:49 UTC (rev 289214)
@@ -643,11 +643,18 @@
 	int fd = -1;
 	time_t error_time;

+	if (PG(in_error_log)) {
+		/* prevent recursive invocation */
+		return;
+	}
+	PG(in_error_log) = 1;
+
 	/* Try to use the specified logging location. */
 	if (PG(error_log) != NULL) {
 #ifdef HAVE_SYSLOG_H
 		if (!strcmp(PG(error_log), "syslog")) {
 			php_syslog(LOG_NOTICE, "%.500s", log_message);
+			PG(in_error_log) = 0;
 			return;
 		}
 #endif
@@ -658,7 +665,7 @@
 			char *error_time_str;

 			time(&error_time);
-			error_time_str = php_format_date("d-M-Y H:i:s", 11, error_time, php_during_module_startup() TSRMLS_CC);
+			error_time_str = php_format_date("d-M-Y H:i:s", 11, error_time, 1 TSRMLS_CC);
 			len = spprintf(&tmp, 0, "[%s] %s%s", error_time_str, log_message, PHP_EOL);
 #ifdef PHP_WIN32
 			php_flock(fd, 2);
@@ -667,6 +674,7 @@
 			efree(tmp);
 			efree(error_time_str);
 			close(fd);
+			PG(in_error_log) = 0;
 			return;
 		}
 	}
@@ -676,6 +684,7 @@
 	if (sapi_module.log_message) {
 		sapi_module.log_message(log_message);
 	}
+	PG(in_error_log) = 0;
 }
 /* }}} */

@@ -1454,6 +1463,7 @@
 #endif

 	zend_try {
+		PG(in_error_log) = 0;
 		PG(during_request_startup) = 1;

 		php_output_activate(TSRMLS_C);

Modified: php/php-src/trunk/main/php_globals.h
===================================================================
--- php/php-src/trunk/main/php_globals.h	2009-10-05 13:00:29 UTC (rev 289213)
+++ php/php-src/trunk/main/php_globals.h	2009-10-05 13:56:49 UTC (rev 289214)
@@ -156,6 +156,7 @@
 	char *mail_log;

 	zend_bool request_decoding_error;
+	zend_bool in_error_log;
 };


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to