diff options
Diffstat (limited to 'sapi')
38 files changed, 340 insertions, 210 deletions
diff --git a/sapi/apache2handler/php_apache.h b/sapi/apache2handler/php_apache.h index 201b1fc30a..c93e20c90f 100644 --- a/sapi/apache2handler/php_apache.h +++ b/sapi/apache2handler/php_apache.h @@ -46,11 +46,7 @@ typedef struct php_struct { request_rec *r; apr_bucket_brigade *brigade; /* stat structure of the current file */ -#if defined(NETWARE) && defined(CLIB_STAT_PATCH) - struct stat_libc finfo; -#else zend_stat_t finfo; -#endif /* Whether or not we've processed PHP in the output filters yet. */ int request_processed; /* final content type */ diff --git a/sapi/apache2handler/php_functions.c b/sapi/apache2handler/php_functions.c index f378997733..572aa98b2f 100644 --- a/sapi/apache2handler/php_functions.c +++ b/sapi/apache2handler/php_functions.c @@ -42,7 +42,7 @@ #include "util_script.h" #include "http_core.h" #include "ap_mpm.h" -#if !defined(WIN32) && !defined(WINNT) && !defined(NETWARE) +#if !defined(WIN32) && !defined(WINNT) #include "unixd.h" #endif @@ -371,7 +371,7 @@ PHP_MINFO_FUNCTION(apache) int n, max_requests; char *p; server_rec *serv = ((php_struct *) SG(server_context))->r->server; -#if !defined(WIN32) && !defined(WINNT) && !defined(NETWARE) +#if !defined(WIN32) && !defined(WINNT) #if MODULE_MAGIC_NUMBER_MAJOR >= 20081201 AP_DECLARE_DATA extern unixd_config_rec ap_unixd_config; #else @@ -410,7 +410,7 @@ PHP_MINFO_FUNCTION(apache) snprintf(tmp, sizeof(tmp), "%s:%u", serv->server_hostname, serv->port); php_info_print_table_row(2, "Hostname:Port", tmp); -#if !defined(WIN32) && !defined(WINNT) && !defined(NETWARE) +#if !defined(WIN32) && !defined(WINNT) #if MODULE_MAGIC_NUMBER_MAJOR >= 20081201 snprintf(tmp, sizeof(tmp), "%s(%d)/%d", ap_unixd_config.user_name, ap_unixd_config.user_id, ap_unixd_config.group_id); #else diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c index e7edcab6da..a4ee0cdcf6 100644 --- a/sapi/apache2handler/sapi_apache2.c +++ b/sapi/apache2handler/sapi_apache2.c @@ -31,11 +31,7 @@ #include <fcntl.h> #include "zend_smart_str.h" -#ifndef NETWARE #include "ext/standard/php_standard.h" -#else -#include "ext/standard/basic_functions.h" -#endif #include "apr_strings.h" #include "ap_config.h" @@ -53,9 +49,9 @@ #include "php_apache.h" -/* UnixWare and Netware define shutdown to _shutdown, which causes problems later +/* UnixWare define shutdown to _shutdown, which causes problems later * on when using a structure member named shutdown. Since this source - * file does not use the system call shutdown, it is safe to #undef it.K + * file does not use the system call shutdown, it is safe to #undef it. */ #undef shutdown @@ -223,16 +219,9 @@ php_apache_sapi_get_stat(void) #endif ctx->finfo.st_dev = ctx->r->finfo.device; ctx->finfo.st_ino = ctx->r->finfo.inode; -#if defined(NETWARE) && defined(CLIB_STAT_PATCH) - ctx->finfo.st_atime.tv_sec = apr_time_sec(ctx->r->finfo.atime); - ctx->finfo.st_mtime.tv_sec = apr_time_sec(ctx->r->finfo.mtime); - ctx->finfo.st_ctime.tv_sec = apr_time_sec(ctx->r->finfo.ctime); -#else ctx->finfo.st_atime = apr_time_sec(ctx->r->finfo.atime); ctx->finfo.st_mtime = apr_time_sec(ctx->r->finfo.mtime); ctx->finfo.st_ctime = apr_time_sec(ctx->r->finfo.ctime); -#endif - ctx->finfo.st_size = ctx->r->finfo.size; ctx->finfo.st_nlink = ctx->r->finfo.nlink; diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index b0f1c1b601..8800788117 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -96,6 +96,10 @@ int __riscosify_control = __RISCOSIFY_STRICT_UNIX_SPECS; # include "openssl/applink.c" #endif +#ifdef HAVE_VALGRIND +# include "valgrind/callgrind.h" +#endif + #ifndef PHP_WIN32 /* XXX this will need to change later when threaded fastcgi is implemented. shane */ struct sigaction act, old_term, old_quit, old_int; @@ -1824,16 +1828,6 @@ int main(int argc, char *argv[]) char *decoded_query_string; int skip_getopt = 0; -#if 0 && defined(PHP_DEBUG) - /* IIS is always making things more difficult. This allows - * us to stop PHP and attach a debugger before much gets started */ - { - char szMessage [256]; - wsprintf (szMessage, "Please attach a debugger to the process 0x%X [%d] (%s) and click OK", GetCurrentProcessId(), GetCurrentProcessId(), argv[0]); - MessageBox(NULL, szMessage, "CGI Debug Time!", MB_OK|MB_SERVICE_NOTIFICATION); - } -#endif - #ifdef HAVE_SIGNAL_H #if defined(SIGPIPE) && defined(SIG_IGN) signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE in standalone mode so @@ -2306,6 +2300,11 @@ consult the installation file that came with this distribution, or visit \n\ if (comma) { warmup_repeats = atoi(php_optarg); repeats = atoi(comma + 1); +#ifdef HAVE_VALGRIND + if (warmup_repeats > 0) { + CALLGRIND_STOP_INSTRUMENTATION; + } +#endif } else { repeats = atoi(php_optarg); } @@ -2517,7 +2516,7 @@ consult the installation file that came with this distribution, or visit \n\ file_handle.filename = SG(request_info).path_translated; file_handle.handle.fp = NULL; } else { - file_handle.filename = "-"; + file_handle.filename = "Standard input code"; file_handle.type = ZEND_HANDLE_FP; file_handle.handle.fp = stdin; } @@ -2728,6 +2727,9 @@ fastcgi_request_done: #else time(&start); #endif +#ifdef HAVE_VALGRIND + CALLGRIND_START_INSTRUMENTATION; +#endif } continue; } else { diff --git a/sapi/cgi/tests/002.phpt b/sapi/cgi/tests/002.phpt index 884e6521e2..fda8fcbe04 100644 --- a/sapi/cgi/tests/002.phpt +++ b/sapi/cgi/tests/002.phpt @@ -31,22 +31,22 @@ echo "Done\n"; string(%d) "X-Powered-By: PHP/%s Content-type: text/html%r; charset=.*|%r -%unicode|string%(3) "111" +string(3) "111" " string(%d) "X-Powered-By: PHP/%s Content-type: text/html%r; charset=.*|%r -%unicode|string%(3) "500" +string(3) "500" " string(%d) "X-Powered-By: PHP/%s Content-type: text/html%r; charset=.*|%r -%unicode|string%(3) "555" +string(3) "555" " string(%d) "X-Powered-By: PHP/%s Content-type: text/html%r; charset=.*|%r -%unicode|string%(3) "555" -%unicode|string%(10) "/test/path" +string(3) "555" +string(10) "/test/path" " Done diff --git a/sapi/cgi/tests/007.phpt b/sapi/cgi/tests/007.phpt index f2c9c0226c..841137a046 100644 --- a/sapi/cgi/tests/007.phpt +++ b/sapi/cgi/tests/007.phpt @@ -17,6 +17,6 @@ var_dump(`"$php" -n -s -w -l`); --EXPECTF-- string(25) "No input file specified. " -string(31) "No syntax errors detected in - +string(49) "No syntax errors detected in Standard input code " ===DONE=== diff --git a/sapi/cli/config.m4 b/sapi/cli/config.m4 index 04db2fecee..21681512a7 100644 --- a/sapi/cli/config.m4 +++ b/sapi/cli/config.m4 @@ -44,9 +44,6 @@ if test "$PHP_CLI" != "no"; then *darwin*) BUILD_CLI="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(NATIVE_RPATHS) \$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_BINARY_OBJS:.lo=.o) \$(PHP_CLI_OBJS:.lo=.o) \$(PHP_FRAMEWORKS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)" ;; - *netware*) - BUILD_CLI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_BINARY_OBJS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -Lnetware -lphp7lib -o \$(SAPI_CLI_PATH)" - ;; *) BUILD_CLI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_BINARY_OBJS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)" ;; diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 617539c155..b217b2731d 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -38,6 +38,7 @@ #ifdef PHP_WIN32 #include "win32/time.h" #include "win32/signal.h" +#include "win32/console.h" #include <process.h> #include <shellapi.h> #endif @@ -243,8 +244,11 @@ static void print_extensions(void) /* {{{ */ #ifndef STDOUT_FILENO #define STDOUT_FILENO 1 #endif +#ifndef STDERR_FILENO +#define STDERR_FILENO 2 +#endif -static inline int sapi_cli_select(int fd) +static inline int sapi_cli_select(php_socket_t fd) { fd_set wfd, dfd; struct timeval tv; @@ -910,6 +914,20 @@ static int do_cli(int argc, char **argv) /* {{{ */ goto err; } +#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE) && (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) + if (!interactive) { + /* The -a option was not passed. If there is no file, it could + still make sense to run interactively. The presense of a file + is essential to mitigate buggy console info. */ + interactive = php_win32_console_is_own() && + !(script_file || + argc > php_optind && behavior!=PHP_MODE_CLI_DIRECT && + behavior!=PHP_MODE_PROCESS_STDIN && + strcmp(argv[php_optind-1],"--") + ); + } +#endif + if (interactive) { #if (HAVE_LIBREADLINE || HAVE_LIBEDIT) && !defined(COMPILE_DL_READLINE) printf("Interactive shell\n\n"); @@ -944,7 +962,7 @@ static int do_cli(int argc, char **argv) /* {{{ */ /* here but this would make things only more complicated. And it */ /* is consitent with the way -R works where the stdin file handle*/ /* is also accessible. */ - file_handle.filename = "-"; + file_handle.filename = "Standard input code"; file_handle.handle.fp = stdin; } file_handle.type = ZEND_HANDLE_FP; @@ -983,7 +1001,7 @@ static int do_cli(int argc, char **argv) /* {{{ */ PG(during_request_startup) = 0; switch (behavior) { case PHP_MODE_STANDARD: - if (strcmp(file_handle.filename, "-")) { + if (strcmp(file_handle.filename, "Standard input code")) { cli_register_file_handles(); } @@ -1125,7 +1143,7 @@ static int do_cli(int argc, char **argv) /* {{{ */ } case PHP_MODE_REFLECTION_EXT_INFO: { - int len = (int)strlen(reflection_what); + size_t len = strlen(reflection_what); char *lcname = zend_str_tolower_dup(reflection_what, len); zend_module_entry *module; @@ -1201,7 +1219,7 @@ int main(int argc, char *argv[]) int php_optind = 1, use_extended_info = 0; char *ini_path_override = NULL; char *ini_entries = NULL; - int ini_entries_len = 0; + size_t ini_entries_len = 0; int ini_ignore = 0; sapi_module_struct *sapi_module = &cli_sapi_module; @@ -1211,6 +1229,11 @@ int main(int argc, char *argv[]) */ argv = save_ps_args(argc, argv); +#if defined(PHP_WIN32) && !defined(PHP_CLI_WIN32_NO_CONSOLE) + php_win32_console_fileno_set_vt100(STDOUT_FILENO, TRUE); + php_win32_console_fileno_set_vt100(STDERR_FILENO, TRUE); +#endif + cli_sapi_module.additional_functions = additional_functions; #if defined(PHP_WIN32) && defined(_DEBUG) && defined(PHP_WIN32_DEBUG_HEAP) @@ -1270,7 +1293,7 @@ int main(int argc, char *argv[]) break; case 'd': { /* define ini entries on command line */ - int len = (int)strlen(php_optarg); + size_t len = strlen(php_optarg); char *val; if ((val = strchr(php_optarg, '='))) { @@ -1278,11 +1301,11 @@ int main(int argc, char *argv[]) if (!isalnum(*val) && *val != '"' && *val != '\'' && *val != '\0') { ini_entries = realloc(ini_entries, ini_entries_len + len + sizeof("\"\"\n\0")); memcpy(ini_entries + ini_entries_len, php_optarg, (val - php_optarg)); - ini_entries_len += (int)(val - php_optarg); + ini_entries_len += (val - php_optarg); memcpy(ini_entries + ini_entries_len, "\"", 1); ini_entries_len++; memcpy(ini_entries + ini_entries_len, val, len - (val - php_optarg)); - ini_entries_len += len - (int)(val - php_optarg); + ini_entries_len += len - (val - php_optarg); memcpy(ini_entries + ini_entries_len, "\"\n\0", sizeof("\"\n\0")); ini_entries_len += sizeof("\n\0\"") - 2; } else { diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 5844cdfe8e..198afc8a6b 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -415,7 +415,7 @@ static void add_response_header(sapi_header_struct *h, zval *return_value) /* {{ do { p++; } while (*p == ' ' || *p == '\t'); - add_assoc_stringl_ex(return_value, s, (uint)len, p, h->header_len - (p - h->header)); + add_assoc_stringl_ex(return_value, s, (uint32_t)len, p, h->header_len - (p - h->header)); free_alloca(s, use_heap); } } @@ -609,7 +609,7 @@ static int sapi_cli_server_register_entry_cb(char **entry, int num_args, va_list zval *track_vars_array = va_arg(args, zval *); if (hash_key->key) { char *real_key, *key; - uint i; + uint32_t i; key = estrndup(ZSTR_VAL(hash_key->key), ZSTR_LEN(hash_key->key)); for(i=0; i<ZSTR_LEN(hash_key->key); i++) { if (key[i] == '-') { @@ -933,9 +933,6 @@ static size_t php_cli_server_buffer_size(const php_cli_server_buffer *buffer) /* static php_cli_server_chunk *php_cli_server_chunk_immortal_new(const char *buf, size_t len) /* {{{ */ { php_cli_server_chunk *chunk = pemalloc(sizeof(php_cli_server_chunk), 1); - if (!chunk) { - return NULL; - } chunk->type = PHP_CLI_SERVER_CHUNK_IMMORTAL; chunk->next = NULL; @@ -947,9 +944,6 @@ static php_cli_server_chunk *php_cli_server_chunk_immortal_new(const char *buf, static php_cli_server_chunk *php_cli_server_chunk_heap_new(void *block, char *buf, size_t len) /* {{{ */ { php_cli_server_chunk *chunk = pemalloc(sizeof(php_cli_server_chunk), 1); - if (!chunk) { - return NULL; - } chunk->type = PHP_CLI_SERVER_CHUNK_HEAP; chunk->next = NULL; @@ -962,9 +956,6 @@ static php_cli_server_chunk *php_cli_server_chunk_heap_new(void *block, char *bu static php_cli_server_chunk *php_cli_server_chunk_heap_new_self_contained(size_t len) /* {{{ */ { php_cli_server_chunk *chunk = pemalloc(sizeof(php_cli_server_chunk) + len, 1); - if (!chunk) { - return NULL; - } chunk->type = PHP_CLI_SERVER_CHUNK_HEAP; chunk->next = NULL; @@ -1220,12 +1211,6 @@ static php_socket_t php_network_listen_socket(const char *host, int *port, int s #if HAVE_GETADDRINFO && HAVE_IPV6 case AF_INET6: sa = pemalloc(sizeof(struct sockaddr_in6), 1); - if (!sa) { - closesocket(retval); - retval = SOCK_ERR; - *errstr = NULL; - goto out; - } *(struct sockaddr_in6 *)sa = *(struct sockaddr_in6 *)*p; ((struct sockaddr_in6 *)sa)->sin6_port = htons(*port); *socklen = sizeof(struct sockaddr_in6); @@ -1233,12 +1218,6 @@ static php_socket_t php_network_listen_socket(const char *host, int *port, int s #endif case AF_INET: sa = pemalloc(sizeof(struct sockaddr_in), 1); - if (!sa) { - closesocket(retval); - retval = SOCK_ERR; - *errstr = NULL; - goto out; - } *(struct sockaddr_in *)sa = *(struct sockaddr_in *)*p; ((struct sockaddr_in *)sa)->sin_port = htons(*port); *socklen = sizeof(struct sockaddr_in); @@ -1375,10 +1354,6 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque size_t prev_path_len = 0; int is_static_file = 0; - if (!buf) { - return; - } - memmove(p, document_root, document_root_len); p += document_root_len; vpath = p; @@ -1463,7 +1438,7 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque } #ifdef PHP_WIN32 { - uint i = 0; + uint32_t i = 0; for (;i<request->vpath_len;i++) { if (request->vpath[i] == '\\') { request->vpath[i] = '/'; @@ -1700,9 +1675,6 @@ static int php_cli_server_client_read_request_on_body(php_http_parser *parser, c php_cli_server_client *client = parser->data; if (!client->request.content) { client->request.content = pemalloc(parser->content_length, 1); - if (!client->request.content) { - return -1; - } client->request.content_len = 0; } client->request.content = perealloc(client->request.content, client->request.content_len + length, 1); @@ -1778,9 +1750,6 @@ static int php_cli_server_client_read_request(php_cli_server_client *client, cha } if (client->current_header_name) { char *header_name = safe_pemalloc(client->current_header_name_len, 1, 1, 1); - if (!header_name) { - return -1; - } memmove(header_name, client->current_header_name, client->current_header_name_len); client->current_header_name = header_name; client->current_header_name_allocated = 1; @@ -2460,9 +2429,6 @@ static int php_cli_server_do_event_for_each_fd_callback(void *_params, php_socke php_socket_t client_sock; socklen_t socklen = server->socklen; struct sockaddr *sa = pemalloc(server->socklen, 1); - if (!sa) { - return FAILURE; - } client_sock = accept(server->server_sock, sa, &socklen); if (!ZEND_VALID_SOCKET(client_sock)) { char *errstr; @@ -2477,7 +2443,8 @@ static int php_cli_server_do_event_for_each_fd_callback(void *_params, php_socke closesocket(client_sock); return SUCCESS; } - if (!(client = pemalloc(sizeof(php_cli_server_client), 1)) || FAILURE == php_cli_server_client_ctor(client, server, client_sock, sa, socklen)) { + client = pemalloc(sizeof(php_cli_server_client), 1); + if (FAILURE == php_cli_server_client_ctor(client, server, client_sock, sa, socklen)) { php_cli_server_logf("Failed to create a new request object"); pefree(sa, 1); closesocket(client_sock); diff --git a/sapi/cli/tests/006.phpt b/sapi/cli/tests/006.phpt index b24da56660..849a8b14e5 100644 --- a/sapi/cli/tests/006.phpt +++ b/sapi/cli/tests/006.phpt @@ -39,10 +39,11 @@ string(%d) "Extension [ <persistent> extension #%d pcre version %s ] { } } - - Constants [15] { + - Constants [16] { Constant [ integer PREG_PATTERN_ORDER ] { 1 } Constant [ integer PREG_SET_ORDER ] { 2 } Constant [ integer PREG_OFFSET_CAPTURE ] { 256 } + Constant [ integer PREG_UNMATCHED_AS_NULL ] { 512 } Constant [ integer PREG_SPLIT_NO_EMPTY ] { 1 } Constant [ integer PREG_SPLIT_DELIM_CAPTURE ] { 2 } Constant [ integer PREG_SPLIT_OFFSET_CAPTURE ] { 4 } diff --git a/sapi/cli/tests/015.phpt b/sapi/cli/tests/015.phpt index ab5918b4d2..62a007b6e4 100644 --- a/sapi/cli/tests/015.phpt +++ b/sapi/cli/tests/015.phpt @@ -24,7 +24,7 @@ echo "Done\n"; PHP %d.%d.%d%s(cli) (built: %s)%s Array ( - [0] => - + [0] => Standard input code [1] => foo [2] => bar [3] => baz diff --git a/sapi/cli/tests/php_cli_server_014.phpt b/sapi/cli/tests/php_cli_server_014.phpt index 7c50a5e30a..f308ffb226 100644 --- a/sapi/cli/tests/php_cli_server_014.phpt +++ b/sapi/cli/tests/php_cli_server_014.phpt @@ -7,7 +7,7 @@ include "skipif.inc"; --FILE-- <?php include "php_cli_server.inc"; -php_cli_server_start('echo done, "\n";', null); +php_cli_server_start('echo "done\n";', null); list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); $port = intval($port)?:80; diff --git a/sapi/fpm/.gitignore b/sapi/fpm/.gitignore new file mode 100644 index 0000000000..3f8c0913a4 --- /dev/null +++ b/sapi/fpm/.gitignore @@ -0,0 +1,4 @@ +php-fpm.8 +php-fpm.service +status.html +www.conf diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c index 0e3bb26c30..b93cd15fe7 100644 --- a/sapi/fpm/fpm/fpm_conf.c +++ b/sapi/fpm/fpm/fpm_conf.c @@ -147,6 +147,7 @@ static struct ini_value_parser_s ini_fpm_pool_options[] = { { "access.format", &fpm_conf_set_string, WPO(access_format) }, { "slowlog", &fpm_conf_set_string, WPO(slowlog) }, { "request_slowlog_timeout", &fpm_conf_set_time, WPO(request_slowlog_timeout) }, + { "request_slowlog_trace_depth", &fpm_conf_set_integer, WPO(request_slowlog_trace_depth) }, { "request_terminate_timeout", &fpm_conf_set_time, WPO(request_terminate_timeout) }, { "rlimit_files", &fpm_conf_set_integer, WPO(rlimit_files) }, { "rlimit_core", &fpm_conf_set_rlimit_core, WPO(rlimit_core) }, @@ -972,6 +973,30 @@ static int fpm_conf_process_all_pools() /* {{{ */ } } + /* request_slowlog_trace_depth */ + if (wp->config->request_slowlog_trace_depth) { +#if HAVE_FPM_TRACE + if (! (wp->config->slowlog && *wp->config->slowlog)) { + zlog(ZLOG_ERROR, "[pool %s] 'slowlog' must be specified for use with 'request_slowlog_trace_depth'", wp->config->name); + return -1; + } +#else + static int warned = 0; + + if (!warned) { + zlog(ZLOG_WARNING, "[pool %s] 'request_slowlog_trace_depth' is not supported on your system", wp->config->name); + warned = 1; + } +#endif + + if (wp->config->request_slowlog_trace_depth <= 0) { + zlog(ZLOG_ERROR, "[pool %s] 'request_slowlog_trace_depth' (%d) must be a positive value", wp->config->name, wp->config->request_slowlog_trace_depth); + return -1; + } + } else { + wp->config->request_slowlog_trace_depth = 20; + } + /* chroot */ if (wp->config->chroot && *wp->config->chroot) { @@ -1252,7 +1277,7 @@ static void fpm_conf_cleanup(int which, void *arg) /* {{{ */ static void fpm_conf_ini_parser_include(char *inc, void *arg) /* {{{ */ { char *filename; - int *error = (int *)arg;; + int *error = (int *)arg; #ifdef HAVE_GLOB glob_t g; #endif @@ -1467,17 +1492,17 @@ static void fpm_conf_ini_parser(zval *arg1, zval *arg2, zval *arg3, int callback switch(callback_type) { case ZEND_INI_PARSER_ENTRY: fpm_conf_ini_parser_entry(arg1, arg2, error); - break;; + break; case ZEND_INI_PARSER_SECTION: fpm_conf_ini_parser_section(arg1, error); - break;; + break; case ZEND_INI_PARSER_POP_ENTRY: fpm_conf_ini_parser_array(arg1, arg3, arg2, error); - break;; + break; default: zlog(ZLOG_ERROR, "[%s:%d] Unknown INI syntax", ini_filename, ini_lineno); *error = 1; - break;; + break; } } /* }}} */ @@ -1638,6 +1663,7 @@ static void fpm_conf_dump() /* {{{ */ zlog(ZLOG_NOTICE, "\taccess.format = %s", STR2STR(wp->config->access_format)); zlog(ZLOG_NOTICE, "\tslowlog = %s", STR2STR(wp->config->slowlog)); zlog(ZLOG_NOTICE, "\trequest_slowlog_timeout = %ds", wp->config->request_slowlog_timeout); + zlog(ZLOG_NOTICE, "\trequest_slowlog_trace_depth = %d", wp->config->request_slowlog_trace_depth); zlog(ZLOG_NOTICE, "\trequest_terminate_timeout = %ds", wp->config->request_terminate_timeout); zlog(ZLOG_NOTICE, "\trlimit_files = %d", wp->config->rlimit_files); zlog(ZLOG_NOTICE, "\trlimit_core = %d", wp->config->rlimit_core); diff --git a/sapi/fpm/fpm/fpm_conf.h b/sapi/fpm/fpm/fpm_conf.h index 4021cbc2e3..a0434b694d 100644 --- a/sapi/fpm/fpm/fpm_conf.h +++ b/sapi/fpm/fpm/fpm_conf.h @@ -79,6 +79,7 @@ struct fpm_worker_pool_config_s { char *access_format; char *slowlog; int request_slowlog_timeout; + int request_slowlog_trace_depth; int request_terminate_timeout; int rlimit_files; int rlimit_core; diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index 24a7e5d56a..f0cc3a07a4 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -280,7 +280,7 @@ static void print_extensions(void) /* {{{ */ #define STDOUT_FILENO 1 #endif -static inline size_t sapi_cgibin_single_write(const char *str, uint str_length) /* {{{ */ +static inline size_t sapi_cgibin_single_write(const char *str, uint32_t str_length) /* {{{ */ { ssize_t ret; @@ -310,7 +310,7 @@ static inline size_t sapi_cgibin_single_write(const char *str, uint str_length) static size_t sapi_cgibin_ub_write(const char *str, size_t str_length) /* {{{ */ { const char *ptr = str; - uint remaining = str_length; + uint32_t remaining = str_length; size_t ret; while (remaining > 0) { @@ -473,7 +473,7 @@ void fcgi_log(int type, const char *fmt, ...) static size_t sapi_cgi_read_post(char *buffer, size_t count_bytes) /* {{{ */ { - uint read_bytes = 0; + uint32_t read_bytes = 0; int tmp_read_bytes; size_t remaining = SG(request_info).content_length - SG(read_post_bytes); @@ -745,7 +745,7 @@ static int sapi_cgi_activate(void) /* {{{ */ { fcgi_request *request = (fcgi_request*) SG(server_context); char *path, *doc_root, *server_name; - uint path_len, doc_root_len, server_name_len; + uint32_t path_len, doc_root_len, server_name_len; /* PATH_TRANSLATED should be defined at this stage but better safe than sorry :) */ if (!SG(request_info).path_translated) { diff --git a/sapi/fpm/fpm/fpm_php.c b/sapi/fpm/fpm/fpm_php.c index e20276974d..11a5e25f24 100644 --- a/sapi/fpm/fpm/fpm_php.c +++ b/sapi/fpm/fpm/fpm_php.c @@ -38,7 +38,10 @@ static int fpm_php_zend_ini_alter_master(char *name, int name_length, char *new_ || ini_entry->on_modify(ini_entry, duplicate, ini_entry->mh_arg1, ini_entry->mh_arg2, ini_entry->mh_arg3, stage) == SUCCESS) { ini_entry->value = duplicate; - ini_entry->modifiable = mode; + /* when mode == ZEND_INI_USER keep unchanged to allow ZEND_INI_PERDIR (.user.ini) */ + if (mode == ZEND_INI_SYSTEM) { + ini_entry->modifiable = mode; + } } else { zend_string_release(duplicate); } diff --git a/sapi/fpm/fpm/fpm_php_trace.c b/sapi/fpm/fpm/fpm_php_trace.c index 4ab2db6e3f..b5d642f8a6 100644 --- a/sapi/fpm/fpm/fpm_php_trace.c +++ b/sapi/fpm/fpm/fpm_php_trace.c @@ -42,7 +42,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ */ { - int callers_limit = 20; + int callers_limit = child->wp->config->request_slowlog_trace_depth; pid_t pid = child->pid; struct timeval tv; static const int buf_size = 1024; @@ -80,7 +80,7 @@ static int fpm_php_trace_dump(struct fpm_child_s *child, FILE *slowlog) /* {{{ * long function_name; long file_name; long prev; - uint lineno = 0; + uint32_t lineno = 0; if (0 > fpm_trace_get_long(execute_data + offsetof(zend_execute_data, func), &l)) { return -1; diff --git a/sapi/fpm/fpm/fpm_sockets.c b/sapi/fpm/fpm/fpm_sockets.c index de0f479afc..36a66544d7 100644 --- a/sapi/fpm/fpm/fpm_sockets.c +++ b/sapi/fpm/fpm/fpm_sockets.c @@ -269,27 +269,63 @@ enum fpm_address_domain fpm_sockets_domain_from_address(char *address) /* {{{ */ } /* }}} */ -static int fpm_socket_af_inet_listening_socket(struct fpm_worker_pool_s *wp) /* {{{ */ +static int fpm_socket_af_inet_socket_by_addr(struct fpm_worker_pool_s *wp, const char *addr, const char *port) /* {{{ */ { struct addrinfo hints, *servinfo, *p; + char tmpbuf[INET6_ADDRSTRLEN]; + int status; + int sock = -1; + + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + + if ((status = getaddrinfo(addr, port, &hints, &servinfo)) != 0) { + zlog(ZLOG_ERROR, "getaddrinfo: %s\n", gai_strerror(status)); + return -1; + } + + for (p = servinfo; p != NULL; p = p->ai_next) { + inet_ntop(p->ai_family, fpm_get_in_addr(p->ai_addr), tmpbuf, INET6_ADDRSTRLEN); + if (sock < 0) { + if ((sock = fpm_sockets_get_listening_socket(wp, p->ai_addr, p->ai_addrlen)) != -1) { + zlog(ZLOG_DEBUG, "Found address for %s, socket opened on %s", addr, tmpbuf); + } + } else { + zlog(ZLOG_WARNING, "Found multiple addresses for %s, %s ignored", addr, tmpbuf); + } + } + + freeaddrinfo(servinfo); + + return sock; +} +/* }}} */ + +static int fpm_socket_af_inet_listening_socket(struct fpm_worker_pool_s *wp) /* {{{ */ +{ char *dup_address = strdup(wp->config->listen_address); char *port_str = strrchr(dup_address, ':'); char *addr = NULL; - char tmpbuf[INET6_ADDRSTRLEN]; int addr_len; int port = 0; int sock = -1; - int status; if (port_str) { /* this is host:port pair */ *port_str++ = '\0'; port = atoi(port_str); addr = dup_address; + + /* strip brackets from address for getaddrinfo */ + addr_len = strlen(addr); + if (addr[0] == '[' && addr[addr_len - 1] == ']') { + addr[addr_len - 1] = '\0'; + addr++; + } + } else if (strlen(dup_address) == strspn(dup_address, "0123456789")) { /* this is port */ port = atoi(dup_address); port_str = dup_address; - /* IPv6 catch-all + IPv4-mapped */ - addr = "::"; } if (port == 0) { @@ -297,36 +333,28 @@ static int fpm_socket_af_inet_listening_socket(struct fpm_worker_pool_s *wp) /* return -1; } - /* strip brackets from address for getaddrinfo */ - addr_len = strlen(addr); - if (addr[0] == '[' && addr[addr_len - 1] == ']') { - addr[addr_len - 1] = '\0'; - addr++; - } + if (addr) { + /* Bind a specific address */ + sock = fpm_socket_af_inet_socket_by_addr(wp, addr, port_str); + } else { + /* Bind ANYADDR + * + * Try "::" first as that covers IPv6 ANYADDR and mapped IPv4 ANYADDR + * silencing warnings since failure is an option + * + * If that fails (because AF_INET6 is unsupported) retry with 0.0.0.0 + */ + int old_level = zlog_set_level(ZLOG_ALERT); + sock = fpm_socket_af_inet_socket_by_addr(wp, "::", port_str); + zlog_set_level(old_level); - memset(&hints, 0, sizeof hints); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - - if ((status = getaddrinfo(addr, port_str, &hints, &servinfo)) != 0) { - zlog(ZLOG_ERROR, "getaddrinfo: %s\n", gai_strerror(status)); - free(dup_address); - return -1; - } - - for (p = servinfo; p != NULL; p = p->ai_next) { - inet_ntop(p->ai_family, fpm_get_in_addr(p->ai_addr), tmpbuf, INET6_ADDRSTRLEN); if (sock < 0) { - if ((sock = fpm_sockets_get_listening_socket(wp, p->ai_addr, p->ai_addrlen)) != -1) { - zlog(ZLOG_DEBUG, "Found address for %s, socket opened on %s", addr, tmpbuf); - } - } else { - zlog(ZLOG_WARNING, "Found multiple addresses for %s, %s ignored", addr, tmpbuf); + zlog(ZLOG_NOTICE, "Failed implicitly binding to ::, retrying with 0.0.0.0"); + sock = fpm_socket_af_inet_socket_by_addr(wp, "0.0.0.0", port_str); } } free(dup_address); - freeaddrinfo(servinfo); return sock; } diff --git a/sapi/fpm/tests/bug75212-php-value-in-user-ini.phpt b/sapi/fpm/tests/bug75212-php-value-in-user-ini.phpt new file mode 100644 index 0000000000..fd8e1b8887 --- /dev/null +++ b/sapi/fpm/tests/bug75212-php-value-in-user-ini.phpt @@ -0,0 +1,57 @@ +--TEST-- +FPM: bug75212 - php_value acts like php_admin_value +--SKIPIF-- +<?php include "skipif.inc"; ?> +--FILE-- +<?php + +require_once "tester.inc"; + +$cfg = <<<EOT +[global] +error_log = {{FILE:LOG}} +[unconfined] +listen = {{ADDR}} +pm = dynamic +pm.max_children = 5 +pm.start_servers = 1 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3 +php_admin_value[memory_limit]=32M +php_value[date.timezone]=Europe/London +EOT; + +$code = <<<EOT +<?php +echo "Test Start\n"; +var_dump(ini_get('memory_limit'), ini_get('date.timezone')); +echo "Test End\n"; +EOT; + +$ini = <<<EOT +memory_limit=64M +date.timezone=Europe/Paris +EOT; + +$tester = new FPM\Tester($cfg, $code); +$tester->setUserIni($ini); +$tester->start(); +$tester->expectLogStartNotices(); +$tester->request()->expectBody([ + 'Test Start', + 'string(3) "32M"', + 'string(12) "Europe/Paris"', + 'Test End' +]); +$tester->terminate(); +$tester->close(); + +?> +Done +--EXPECT-- +Done +--CLEAN-- +<?php +require_once "tester.inc"; +FPM\Tester::clean(); +?> diff --git a/sapi/fpm/tests/socket-ipv4-fallback.phpt b/sapi/fpm/tests/socket-ipv4-fallback.phpt new file mode 100644 index 0000000000..f0a8301916 --- /dev/null +++ b/sapi/fpm/tests/socket-ipv4-fallback.phpt @@ -0,0 +1,43 @@ +--TEST-- +FPM: Socket port connection falls back to IPv4 +--SKIPIF-- +<?php +include "skipif.inc"; +FPM\Tester::skipIfIPv6IsNotSupported(); +?> +--FILE-- +<?php + +require_once "tester.inc"; + +$cfg = <<<EOT +[global] +error_log = {{FILE:LOG}} +[unconfined] +listen = {{PORT}} +pm = dynamic +pm.max_children = 5 +pm.start_servers = 2 +pm.min_spare_servers = 1 +pm.max_spare_servers = 3 +EOT; + +$tester = new FPM\Tester($cfg); +$port = $tester->getPort(); +// Occupy our port and let things fail +$busy = stream_socket_server("tcp://[::]:$port"); +$tester->start(); +$tester->expectLogNotice('Failed implicitly binding to ::, retrying with 0.0.0.0'); +$tester->expectLogError("unable to bind listening socket for address '$port': " . + 'Address already in use \(\d+\)'); +$tester->expectLogError('FPM initialization failed'); +$tester->close(true); +?> +Done +--EXPECT-- +Done +--CLEAN-- +<?php +require_once "tester.inc"; +FPM\Tester::clean(); +?> diff --git a/sapi/fpm/www.conf.in b/sapi/fpm/www.conf.in index df2c7c3dac..ccfdbd9e87 100644 --- a/sapi/fpm/www.conf.in +++ b/sapi/fpm/www.conf.in @@ -328,6 +328,10 @@ pm.max_spare_servers = 3 ; Default Value: 0 ;request_slowlog_timeout = 0 +; Depth of slow log stack trace. +; Default Value: 20 +;request_slowlog_trace_depth = 20 + ; The timeout for serving a single request after which the worker process will ; be killed. This option should be used when the 'max_execution_time' ini option ; does not stop script execution for some reason. A value of '0' means 'off'. diff --git a/sapi/litespeed/lsapi_main.c b/sapi/litespeed/lsapi_main.c index 9a23bffa08..0c5f5cc9ac 100644 --- a/sapi/litespeed/lsapi_main.c +++ b/sapi/litespeed/lsapi_main.c @@ -679,7 +679,7 @@ static void walk_down_the_path(char* path_start, typedef struct { char *path; - uint path_len; + uint32_t path_len; char *doc_root; user_config_cache_entry *entry; } _lsapi_activate_user_ini_ctx; @@ -723,8 +723,6 @@ static int lsapi_activate_user_ini_mk_path(_lsapi_activate_user_ini_ctx *ctx, /* Extract dir name from path_translated * and store it in 'path' */ ctx->path_len = strlen(ctx->path); path = ctx->path = estrndup(SG(request_info).path_translated, ctx->path_len); - if (!path) - return FAILURE; ctx->path_len = zend_dirname(path, ctx->path_len); if (*fn_next) { @@ -802,7 +800,7 @@ static int lsapi_activate_user_ini_walk_down_the_path(_lsapi_activate_user_ini_c void* next) { time_t request_time = sapi_get_request_time(); - uint docroot_len; + uint32_t docroot_len; int rc = SUCCESS; fn_activate_user_ini_chain_t *fn_next = next; diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 70ced5793d..5af6ba619b 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -381,7 +381,7 @@ static PHP_FUNCTION(phpdbg_break_file) return; } - phpdbg_set_breakpoint_file(file, line); + phpdbg_set_breakpoint_file(file, 0, line); } /* }}} */ /* {{{ proto void phpdbg_break_method(string class, string method) */ @@ -815,15 +815,11 @@ static zend_module_entry sapi_phpdbg_module_entry = { STANDARD_MODULE_PROPERTIES }; -static void phpdbg_interned_strings_nothing(void) { } - static inline int php_sapi_phpdbg_module_startup(sapi_module_struct *module) /* {{{ */ { if (php_module_startup(module, &sapi_phpdbg_module_entry, 1) == FAILURE) { return FAILURE; } - /* prevent zend_interned_strings_restore from invalidating our string pointers too early (in phpdbg allocated memory only gets freed after module shutdown) */ - zend_interned_strings_restore = phpdbg_interned_strings_nothing; phpdbg_booted = 1; @@ -2102,7 +2098,7 @@ phpdbg_out: php_request_shutdown(NULL); } zend_end_try(); - if (PHPDBG_G(exec) && !memcmp("-", PHPDBG_G(exec), 2)) { /* i.e. execution context has been read from stdin - back it up */ + if (PHPDBG_G(exec) && strcmp("Standard input code", PHPDBG_G(exec)) == SUCCESS) { /* i.e. execution context has been read from stdin - back it up */ phpdbg_file_source *data = zend_hash_str_find_ptr(&PHPDBG_G(file_sources), PHPDBG_G(exec), PHPDBG_G(exec_len)); backup_phpdbg_compile = zend_string_alloc(data->len + 2, 1); sprintf(ZSTR_VAL(backup_phpdbg_compile), "?>%.*s", (int) data->len, data->buf); diff --git a/sapi/phpdbg/phpdbg_bp.c b/sapi/phpdbg/phpdbg_bp.c index 4422ec4cbe..27bf532dcc 100644 --- a/sapi/phpdbg/phpdbg_bp.c +++ b/sapi/phpdbg/phpdbg_bp.c @@ -237,12 +237,7 @@ PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str) /* {{{ */ } } /* }}} */ -PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num) /* {{{ */ -{ - phpdbg_set_breakpoint_file_ex(path, 0, line_num); -} /* }}} */ - -PHPDBG_API void phpdbg_set_breakpoint_file_ex(const char *path, size_t path_len, long line_num) /* {{{ */ +PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, size_t path_len, long line_num) /* {{{ */ { php_stream_statbuf ssb; char realpath[MAXPATHLEN]; @@ -329,7 +324,7 @@ PHPDBG_API void phpdbg_set_breakpoint_file_ex(const char *path, size_t path_len, zend_string_release(path_str); } /* }}} */ -PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uint filelen, zend_string *cur, HashTable *fileht) /* {{{ */ +PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uint32_t filelen, zend_string *cur, HashTable *fileht) /* {{{ */ { phpdbg_debug("file: %s, filelen: %u, cur: %s, curlen %u, pos: %c, memcmp: %d\n", file, filelen, ZSTR_VAL(cur), ZSTR_LEN(cur), filelen > ZSTR_LEN(cur) ? file[filelen - ZSTR_LEN(cur) - 1] : '?', filelen > ZSTR_LEN(cur) ? memcmp(file + filelen - ZSTR_LEN(cur), ZSTR_VAL(cur), ZSTR_LEN(cur)) : 0); @@ -378,7 +373,7 @@ PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uin PHPDBG_API void phpdbg_resolve_pending_file_break(const char *file) /* {{{ */ { HashTable *fileht; - uint filelen = strlen(file); + uint32_t filelen = strlen(file); zend_string *cur; phpdbg_debug("was compiled: %s\n", file); diff --git a/sapi/phpdbg/phpdbg_bp.h b/sapi/phpdbg/phpdbg_bp.h index 003d4e5a81..761b0430a7 100644 --- a/sapi/phpdbg/phpdbg_bp.h +++ b/sapi/phpdbg/phpdbg_bp.h @@ -121,12 +121,11 @@ typedef struct _phpdbg_breakcond_t { PHPDBG_API void phpdbg_resolve_op_array_breaks(zend_op_array *op_array); PHPDBG_API int phpdbg_resolve_op_array_break(phpdbg_breakopline_t *brake, zend_op_array *op_array); PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break); -PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uint filelen, zend_string *cur, HashTable *fileht); +PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uint32_t filelen, zend_string *cur, HashTable *fileht); PHPDBG_API void phpdbg_resolve_pending_file_break(const char *file); /* }}} */ /* {{{ Breakpoint Creation API */ -PHPDBG_API void phpdbg_set_breakpoint_file(const char* filename, long lineno); -PHPDBG_API void phpdbg_set_breakpoint_file_ex(const char* filename, size_t path_len, long lineno); +PHPDBG_API void phpdbg_set_breakpoint_file(const char* filename, size_t path_len, long lineno); PHPDBG_API void phpdbg_set_breakpoint_symbol(const char* func_name, size_t func_name_len); PHPDBG_API void phpdbg_set_breakpoint_method(const char* class_name, const char* func_name); PHPDBG_API void phpdbg_set_breakpoint_opcode(const char* opname, size_t opname_len); diff --git a/sapi/phpdbg/phpdbg_help.c b/sapi/phpdbg/phpdbg_help.c index d6e6f0b5f0..e9caa18895 100644 --- a/sapi/phpdbg/phpdbg_help.c +++ b/sapi/phpdbg/phpdbg_help.c @@ -382,8 +382,8 @@ phpdbg_help_text_t phpdbg_help_text[] = { "Type **help <command>** or (**help alias**) to get detailed help on any of the above commands, " "for example **help list** or **h l**. Note that help will also match partial commands if unique " -"(and list out options if not unique), so **help clea** will give help on the **clean** command, " -"but **help cl** will list the summary for **clean** and **clear**." CR CR +"(and list out options if not unique), so **help exp** will give help on the **export** command, " +"but **help ex** will list the summary for **exec** and **export**." CR CR "Type **help aliases** to show a full alias list, including any registered phpdginit functions" CR "Type **help syntax** for a general introduction to the command syntax." CR @@ -924,7 +924,7 @@ phpdbg_help_text_t phpdbg_help_text[] = { " Enable refcount display when hitting watchpoints" CR CR " $P S b 4 off" CR -" Temporarily disable breakpoint 4. This can be subsequently reenabled by a **s b 4 on**." CR +" Temporarily disable breakpoint 4. This can be subsequently reenabled by a **S b 4 on**." CR //*********** check oplog syntax }, diff --git a/sapi/phpdbg/phpdbg_list.c b/sapi/phpdbg/phpdbg_list.c index a934b0dd34..865f75bc27 100644 --- a/sapi/phpdbg/phpdbg_list.c +++ b/sapi/phpdbg/phpdbg_list.c @@ -129,9 +129,9 @@ PHPDBG_LIST(class) /* {{{ */ return SUCCESS; } /* }}} */ -void phpdbg_list_file(zend_string *filename, uint count, int offset, uint highlight) /* {{{ */ +void phpdbg_list_file(zend_string *filename, uint32_t count, int offset, uint32_t highlight) /* {{{ */ { - uint line, lastline; + uint32_t line, lastline; phpdbg_file_source *data; if (!(data = zend_hash_find_ptr(&PHPDBG_G(file_sources), filename))) { @@ -153,8 +153,8 @@ void phpdbg_list_file(zend_string *filename, uint count, int offset, uint highli phpdbg_xml("<list %r file=\"%s\">", ZSTR_VAL(filename)); for (line = offset; line < lastline;) { - uint linestart = data->line[line++]; - uint linelen = data->line[line] - linestart; + uint32_t linestart = data->line[line++]; + uint32_t linelen = data->line[line] - linestart; char *buffer = data->buf + linestart; if (!highlight) { @@ -237,7 +237,7 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) { zend_file_handle fake; zend_op_array *ret; char *filename; - uint line; + uint32_t line; char *bufptr, *endptr; if (zend_stream_fixup(file, &bufptr, &data.len) == FAILURE) { @@ -261,11 +261,11 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) { fake.filename = filename; fake.opened_path = file->opened_path; - *(dataptr = emalloc(sizeof(phpdbg_file_source) + sizeof(uint) * data.len)) = data; + *(dataptr = emalloc(sizeof(phpdbg_file_source) + sizeof(uint32_t) * data.len)) = data; for (line = 0, bufptr = data.buf - 1, endptr = data.buf + data.len; ++bufptr < endptr;) { if (*bufptr == '\n') { - dataptr->line[++line] = (uint)(bufptr - data.buf) + 1; + dataptr->line[++line] = (uint32_t)(bufptr - data.buf) + 1; } } dataptr->lines = ++line; @@ -283,7 +283,7 @@ zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) { return NULL; } - dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint) * line); + dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint32_t) * line); zend_hash_add_ptr(&PHPDBG_G(file_sources), ret->filename, dataptr); phpdbg_resolve_pending_file_break(ZSTR_VAL(ret->filename)); @@ -335,20 +335,20 @@ zend_op_array *phpdbg_compile_string(zval *source_string, char *filename) { zend_string *fake_name; zend_op_array *op_array; phpdbg_file_source *dataptr; - uint line; + uint32_t line; char *bufptr, *endptr; if (PHPDBG_G(flags) & PHPDBG_IN_EVAL) { return PHPDBG_G(compile_string)(source_string, filename); } - dataptr = emalloc(sizeof(phpdbg_file_source) + sizeof(uint) * Z_STRLEN_P(source_string)); + dataptr = emalloc(sizeof(phpdbg_file_source) + sizeof(uint32_t) * Z_STRLEN_P(source_string)); dataptr->buf = estrndup(Z_STRVAL_P(source_string), Z_STRLEN_P(source_string)); dataptr->len = Z_STRLEN_P(source_string); dataptr->line[0] = 0; for (line = 0, bufptr = dataptr->buf - 1, endptr = dataptr->buf + dataptr->len; ++bufptr < endptr;) { if (*bufptr == '\n') { - dataptr->line[++line] = (uint)(bufptr - dataptr->buf) + 1; + dataptr->line[++line] = (uint32_t)(bufptr - dataptr->buf) + 1; } } dataptr->lines = ++line; @@ -364,7 +364,7 @@ zend_op_array *phpdbg_compile_string(zval *source_string, char *filename) { fake_name = strpprintf(0, "%s%c%p", filename, 0, op_array->opcodes); - dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint) * line); + dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint32_t) * line); zend_hash_add_ptr(&PHPDBG_G(file_sources), fake_name, dataptr); zend_string_release(fake_name); diff --git a/sapi/phpdbg/phpdbg_list.h b/sapi/phpdbg/phpdbg_list.h index 675fd9256f..474bfdf4f5 100644 --- a/sapi/phpdbg/phpdbg_list.h +++ b/sapi/phpdbg/phpdbg_list.h @@ -34,7 +34,7 @@ PHPDBG_LIST(func); void phpdbg_list_function_byname(const char *, size_t); void phpdbg_list_function(const zend_function *); -void phpdbg_list_file(zend_string *, uint, int, uint); +void phpdbg_list_file(zend_string *, uint32_t, int, uint32_t); extern const phpdbg_command_t phpdbg_list_commands[]; @@ -48,8 +48,8 @@ typedef struct { void *map; #endif zend_op_array op_array; - uint lines; - uint line[1]; + uint32_t lines; + uint32_t line[1]; } phpdbg_file_source; #endif /* PHPDBG_LIST_H */ diff --git a/sapi/phpdbg/phpdbg_opcode.c b/sapi/phpdbg/phpdbg_opcode.c index 38238ab635..0fd3d17edf 100644 --- a/sapi/phpdbg/phpdbg_opcode.c +++ b/sapi/phpdbg/phpdbg_opcode.c @@ -99,6 +99,11 @@ char *phpdbg_decode_opline(zend_op_array *ops, zend_op *opline) /*{{{ */ uint32_t flags = zend_get_opcode_flags(opline->opcode); char *result, *decode[4] = {NULL, NULL, NULL, NULL}; + /* OpcodeName */ + if (opline->extended_value) { + spprintf(&decode[0], 0, "%s<%" PRIi32 ">", opcode_name, opline->extended_value); + } + /* OP1 */ decode[1] = phpdbg_decode_input_op( ops, opline, opline->op1, opline->op1_type, ZEND_VM_OP1_FLAGS(flags)); diff --git a/sapi/phpdbg/phpdbg_out.c b/sapi/phpdbg/phpdbg_out.c index 5a7693dcc1..1f35a3d1d5 100644 --- a/sapi/phpdbg/phpdbg_out.c +++ b/sapi/phpdbg/phpdbg_out.c @@ -589,7 +589,7 @@ static int format_converter(register buffy *odp, const char *fmt, zend_bool esca case 'r': if (PHPDBG_G(req_id)) { - s_len = spprintf(&s, 0, "req=\"%lu\"", PHPDBG_G(req_id)); + s_len = spprintf(&s, 0, "req=\"" ZEND_ULONG_FMT "\"", PHPDBG_G(req_id)); free_s = s; } else { s = ""; @@ -861,11 +861,10 @@ PHPDBG_API int phpdbg_xml_vasprintf(char **buf, const char *format, zend_bool es *buf = NULL; if (cc >= 0) { - if ((*buf = emalloc(++cc)) != NULL) { - if ((cc = phpdbg_xml_vsnprintf(*buf, cc, format, escape_xml, ap)) < 0) { - efree(*buf); - *buf = NULL; - } + *buf = emalloc(++cc); + if ((cc = phpdbg_xml_vsnprintf(*buf, cc, format, escape_xml, ap)) < 0) { + efree(*buf); + *buf = NULL; } } @@ -1063,7 +1062,7 @@ static int phpdbg_process_print(int fd, int type, const char *tag, const char *m if (PHPDBG_G(req_id)) { char *xmlbuf = NULL; - xmllen = phpdbg_asprintf(&xmlbuf, "req=\"%lu\" %.*s", PHPDBG_G(req_id), xmllen, xml); + xmllen = phpdbg_asprintf(&xmlbuf, "req=\"" ZEND_ULONG_FMT "\" %.*s", PHPDBG_G(req_id), xmllen, xml); xml = xmlbuf; } if (msgout) { diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index c4b1540796..fc25e30af1 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -46,7 +46,7 @@ #include "phpdbg_wait.h" #include "phpdbg_eol.h" -#if ZEND_VM_KIND != ZEND_VM_KIND_CALL +#if ZEND_VM_KIND != ZEND_VM_KIND_CALL && ZEND_VM_KIND != ZEND_VM_KIND_HYBRID #error "phpdbg can only be built with CALL zend vm kind" #endif @@ -58,9 +58,6 @@ extern int phpdbg_startup_run; #include "win32/param.h" #include "win32/winutil.h" #define GET_DL_ERROR() php_win_err() -#elif defined(NETWARE) -#include <sys/param.h> -#define GET_DL_ERROR() dlerror() #else #include <sys/param.h> #define GET_DL_ERROR() DL_ERROR() @@ -528,7 +525,7 @@ int phpdbg_compile_stdin(zend_string *code) { ZVAL_STR(&zv, code); - PHPDBG_G(ops) = zend_compile_string(&zv, "-"); + PHPDBG_G(ops) = zend_compile_string(&zv, "Standard input code"); zend_string_release(code); @@ -539,18 +536,18 @@ int phpdbg_compile_stdin(zend_string *code) { if (PHPDBG_G(exec)) { efree(PHPDBG_G(exec)); } - PHPDBG_G(exec) = estrdup("-"); - PHPDBG_G(exec_len) = 1; + PHPDBG_G(exec) = estrdup("Standard input code"); + PHPDBG_G(exec_len) = sizeof("Standard input code") - 1; { /* remove leading ?> from source */ int i; /* remove trailing data after zero byte, used for avoiding conflicts in eval()'ed code snippets */ - zend_string *source_path = strpprintf(0, "-%c%p", 0, PHPDBG_G(ops)->opcodes); + zend_string *source_path = strpprintf(0, "Standard input code%c%p", 0, PHPDBG_G(ops)->opcodes); phpdbg_file_source *data = zend_hash_find_ptr(&PHPDBG_G(file_sources), source_path); dtor_func_t dtor = PHPDBG_G(file_sources).pDestructor; PHPDBG_G(file_sources).pDestructor = NULL; zend_hash_del(&PHPDBG_G(file_sources), source_path); PHPDBG_G(file_sources).pDestructor = dtor; - zend_hash_str_update_ptr(&PHPDBG_G(file_sources), "-", 1, data); + zend_hash_str_update_ptr(&PHPDBG_G(file_sources), "Standard input code", sizeof("Standard input code")-1, data); zend_string_release(source_path); for (i = 1; i <= data->lines; i++) { @@ -560,7 +557,7 @@ int phpdbg_compile_stdin(zend_string *code) { memmove(data->buf, data->buf + 2, data->len); } - phpdbg_notice("compile", "context=\"-\"", "Successful compilation of stdin input"); + phpdbg_notice("compile", "context=\"Standard input code\"", "Successful compilation of stdin input"); return SUCCESS; } @@ -611,8 +608,8 @@ int phpdbg_compile(void) /* {{{ */ zend_hash_del(&PHPDBG_G(file_sources), PHPDBG_G(ops)->filename); PHPDBG_G(file_sources).pDestructor = dtor; - data = erealloc(data, sizeof(phpdbg_file_source) + sizeof(uint) * ++data->lines); - memmove(data->line + 1, data->line, sizeof(uint) * data->lines); + data = erealloc(data, sizeof(phpdbg_file_source) + sizeof(uint32_t) * ++data->lines); + memmove(data->line + 1, data->line, sizeof(uint32_t) * data->lines); data->line[0] = 0; data->buf = erealloc(data->buf, data->len + start_line_len); memmove(data->buf + start_line_len, data->buf, data->len); @@ -1208,7 +1205,7 @@ PHPDBG_COMMAND(break) /* {{{ */ { if (!param) { if (PHPDBG_G(exec)) { - phpdbg_set_breakpoint_file_ex( + phpdbg_set_breakpoint_file( zend_get_executed_filename(), strlen(zend_get_executed_filename()), zend_get_executed_lineno()); @@ -1221,7 +1218,7 @@ PHPDBG_COMMAND(break) /* {{{ */ break; case NUMERIC_PARAM: if (PHPDBG_G(exec)) { - phpdbg_set_breakpoint_file_ex(phpdbg_current_file(), strlen(phpdbg_current_file()), param->num); + phpdbg_set_breakpoint_file(phpdbg_current_file(), strlen(phpdbg_current_file()), param->num); } else { phpdbg_error("inactive", "type=\"noexec\"", "Execution context not set!"); } @@ -1236,7 +1233,7 @@ PHPDBG_COMMAND(break) /* {{{ */ phpdbg_set_breakpoint_function_opline(param->str, param->num); break; case FILE_PARAM: - phpdbg_set_breakpoint_file(param->file.name, param->file.line); + phpdbg_set_breakpoint_file(param->file.name, 0, param->file.line); break; case NUMERIC_FILE_PARAM: phpdbg_set_breakpoint_file_opline(param->file.name, param->file.line); diff --git a/sapi/phpdbg/tests/exceptions_003.phpt b/sapi/phpdbg/tests/exceptions_003.phpt index 51090c081a..9d4abc0739 100644 --- a/sapi/phpdbg/tests/exceptions_003.phpt +++ b/sapi/phpdbg/tests/exceptions_003.phpt @@ -20,22 +20,22 @@ prompt> [L0 %s HANDLE_EXCEPTION >00005: x(); 00006: } finally { 00007: print "ok\n"; -prompt> [L7 %s ECHO "ok\n" %s] +prompt> [L7 %s ECHO<1> "ok\n" %s] >00007: print "ok\n"; 00008: } 00009: } catch (Error $e) { prompt> ok [L7 %s FAST_RET ~%d try-catch(0) %s] -[L9 %s CATCH "Error" $e 1 %s] +[L9 %s CATCH<-%d> "Error" $e 1 %s] >00005: x(); 00006: } finally { 00007: print "ok\n"; -prompt> [L10 %s ECHO "caught\n" %s] +prompt> [L10 %s ECHO<1> "caught\n" %s] >00010: print "caught\n"; 00011: } 00012: prompt> caught -[L14 %s RETURN 1 %s] +[L14 %s RETURN<-1> 1 %s] >00014: prompt> --FILE-- diff --git a/sapi/phpdbg/tests/next_001.phpt b/sapi/phpdbg/tests/next_001.phpt index b07d954303..afc5133d25 100644 --- a/sapi/phpdbg/tests/next_001.phpt +++ b/sapi/phpdbg/tests/next_001.phpt @@ -15,7 +15,7 @@ prompt> [Breakpoint #0 at %s:4, hits: 1] 00005: } 00006: prompt> 0 -[L5 %s RETURN null %s] +[L5 %s RETURN<-1> null %s] >00005: } 00006: 00007: foo(); @@ -23,7 +23,7 @@ prompt> [L8 %s ECHO 1 >00008: echo 1; 00009: prompt> 1 -[L9 %s RETURN 1 %s] +[L9 %s RETURN<-1> 1 %s] >00009: prompt> --FILE-- diff --git a/sapi/phpdbg/tests/print_001.phpt b/sapi/phpdbg/tests/print_001.phpt index 94ccedc3cf..93a000528f 100644 --- a/sapi/phpdbg/tests/print_001.phpt +++ b/sapi/phpdbg/tests/print_001.phpt @@ -19,16 +19,16 @@ L14-16 foo() %s - %s + 8 ops L15 #4 DO_%cCALL @0 L15 #5 SEND_VAR @0 1 L15 #6 DO_%cCALL - L16 #7 RETURN null + L16 #7 RETURN<-1> null prompt> [User Class: Foo\Bar (2 methods)] L5-7 Foo\Bar::Foo() %s - %s + 5 ops L5 #0 RECV 1 $bar - L6 #1 INIT_NS_FCALL_BY_NAME "Foo\\var_dump" + L6 #1 INIT_NS_FCALL_BY_NAME<1> "Foo\\var_dump" L6 #2 SEND_VAR_EX $bar 1 L6 #3 DO_FCALL - L7 #4 RETURN null + L7 #4 RETURN<-1> null L9-9 Foo\Bar::baz() %s - %s + 1 ops - L9 #0 RETURN null + L9 #0 RETURN<-1> null prompt> [Not Executing!] prompt> [Context %s (11 ops)] L1-21 {main}() %s - %s + 11 ops @@ -36,13 +36,13 @@ L1-21 {main}() %s - %s + 11 ops L14 #1 NOP L18 #2 NEW "Foo\\Bar" @1 L18 #3 DO_FCALL - L18 #4 INIT_METHOD_CALL @1 "Foo" + L18 #4 INIT_METHOD_CALL<1> @1 "Foo" L18 #5 SEND_VAL_EX "test" 1 L18 #6 DO_FCALL L19 #7 INIT_FCALL%s %d %s "foo" L19 #8 SEND_VAL "test" 1 L19 #9 DO_FCALL - L21 #10 RETURN 1 + L21 #10 RETURN<-1> 1 prompt> --FILE-- <?php diff --git a/sapi/phpdbg/tests/print_002.phpt b/sapi/phpdbg/tests/print_002.phpt index 3a824986c1..dfec641672 100644 --- a/sapi/phpdbg/tests/print_002.phpt +++ b/sapi/phpdbg/tests/print_002.phpt @@ -25,7 +25,7 @@ L14-16 foo() %s - %s + 8 ops L15 #4 DO_%cCALL @0 L15 #5 SEND_VAR @0 1 L15 #6 DO_%cCALL - L16 #7 RETURN null + L16 #7 RETURN<-1> null prompt> [L15 %s INIT_FCALL%s %d %s "var_dump" %s] prompt> --FILE-- diff --git a/sapi/phpdbg/tests/stdin_001.phpt b/sapi/phpdbg/tests/stdin_001.phpt index 0bc940caef..2f93a2d956 100644 --- a/sapi/phpdbg/tests/stdin_001.phpt +++ b/sapi/phpdbg/tests/stdin_001.phpt @@ -13,13 +13,13 @@ r q --EXPECTF-- prompt> [Successful compilation of stdin input] -prompt> [Breakpoint #0 added at -:3] -prompt> [Breakpoint #0 at -:3, hits: 1] +prompt> [Breakpoint #0 added at Standard input code:3] +prompt> [Breakpoint #0 at Standard input code:3, hits: 1] >00003: echo "Hello, world!\n"; 00004: prompt> Hello, world! [Script ended normally] -prompt> [Breakpoint #0 at -:3, hits: 1] +prompt> [Breakpoint #0 at Standard input code:3, hits: 1] >00003: echo "Hello, world!\n"; 00004: -prompt>
\ No newline at end of file +prompt> diff --git a/sapi/phpdbg/tests/stepping_001.phpt b/sapi/phpdbg/tests/stepping_001.phpt index 76577b2767..e8e32db0be 100644 --- a/sapi/phpdbg/tests/stepping_001.phpt +++ b/sapi/phpdbg/tests/stepping_001.phpt @@ -25,7 +25,7 @@ prompt> [L0 %s HANDLE_EXCEPTION 00005: } 00006: prompt> [L0 %s HANDLE_EXCEPTION %s] -[L9 %s CATCH "Exception" $e 1 %s] +[L9 %s CATCH<-%d> "Exception" $e 1 %s] >00008: foo(); 00009: } catch (Exception $e) { 00010: echo "ok"; @@ -48,7 +48,7 @@ prompt> ... ok >00011: } finally { 00012: echo " ... ok"; 00013: } -prompt> [L14 %s RETURN 1 %s] +prompt> [L14 %s RETURN<-1> 1 %s] >00014: prompt> --FILE-- |
