From 5ef0100b4d2e7a6b285f491e5bd51df27b33b0fe Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Loyet?= Date: Sun, 14 Nov 2010 22:22:07 +0000 Subject: [PATCH] - extend the 'i-t' fpm argument to dump configuration file when called twice (-tt) --- sapi/fpm/fpm/fpm.c | 6 ++-- sapi/fpm/fpm/fpm.h | 3 +- sapi/fpm/fpm/fpm_conf.c | 68 +++++++++++++++++++++++++++++++++++++++-- sapi/fpm/fpm/fpm_conf.h | 6 +++- sapi/fpm/fpm/fpm_main.c | 5 +-- sapi/fpm/fpm/zlog.c | 6 ++++ sapi/fpm/fpm/zlog.h | 1 + sapi/fpm/php-fpm.8.in | 1 + 8 files changed, 86 insertions(+), 10 deletions(-) diff --git a/sapi/fpm/fpm/fpm.c b/sapi/fpm/fpm/fpm.c index eb1ff40197..987e13c3ff 100644 --- a/sapi/fpm/fpm/fpm.c +++ b/sapi/fpm/fpm/fpm.c @@ -23,16 +23,16 @@ struct fpm_globals_s fpm_globals; -int fpm_init(int argc, char **argv, char *config, char *prefix, struct event_base **base) /* {{{ */ +int fpm_init(int argc, char **argv, char *config, char *prefix, int test_conf, struct event_base **base) /* {{{ */ { fpm_globals.argc = argc; fpm_globals.argv = argv; fpm_globals.config = config; fpm_globals.prefix = prefix; - if (0 > fpm_php_init_main() || + if (0 > fpm_php_init_main() || 0 > fpm_stdio_init_main() || - 0 > fpm_conf_init_main() || + 0 > fpm_conf_init_main(test_conf) || 0 > fpm_unix_init_main() || 0 > fpm_pctl_init_main() || 0 > fpm_env_init_main() || diff --git a/sapi/fpm/fpm/fpm.h b/sapi/fpm/fpm/fpm.h index b0d8e13699..834f4f1929 100644 --- a/sapi/fpm/fpm/fpm.h +++ b/sapi/fpm/fpm/fpm.h @@ -10,7 +10,7 @@ #include int fpm_run(int *max_requests, struct event_base *base); -int fpm_init(int argc, char **argv, char *config, char *prefix, struct event_base **base); +int fpm_init(int argc, char **argv, char *config, char *prefix, int test_conf, struct event_base **base); struct fpm_globals_s { pid_t parent_pid; @@ -24,7 +24,6 @@ struct fpm_globals_s { int listening_socket; /* for this child */ int max_requests; /* for this child */ int is_child; - int test_conf; }; extern struct fpm_globals_s fpm_globals; diff --git a/sapi/fpm/fpm/fpm_conf.c b/sapi/fpm/fpm/fpm_conf.c index 2c49410e20..2389fc6759 100644 --- a/sapi/fpm/fpm/fpm_conf.c +++ b/sapi/fpm/fpm/fpm_conf.c @@ -1105,7 +1105,68 @@ int fpm_conf_load_ini_file(char *filename TSRMLS_DC) /* {{{ */ } /* }}} */ -int fpm_conf_init_main() /* {{{ */ +static void fpm_conf_dump() /* {{{ */ +{ + struct fpm_worker_pool_s *wp; + + zlog(ZLOG_NOTICE, "[General]"); + zlog(ZLOG_NOTICE, "\tpid = %s", STR2STR(fpm_global_config.pid_file)); + zlog(ZLOG_NOTICE, "\tdaemonize = %s", BOOL2STR(fpm_global_config.daemonize)); + zlog(ZLOG_NOTICE, "\terror_log = %s", STR2STR(fpm_global_config.error_log)); + zlog(ZLOG_NOTICE, "\tlog_level = %s", zlog_get_level_name()); + zlog(ZLOG_NOTICE, "\tprocess_control_timeout = %ds", fpm_global_config.process_control_timeout); + zlog(ZLOG_NOTICE, "\temergency_restart_interval = %ds", fpm_global_config.emergency_restart_interval); + zlog(ZLOG_NOTICE, "\temergency_restart_threshold = %d", fpm_global_config.emergency_restart_threshold); + zlog(ZLOG_NOTICE, " "); + + for (wp = fpm_worker_all_pools; wp; wp = wp->next) { + struct key_value_s *kv; + if (!wp->config) continue; + zlog(ZLOG_NOTICE, "[%s]", STR2STR(wp->config->name)); + zlog(ZLOG_NOTICE, "\tprefix = %s", STR2STR(wp->config->prefix)); + zlog(ZLOG_NOTICE, "\tuser = %s", STR2STR(wp->config->user)); + zlog(ZLOG_NOTICE, "\tgroup = %s", STR2STR(wp->config->group)); + zlog(ZLOG_NOTICE, "\tchroot = %s", STR2STR(wp->config->chroot)); + zlog(ZLOG_NOTICE, "\tchdir = %s", STR2STR(wp->config->chdir)); + zlog(ZLOG_NOTICE, "\tlisten = %s", STR2STR(wp->config->listen_address)); + zlog(ZLOG_NOTICE, "\tlisten.backlog = %d", wp->config->listen_backlog); + zlog(ZLOG_NOTICE, "\tlisten.owner = %s", STR2STR(wp->config->listen_owner)); + zlog(ZLOG_NOTICE, "\tlisten.group = %s", STR2STR(wp->config->listen_group)); + zlog(ZLOG_NOTICE, "\tlisten.mode = %s", STR2STR(wp->config->listen_mode)); + zlog(ZLOG_NOTICE, "\tlisten.allowed_clients = %s", STR2STR(wp->config->listen_allowed_clients)); + zlog(ZLOG_NOTICE, "\tpm = %s", PM2STR(wp->config->pm)); + zlog(ZLOG_NOTICE, "\tpm.max_children = %d", wp->config->pm_max_children); + zlog(ZLOG_NOTICE, "\tpm.max_requests = %d", wp->config->pm_max_requests); + zlog(ZLOG_NOTICE, "\tpm.start_servers = %d", wp->config->pm_start_servers); + zlog(ZLOG_NOTICE, "\tpm.min_spare_servers = %d", wp->config->pm_min_spare_servers); + zlog(ZLOG_NOTICE, "\tpm.max_spare_servers = %d", wp->config->pm_max_spare_servers); + zlog(ZLOG_NOTICE, "\tpm.status_path = %s", STR2STR(wp->config->pm_status_path)); + zlog(ZLOG_NOTICE, "\tping.path = %s", STR2STR(wp->config->ping_path)); + zlog(ZLOG_NOTICE, "\tping.response = %s", STR2STR(wp->config->ping_response)); + zlog(ZLOG_NOTICE, "\tcatch_workers_output = %s", BOOL2STR(wp->config->catch_workers_output)); + zlog(ZLOG_NOTICE, "\trequest_terminate_timeout = %ds", wp->config->request_terminate_timeout); + zlog(ZLOG_NOTICE, "\trequest_slowlog_timeout = %ds", wp->config->request_slowlog_timeout); + zlog(ZLOG_NOTICE, "\tslowlog = %s", STR2STR(wp->config->slowlog)); + zlog(ZLOG_NOTICE, "\trlimit_files = %d", wp->config->rlimit_files); + zlog(ZLOG_NOTICE, "\trlimit_core = %d", wp->config->rlimit_core); + + for (kv = wp->config->env; kv; kv = kv->next) { + zlog(ZLOG_NOTICE, "\tenv[%s] = %s", kv->key, kv->value); + } + + for (kv = wp->config->php_values; kv; kv = kv->next) { + zlog(ZLOG_NOTICE, "\tphp_value[%s] = %s", kv->key, kv->value); + } + + for (kv = wp->config->php_admin_values; kv; kv = kv->next) { + zlog(ZLOG_NOTICE, "\tphp_admin_value[%s] = %s", kv->key, kv->value); + } + zlog(ZLOG_NOTICE, " "); + } +} +/* }}} */ + +int fpm_conf_init_main(int test_conf) /* {{{ */ { int ret; TSRMLS_FETCH(); @@ -1143,7 +1204,10 @@ int fpm_conf_init_main() /* {{{ */ return -1; } - if (fpm_globals.test_conf) { + if (test_conf) { + if (test_conf > 1) { + fpm_conf_dump(); + } zlog(ZLOG_NOTICE, "configuration file %s test is successful\n", fpm_globals.config); return -1; } diff --git a/sapi/fpm/fpm/fpm_conf.h b/sapi/fpm/fpm/fpm_conf.h index 2e65efe2ea..ac38ee2e9a 100644 --- a/sapi/fpm/fpm/fpm_conf.h +++ b/sapi/fpm/fpm/fpm_conf.h @@ -10,6 +10,10 @@ #define FPM_CONF_MAX_PONG_LENGTH 64 +#define STR2STR(a) (a ? a : "undefined") +#define BOOL2STR(a) (a ? "yes" : "no") +#define PM2STR(a) (a == PM_STYLE_STATIC ? "static" : "dynamic") + struct key_value_s; struct key_value_s { @@ -70,7 +74,7 @@ struct ini_value_parser_s { enum { PM_STYLE_STATIC = 1, PM_STYLE_DYNAMIC = 2 }; -int fpm_conf_init_main(); +int fpm_conf_init_main(int test_conf); int fpm_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc); int fpm_conf_write_pid(); int fpm_conf_unlink_pid(); diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index 4fae1dddb8..a0672fd017 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -1553,6 +1553,7 @@ int main(int argc, char *argv[]) fcgi_request request; char *fpm_config = NULL; char *fpm_prefix = NULL; + int test_conf = 0; fcgi_init(); @@ -1640,7 +1641,7 @@ int main(int argc, char *argv[]) break; case 't': - fpm_globals.test_conf = 1; + test_conf++; break; case 'm': /* list compiled in modules */ @@ -1779,7 +1780,7 @@ consult the installation file that came with this distribution, or visit \n\ } } - if (0 > fpm_init(argc, argv, fpm_config ? fpm_config : CGIG(fpm_config), fpm_prefix, &CGIG(event_base))) { + if (0 > fpm_init(argc, argv, fpm_config ? fpm_config : CGIG(fpm_config), fpm_prefix, test_conf, &CGIG(event_base))) { return FAILURE; } diff --git a/sapi/fpm/fpm/zlog.c b/sapi/fpm/fpm/zlog.c index 66e58762ed..4df018bc2c 100644 --- a/sapi/fpm/fpm/zlog.c +++ b/sapi/fpm/fpm/zlog.c @@ -28,6 +28,12 @@ static const char *level_names[] = { [ZLOG_ALERT] = "ALERT", }; +const char *zlog_get_level_name() /* {{{ */ +{ + return level_names[zlog_level]; +} +/* }}} */ + void zlog_set_launched(void) { launched = 1; } diff --git a/sapi/fpm/fpm/zlog.h b/sapi/fpm/fpm/zlog.h index fbb34ee6f6..598c075e35 100644 --- a/sapi/fpm/fpm/zlog.h +++ b/sapi/fpm/fpm/zlog.h @@ -11,6 +11,7 @@ struct timeval; int zlog_set_fd(int new_fd); int zlog_set_level(int new_value); +const char *zlog_get_level_name(); void zlog_set_launched(void); size_t zlog_print_time(struct timeval *tv, char *timebuf, size_t timebuf_len); diff --git a/sapi/fpm/php-fpm.8.in b/sapi/fpm/php-fpm.8.in index 3d9dc0981c..6c9c6d6274 100644 --- a/sapi/fpm/php-fpm.8.in +++ b/sapi/fpm/php-fpm.8.in @@ -96,6 +96,7 @@ Specify alternative path to FastCGI process manager configuration file (the defa .PD 1 .B \-t Test FPM configuration file and exit +If called twice (-tt), the configuration is dumped before exiting. .TP .PD 0 .B \-\-zend\-extension \fIfile\fP -- 2.40.0