--- embedaddon/php/main/main.c 2012/05/29 12:34:35 1.1.1.2 +++ embedaddon/php/main/main.c 2013/07/22 01:32:11 1.1.1.3 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2012 The PHP Group | + | Copyright (c) 1997-2013 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: main.c,v 1.1.1.2 2012/05/29 12:34:35 misho Exp $ */ +/* $Id: main.c,v 1.1.1.3 2013/07/22 01:32:11 misho Exp $ */ /* {{{ includes */ @@ -257,7 +257,7 @@ static void php_disable_classes(TSRMLS_D) /* {{{ php_binary_init */ -static void php_binary_init(TSRMLS_D) +static void php_binary_init(TSRMLS_D) { char *binary_location; #ifdef PHP_WIN32 @@ -597,6 +597,7 @@ PHPAPI int php_get_module_initialized(void) { return module_initialized; } +/* }}} */ /* {{{ php_log_err */ @@ -627,7 +628,15 @@ PHPAPI void php_log_err(char *log_message TSRMLS_DC) char *error_time_str; time(&error_time); - error_time_str = php_format_date("d-M-Y H:i:s e", 13, error_time, 0 TSRMLS_CC); +#ifdef ZTS + if (!php_during_module_startup()) { + error_time_str = php_format_date("d-M-Y H:i:s e", 13, error_time, 1 TSRMLS_CC); + } else { + error_time_str = php_format_date("d-M-Y H:i:s e", 13, error_time, 0 TSRMLS_CC); + } +#else + error_time_str = php_format_date("d-M-Y H:i:s e", 13, error_time, 1 TSRMLS_CC); +#endif len = spprintf(&tmp, 0, "[%s] %s%s", error_time_str, log_message, PHP_EOL); #ifdef PHP_WIN32 php_flock(fd, 2); @@ -836,7 +845,7 @@ PHPAPI void php_verror(const char *docref, const char efree(docref_buf); } - if (PG(track_errors) && module_initialized && + if (PG(track_errors) && module_initialized && (!EG(user_error_handler) || !(EG(user_error_handler_error_reporting) & type))) { if (!EG(active_symbol_table)) { zend_rebuild_symbol_table(TSRMLS_C); @@ -953,7 +962,7 @@ static void php_error_cb(int type, const char *error_f /* store the error if it has changed */ if (display) { #ifdef ZEND_SIGNALS - HANDLE_BLOCK_INTERRUPTIONS(); + HANDLE_BLOCK_INTERRUPTIONS(); #endif if (PG(last_error_message)) { free(PG(last_error_message)); @@ -1080,7 +1089,7 @@ static void php_error_cb(int type, const char *error_f PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR ) { #ifdef PHP_WIN32 - fprintf(stderr, "%s: %s in %s on line%d\n", error_type_str, buffer, error_filename, error_lineno); + fprintf(stderr, "%s: %s in %s on line %d\n", error_type_str, buffer, error_filename, error_lineno); fflush(stderr); #else fprintf(stderr, "%s: %s in %s on line %d\n", error_type_str, buffer, error_filename, error_lineno); @@ -1124,11 +1133,20 @@ static void php_error_cb(int type, const char *error_f case E_PARSE: case E_COMPILE_ERROR: case E_USER_ERROR: - EG(exit_status) = 255; + { /* new block to allow variable definition */ + /* eval() errors do not affect exit_status or response code */ + zend_bool during_eval = (type == E_PARSE) && (EG(current_execute_data) && + EG(current_execute_data)->opline && + EG(current_execute_data)->opline->opcode == ZEND_INCLUDE_OR_EVAL && + EG(current_execute_data)->opline->extended_value == ZEND_EVAL); + if (!during_eval) { + EG(exit_status) = 255; + } if (module_initialized) { if (!PG(display_errors) && !SG(headers_sent) && - SG(sapi_headers).http_response_code == 200 + SG(sapi_headers).http_response_code == 200 && + !during_eval ) { sapi_header_line ctr = {0}; @@ -1149,6 +1167,7 @@ static void php_error_cb(int type, const char *error_f } } break; + } } /* Log if necessary */ @@ -1202,7 +1221,7 @@ PHPAPI char *php_get_current_user(TSRMLS_D) name[len] = '\0'; SG(request_info).current_user_length = len; SG(request_info).current_user = estrndup(name, len); - return SG(request_info).current_user; + return SG(request_info).current_user; #else struct passwd *pwd; #if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX) @@ -1230,9 +1249,9 @@ PHPAPI char *php_get_current_user(TSRMLS_D) #if defined(ZTS) && defined(HAVE_GETPWUID_R) && defined(_SC_GETPW_R_SIZE_MAX) efree(pwbuf); #endif - return SG(request_info).current_user; + return SG(request_info).current_user; #endif - } + } } /* }}} */ @@ -1247,7 +1266,7 @@ PHP_FUNCTION(set_time_limit) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &new_timeout) == FAILURE) { return; } - + new_timeout_strlen = zend_spprintf(&new_timeout_str, 0, "%ld", new_timeout); if (zend_alter_ini_entry_ex("max_execution_time", sizeof("max_execution_time"), new_timeout_str, new_timeout_strlen, PHP_INI_USER, PHP_INI_STAGE_RUNTIME, 0 TSRMLS_CC) == SUCCESS) { @@ -1740,22 +1759,22 @@ void php_request_shutdown(void *dummy) } } zend_end_try(); - /* 4. Shutdown output layer (send the set HTTP headers, cleanup output handlers, etc.) */ + /* 4. Reset max_execution_time (no longer executing php code after response sent) */ zend_try { - php_output_deactivate(TSRMLS_C); - } zend_end_try(); - - /* 5. Reset max_execution_time (no longer executing php code after response sent) */ - zend_try { zend_unset_timeout(TSRMLS_C); } zend_end_try(); - /* 6. Call all extensions RSHUTDOWN functions */ + /* 5. Call all extensions RSHUTDOWN functions */ if (PG(modules_activated)) { zend_deactivate_modules(TSRMLS_C); php_free_shutdown_functions(TSRMLS_C); } + /* 6. Shutdown output layer (send the set HTTP headers, cleanup output handlers, etc.) */ + zend_try { + php_output_deactivate(TSRMLS_C); + } zend_end_try(); + /* 7. Destroy super-globals */ zend_try { int i; @@ -1881,7 +1900,7 @@ static void core_globals_dtor(php_core_globals *core_g PHP_MINFO_FUNCTION(php_core) { /* {{{ */ php_info_print_table_start(); php_info_print_table_row(2, "PHP Version", PHP_VERSION); - php_info_print_table_end(); + php_info_print_table_end(); DISPLAY_INI_ENTRIES(); } /* }}} */ @@ -2051,6 +2070,8 @@ int php_module_startup(sapi_module_struct *sf, zend_mo EG(exception_class) = NULL; PG(disable_functions) = NULL; PG(disable_classes) = NULL; + EG(exception) = NULL; + EG(objects_store).object_buckets = NULL; #if HAVE_SETLOCALE setlocale(LC_CTYPE, ""); @@ -2157,7 +2178,7 @@ int php_module_startup(sapi_module_struct *sf, zend_mo return FAILURE; } - /* initialize registry for images to be used in phpinfo() + /* initialize registry for images to be used in phpinfo() (this uses configuration parameters from php.ini) */ if (php_init_info_logos() == FAILURE) { @@ -2203,7 +2224,7 @@ int php_module_startup(sapi_module_struct *sf, zend_mo EG(current_module) = NULL; } } - + /* disable certain classes and functions as requested by php.ini */ php_disable_functions(TSRMLS_C); php_disable_classes(TSRMLS_C); @@ -2238,38 +2259,38 @@ int php_module_startup(sapi_module_struct *sf, zend_mo const char *directives[16]; /* Remember to change this if the number of directives change */ } directives[2] = { { - E_DEPRECATED, - "Directive '%s' is deprecated in PHP 5.3 and greater", + E_DEPRECATED, + "Directive '%s' is deprecated in PHP 5.3 and greater", { NULL } - }, + }, { - E_CORE_ERROR, - "Directive '%s' is no longer available in PHP", + E_CORE_ERROR, + "Directive '%s' is no longer available in PHP", { "allow_call_time_pass_reference", - "define_syslog_variables", - "highlight.bg", - "magic_quotes_gpc", - "magic_quotes_runtime", - "magic_quotes_sybase", - "register_globals", - "register_long_arrays", - "safe_mode", - "safe_mode_gid", - "safe_mode_include_dir", - "safe_mode_exec_dir", - "safe_mode_allowed_env_vars", - "safe_mode_protected_env_vars", - "zend.ze1_compatibility_mode", + "define_syslog_variables", + "highlight.bg", + "magic_quotes_gpc", + "magic_quotes_runtime", + "magic_quotes_sybase", + "register_globals", + "register_long_arrays", + "safe_mode", + "safe_mode_gid", + "safe_mode_include_dir", + "safe_mode_exec_dir", + "safe_mode_allowed_env_vars", + "safe_mode_protected_env_vars", + "zend.ze1_compatibility_mode", NULL } } }; unsigned int i; - + zend_try { /* 2 = Count of deprecation structs */ for (i = 0; i < 2; i++) { @@ -2289,7 +2310,7 @@ int php_module_startup(sapi_module_struct *sf, zend_mo retval = FAILURE; } zend_end_try(); } - + sapi_deactivate(TSRMLS_C); module_startup = 0; @@ -2344,7 +2365,7 @@ void php_module_shutdown(TSRMLS_D) sapi_flush(TSRMLS_C); zend_shutdown(TSRMLS_C); - + /* Destroys filter & transport registries too */ php_shutdown_stream_wrappers(module_number TSRMLS_CC); @@ -2388,7 +2409,7 @@ PHPAPI int php_execute_script(zend_file_handle *primar zend_file_handle *prepend_file_p, *append_file_p; zend_file_handle prepend_file = {0}, append_file = {0}; #if HAVE_BROKEN_GETCWD - int old_cwd_fd = -1; + volatile int old_cwd_fd = -1; #else char *old_cwd; ALLOCA_FLAG(use_heap)