diff options
author | Stefan Fritsch <sf@apache.org> | 2011-10-09 20:35:23 +0200 |
---|---|---|
committer | Stefan Fritsch <sf@apache.org> | 2011-10-09 20:35:23 +0200 |
commit | 0ddfb3e6ccf8b5bc6995b63732dc0a0fa58f8790 (patch) | |
tree | 47e100c65525f10b4b7834d13333c2fb75e9a41f /server | |
parent | Consistenly use apr_file_* API instead of libc when dumping config because (diff) | |
download | apache2-0ddfb3e6ccf8b5bc6995b63732dc0a0fa58f8790.tar.xz apache2-0ddfb3e6ccf8b5bc6995b63732dc0a0fa58f8790.zip |
Add -D DUMP_RUN_CFG option to dump some configuration items
from the parsed (or default) config. This is useful for init scripts that
need to setup temporary directories and permissions, for example if those
temporary directories are located on a ram disk.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1180681 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'server')
-rw-r--r-- | server/core.c | 38 | ||||
-rw-r--r-- | server/main.c | 16 | ||||
-rw-r--r-- | server/mpm_common.c | 6 | ||||
-rw-r--r-- | server/util_mutex.c | 62 |
4 files changed, 117 insertions, 5 deletions
diff --git a/server/core.c b/server/core.c index 6858cad0de..e596508dc2 100644 --- a/server/core.c +++ b/server/core.c @@ -4674,6 +4674,43 @@ AP_DECLARE(apr_uint32_t) ap_random_pick(apr_uint32_t min, apr_uint32_t max) return number; } +static void core_dump_config(apr_pool_t *p, server_rec *s) +{ + core_server_config *sconf = ap_get_core_module_config(s->module_config); + apr_file_t *out = NULL; + char *tmp; + const char **defines; + int i; + if (!ap_exists_config_define("DUMP_RUN_CFG")) + return; + + apr_file_open_stdout(&out, p); + apr_file_printf(out, "ServerRoot: \"%s\"\n", ap_server_root); + tmp = ap_server_root_relative(p, sconf->ap_document_root); + apr_file_printf(out, "Main DocumentRoot: \"%s\"\n", tmp); + tmp = ap_server_root_relative(p, s->error_fname); + apr_file_printf(out, "Main ErrorLog: \"%s\"\n", tmp); + if (ap_scoreboard_fname) { + tmp = ap_server_root_relative(p, ap_scoreboard_fname); + apr_file_printf(out, "ScoreBoardFile: \"%s\"\n", tmp); + } + ap_dump_mutexes(p, s, out); + ap_mpm_dump_pidfile(p, out); + + defines = (const char **)ap_server_config_defines->elts; + for (i = 0; i < ap_server_config_defines->nelts; i++) { + const char *name = defines[i]; + const char *val = NULL; + if (server_config_defined_vars) + val = apr_table_get(server_config_defined_vars, name); + if (val) + apr_file_printf(out, "Define: %s=%s\n", name, val); + else + apr_file_printf(out, "Define: %s\n", name); + } + +} + static void register_hooks(apr_pool_t *p) { errorlog_hash = apr_hash_make(p); @@ -4694,6 +4731,7 @@ static void register_hooks(apr_pool_t *p) ap_hook_pre_config(core_pre_config, NULL, NULL, APR_HOOK_REALLY_FIRST); ap_hook_post_config(core_post_config,NULL,NULL,APR_HOOK_REALLY_FIRST); + ap_hook_test_config(core_dump_config,NULL,NULL,APR_HOOK_FIRST); ap_hook_translate_name(ap_core_translate,NULL,NULL,APR_HOOK_REALLY_LAST); ap_hook_map_to_storage(core_map_to_storage,NULL,NULL,APR_HOOK_REALLY_LAST); ap_hook_open_logs(ap_open_logs,NULL,NULL,APR_HOOK_REALLY_FIRST); diff --git a/server/main.c b/server/main.c index 60208d28b9..70e698b428 100644 --- a/server/main.c +++ b/server/main.c @@ -415,10 +415,11 @@ static void usage(process_rec *process) " -L : list available configuration " "directives"); ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, - " -t -D DUMP_VHOSTS : show parsed settings (currently only " - "vhost settings)"); + " -t -D DUMP_VHOSTS : show parsed vhost settings"); ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, - " -S : a synonym for -t -D DUMP_VHOSTS"); + " -t -D DUMP_RUN_CFG : show parsed run settings"); + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, + " -S : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG"); ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, " -t -D DUMP_MODULES : show all loaded modules "); ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, @@ -511,11 +512,14 @@ int main(int argc, const char * const argv[]) case 'D': new = (char **)apr_array_push(ap_server_config_defines); *new = apr_pstrdup(pcommands, opt_arg); - /* Setting -D DUMP_VHOSTS is equivalent to setting -S */ + /* Setting -D DUMP_VHOSTS should work like setting -S */ if (strcmp(opt_arg, "DUMP_VHOSTS") == 0) ap_run_mode = AP_SQ_RM_CONFIG_DUMP; + /* Setting -D DUMP_RUN_CFG should work like setting -S */ + else if (strcmp(opt_arg, "DUMP_RUN_CFG") == 0) + ap_run_mode = AP_SQ_RM_CONFIG_DUMP; /* Setting -D DUMP_MODULES is equivalent to setting -M */ - if (strcmp(opt_arg, "DUMP_MODULES") == 0) + else if (strcmp(opt_arg, "DUMP_MODULES") == 0) ap_run_mode = AP_SQ_RM_CONFIG_DUMP; break; @@ -563,6 +567,8 @@ int main(int argc, const char * const argv[]) ap_run_mode = AP_SQ_RM_CONFIG_DUMP; new = (char **)apr_array_push(ap_server_config_defines); *new = "DUMP_VHOSTS"; + new = (char **)apr_array_push(ap_server_config_defines); + *new = "DUMP_RUN_CFG"; break; case 'M': diff --git a/server/mpm_common.c b/server/mpm_common.c index f04ac18176..aee3f18c1f 100644 --- a/server/mpm_common.c +++ b/server/mpm_common.c @@ -299,6 +299,12 @@ const char *ap_mpm_set_pidfile(cmd_parms *cmd, void *dummy, return NULL; } +void ap_mpm_dump_pidfile(apr_pool_t *p, apr_file_t *out) +{ + apr_file_printf(out, "PidFile: \"%s\"\n", + ap_server_root_relative(p, ap_pid_fname)); +} + const char *ap_mpm_set_max_requests(cmd_parms *cmd, void *dummy, const char *arg) { diff --git a/server/util_mutex.c b/server/util_mutex.c index 490591502d..c5c1bf0aaa 100644 --- a/server/util_mutex.c +++ b/server/util_mutex.c @@ -496,3 +496,65 @@ AP_DECLARE(apr_status_t) ap_proc_mutex_create(apr_proc_mutex_t **mutex, return rv; } + +AP_CORE_DECLARE(void) ap_dump_mutexes(apr_pool_t *p, server_rec *s, apr_file_t *out) +{ + apr_hash_index_t *idx; + mutex_cfg_t *defcfg = apr_hash_get(mxcfg_by_type, "default", APR_HASH_KEY_STRING); + for (idx = apr_hash_first(p, mxcfg_by_type); idx; idx = apr_hash_next(idx)) + { + mutex_cfg_t *mxcfg; + const char *name, *mech; + const void *name_; + const char *dir = ""; + apr_hash_this(idx, &name_, NULL, NULL); + name = name_; + mxcfg = mxcfg_lookup(p, name); + if (mxcfg == defcfg && strcmp(name, "default") != 0) { + apr_file_printf(out, "Mutex %s: using_defaults\n", name); + continue; + } + if (mxcfg->none) { + apr_file_printf(out, "Mutex %s: none\n", name); + continue; + } + switch (mxcfg->mech) { + case APR_LOCK_DEFAULT: + mech = "default"; + break; +#if APR_HAS_FCNTL_SERIALIZE + case APR_LOCK_FCNTL: + mech = "fcntl"; + break; +#endif +#if APR_HAS_FLOCK_SERIALIZE + case APR_LOCK_FLOCK: + mech = "flock"; + break; +#endif +#if APR_HAS_POSIXSEM_SERIALIZE + case APR_LOCK_POSIXSEM: + mech = "posixsem"; + break; +#endif +#if APR_HAS_SYSVSEM_SERIALIZE + case APR_LOCK_SYSVSEM: + mech = "sysvsem"; + break; +#endif +#if APR_HAS_PROC_PTHREAD_SERIALIZE + case APR_LOCK_PROC_PTHREAD: + mech = "pthread"; + break; +#endif + default: + ap_assert(0); + } + + if (mxcfg->dir) + dir = ap_server_root_relative(p, mxcfg->dir); + + apr_file_printf(out, "Mutex %s: dir=\"%s\" mechanism=%s %s\n", name, dir, mech, + mxcfg->omit_pid ? "[OmitPid]" : ""); + } +} |