com php-src: rewrite fpm_get_configuration() patch: sapi/fpm/fpm/fpm.c sapi/fpm/fpm/fpm_children.c sap i/fpm/fpm/fpm_children.h
sapi/fpm/fpm/fpm_conf.c sa pi/fpm/fpm/fpm_conf.h sapi/fpm/fpm/fpm_main.c

From: Date: Wed, 05 Feb 2014 12:24:30 +0000
Subject: com php-src: rewrite fpm_get_configuration() patch: sapi/fpm/fpm/fpm.c sapi/fpm/fpm/fpm_children.c sap i/fpm/fpm/fpm_children.h
sapi/fpm/fpm/fpm_conf.c sa pi/fpm/fpm/fpm_conf.h sapi/fpm/fpm/fpm_main.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-76621@lists.php.net to get a copy of this message
Commit: 7dcf8765f1c18862e25422930a69c09aa8ff6c48 Author: Antony Dovgal <tony2001@php.net> Wed, 5 Feb 2014 16:24:30 +0400 Parents: f9b709956822139b7935dc7a3a572119debd0b4e Branches: badoo-5.5_mysqlnd Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7dcf8765f1c18862e25422930a69c09aa8ff6c48 Log: rewrite fpm_get_configuration() patch in order to avoid leaking parent FDs to children Changed paths: M sapi/fpm/fpm/fpm.c M sapi/fpm/fpm/fpm_children.c M sapi/fpm/fpm/fpm_children.h M sapi/fpm/fpm/fpm_conf.c M sapi/fpm/fpm/fpm_conf.h M sapi/fpm/fpm/fpm_main.c Diff: diff --git a/sapi/fpm/fpm/fpm.c b/sapi/fpm/fpm/fpm.c index 4d3252a..b866f37 100644 --- a/sapi/fpm/fpm/fpm.c +++ b/sapi/fpm/fpm/fpm.c @@ -114,6 +114,8 @@ int fpm_run(int *max_requests) /* {{{ */ run_child: /* only workers reach this point */ + fpm_cleanups_run(FPM_CLEANUP_CHILD); + *max_requests = fpm_globals.max_requests; return fpm_globals.listening_socket; } diff --git a/sapi/fpm/fpm/fpm_children.c b/sapi/fpm/fpm/fpm_children.c index c063820..25613c6 100644 --- a/sapi/fpm/fpm/fpm_children.c +++ b/sapi/fpm/fpm/fpm_children.c @@ -34,7 +34,7 @@ static time_t *last_faults; static int fault; -struct fpm_child_s *this_child = NULL; +struct fpm_worker_pool_config_s *this_config = NULL; static void fpm_children_cleanup(int which, void *arg) /* {{{ */ { @@ -405,7 +405,7 @@ int fpm_children_make(struct fpm_worker_pool_s *wp, int in_event_loop, int nb_to case 0 : fpm_child_resources_use(child); fpm_globals.is_child = 1; - this_child = child; + this_config = fpm_worker_pool_config_copy(child->wp->config); fpm_child_init(wp); return 0; diff --git a/sapi/fpm/fpm/fpm_children.h b/sapi/fpm/fpm/fpm_children.h index f43112d..16c0635 100644 --- a/sapi/fpm/fpm/fpm_children.h +++ b/sapi/fpm/fpm/fpm_children.h @@ -18,7 +18,7 @@ int fpm_children_init_main(); int fpm_children_make(struct fpm_worker_pool_s *wp, int in_event_loop, int nb_to_spawn, int is_debug); void fpm_child_free(struct fpm_child_s *child); -extern struct fpm_child_s *this_child; +extern struct fpm_worker_pool_config_s *this_config; struct fpm_child_s; diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c index cd5fc34..13fc127 100644 --- a/sapi/fpm/fpm/fpm_conf.c +++ b/sapi/fpm/fpm/fpm_conf.c @@ -668,6 +668,41 @@ int fpm_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc) /* {{{ */ } /* }}} */ +struct fpm_worker_pool_config_s *fpm_worker_pool_config_copy(struct fpm_worker_pool_config_s *wpc) /* {{{ */ +{ + struct fpm_worker_pool_config_s *copy; + + copy = malloc(sizeof(struct fpm_worker_pool_config_s)); + *copy = *wpc; + + copy->name = wpc->name ? strdup(wpc->name) : NULL; + copy->prefix = wpc->prefix ? strdup(wpc->prefix) : NULL; + copy->user = wpc->user ? strdup(wpc->user) : NULL; + copy->group = wpc->group ? strdup(wpc->group) : NULL; + copy->listen_address = wpc->listen_address ? strdup(wpc->listen_address) : NULL; + copy->listen_owner = wpc->listen_owner ? strdup(wpc->listen_owner) : NULL; + copy->listen_group = wpc->listen_group ? strdup(wpc->listen_group) : NULL; + copy->listen_mode = wpc->listen_mode ? strdup(wpc->listen_mode) : NULL; + copy->listen_allowed_clients = wpc->listen_allowed_clients ? strdup(wpc->listen_allowed_clients) : NULL; + copy->pm_status_path = wpc->pm_status_path ? strdup(wpc->pm_status_path) : NULL; + copy->ping_path = wpc->ping_path ? strdup(wpc->ping_path) : NULL; + copy->ping_response = wpc->ping_response ? strdup(wpc->ping_response) : NULL; + copy->access_log = wpc->access_log ? strdup(wpc->access_log) : NULL; + copy->access_format = wpc->access_format ? strdup(wpc->access_format) : NULL; + copy->slowlog = wpc->slowlog ? strdup(wpc->slowlog) : NULL; + copy->chroot = wpc->chroot ? strdup(wpc->chroot) : NULL; + copy->chdir = wpc->chdir ? strdup(wpc->chdir) : NULL; + copy->security_limit_extensions = wpc->security_limit_extensions ? strdup(wpc->security_limit_extensions) : NULL; + + /* doesn't seem to be needed */ + copy->php_values = NULL; + copy->php_admin_values = NULL; + copy->env = NULL; + + return copy; +} +/* }}} */ + static int fpm_evaluate_full_path(char **path, struct fpm_worker_pool_s *wp, char *default_prefix, int expand) /* {{{ */ { char *prefix = NULL; diff --git a/sapi/fpm/fpm/fpm_conf.h b/sapi/fpm/fpm/fpm_conf.h index efd65dc..b2c89ac 100644 --- a/sapi/fpm/fpm/fpm_conf.h +++ b/sapi/fpm/fpm/fpm_conf.h @@ -105,6 +105,7 @@ int fpm_conf_init_main(int test_conf, int force_daemon); int fpm_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc); int fpm_conf_write_pid(); int fpm_conf_unlink_pid(); +struct fpm_worker_pool_config_s *fpm_worker_pool_config_copy(struct fpm_worker_pool_config_s *wpc); #endif diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index c405449..c280884 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -1500,10 +1500,10 @@ static PHP_MSHUTDOWN_FUNCTION(cgi) php_info_print_table_row(2, #name, buf); #define FPM_POOL_INFO_STR(name) \ - php_info_print_table_row(2, #name, this_child->wp->config->name); + php_info_print_table_row(2, #name, this_config->name); #define FPM_POOL_INFO_INT(name) \ - sprintf(buf, "%d", this_child->wp->config->name); \ + sprintf(buf, "%d", this_config->name); \ php_info_print_table_row(2, #name, buf); /* {{{ PHP_MINFO_FUNCTION @@ -1565,7 +1565,7 @@ static PHP_MINFO_FUNCTION(cgi) php_info_print_table_end(); - if (this_child && this_child->wp && this_child->wp->config) { + if (this_config) { php_info_print_table_start(); php_info_print_table_header(2, "PHP-FPM current pool configuration", "Value"); FPM_POOL_INFO_STR(name); @@ -1579,7 +1579,7 @@ static PHP_MINFO_FUNCTION(cgi) FPM_POOL_INFO_STR(listen_mode); FPM_POOL_INFO_STR(listen_allowed_clients); FPM_POOL_INFO_INT(process_priority); - switch (this_child->wp->config->pm) { + switch (this_config->pm) { case PM_STYLE_STATIC: sprintf(buf, "static"); break; @@ -1590,7 +1590,7 @@ static PHP_MINFO_FUNCTION(cgi) sprintf(buf, "ondemand"); break; default: - sprintf(buf, "invalid pm value (%d)", this_child->wp->config->pm); + sprintf(buf, "invalid pm value (%d)", this_config->pm); break; } php_info_print_table_row(2, "pm", buf); @@ -1653,11 +1653,11 @@ PHP_FUNCTION(fastcgi_finish_request) /* {{{ */ } \ #define FPM_GET_POOL_INT(name) \ - add_assoc_long(pool, #name, this_child->wp->config->name) + add_assoc_long(pool, #name, this_config->name) #define FPM_GET_POOL_STR(name) \ - if (this_child->wp->config->name) { \ - add_assoc_string(pool, #name, this_child->wp->config->name, 1); \ + if (this_config->name) { \ + add_assoc_string(pool, #name, this_config->name, 1); \ } else { \ add_assoc_string(pool, #name, "", 1); \ } @@ -1667,7 +1667,7 @@ PHP_FUNCTION(fpm_get_configuration) /* {{{ */ { zval *pool; - if (!this_child || !this_child->wp || !this_child->wp->config) { + if (!this_config) { RETURN_FALSE; } @@ -1724,7 +1724,7 @@ PHP_FUNCTION(fpm_get_configuration) /* {{{ */ add_assoc_zval(return_value, "pool", pool); - if (this_child && this_child->wp && this_child->wp->config) { + if (this_config) { FPM_GET_POOL_STR(name); FPM_GET_POOL_STR(prefix); FPM_GET_POOL_STR(user); @@ -1737,7 +1737,7 @@ PHP_FUNCTION(fpm_get_configuration) /* {{{ */ FPM_GET_POOL_STR(listen_allowed_clients); FPM_GET_POOL_INT(process_priority); - switch (this_child->wp->config->pm) { + switch (this_config->pm) { case PM_STYLE_STATIC: add_assoc_string(pool, "pm", "static", 1); break; @@ -2221,7 +2221,8 @@ fastcgi_request_done: /* end of fastcgi loop */ } fpm_cleanups_run(FPM_CLEANUP_CHILD); - fpm_child_free(this_child); + fpm_worker_pool_config_free(this_config); + free(this_config); fcgi_shutdown(); if (cgi_sapi_module.php_ini_path_override) {

« previous php.cvs (#76621) next »