From 0ddfb3e6ccf8b5bc6995b63732dc0a0fa58f8790 Mon Sep 17 00:00:00 2001 From: Stefan Fritsch Date: Sun, 9 Oct 2011 18:35:23 +0000 Subject: [PATCH] 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 --- CHANGES | 4 +++ include/ap_mmn.h | 3 +- include/mpm_common.h | 1 + include/util_mutex.h | 2 ++ modules/arch/unix/mod_unixd.c | 23 +++++++++++- modules/ssl/ssl_engine_config.c | 3 +- os/unix/unixd.h | 1 + server/core.c | 38 ++++++++++++++++++++ server/main.c | 16 ++++++--- server/mpm_common.c | 6 ++++ server/util_mutex.c | 62 +++++++++++++++++++++++++++++++++ 11 files changed, 151 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index e74f609594..74f1156d0f 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,10 @@ Changes with Apache 2.3.15 PR 51714. [Stefan Fritsch, Jim Jagielski, Ruediger Pluem, Eric Covener, ] + *) core, unixd: 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. [Stefan Fritsch] + *) core, mod_actions, mod_asis: Downgrade error log messages which accompany a 404 request status from loglevel error to info. PR: 35768. [Stefan Fritsch] diff --git a/include/ap_mmn.h b/include/ap_mmn.h index f3d53cef9a..d48a1ca44d 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -356,7 +356,8 @@ * ap_realloc() * 20110724.9 (2.3.15-dev) add ap_varbuf_pdup() and ap_varbuf_regsub() * 20110724.10(2.3.15-dev) Export ap_max_mem_free - * 20111009.0 (2.3.15-dev) Remove ap_proxy_removestr() + * 20111009.0 (2.3.15-dev) Remove ap_proxy_removestr(), + * add ap_unixd_config.group_name */ #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */ diff --git a/include/mpm_common.h b/include/mpm_common.h index 53c286faf9..f342c290ab 100644 --- a/include/mpm_common.h +++ b/include/mpm_common.h @@ -290,6 +290,7 @@ const char *ap_mpm_set_max_requests(cmd_parms *cmd, void *dummy, extern const char *ap_pid_fname; const char *ap_mpm_set_pidfile(cmd_parms *cmd, void *dummy, const char *arg); +void ap_mpm_dump_pidfile(apr_pool_t *p, apr_file_t *out); /* * The directory that the server changes directory to dump core. diff --git a/include/util_mutex.h b/include/util_mutex.h index 5935a1c38b..1cb89c8675 100644 --- a/include/util_mutex.h +++ b/include/util_mutex.h @@ -213,6 +213,8 @@ AP_DECLARE(apr_status_t) ap_proc_mutex_create(apr_proc_mutex_t **mutex, apr_pool_t *pool, apr_int32_t options); +AP_CORE_DECLARE(void) ap_dump_mutexes(apr_pool_t *p, server_rec *s, apr_file_t *out); + #ifdef __cplusplus } #endif diff --git a/modules/arch/unix/mod_unixd.c b/modules/arch/unix/mod_unixd.c index 9e55177b93..442dffc137 100644 --- a/modules/arch/unix/mod_unixd.c +++ b/modules/arch/unix/mod_unixd.c @@ -239,6 +239,7 @@ unixd_set_group(cmd_parms *cmd, void *dummy, return err; } + ap_unixd_config.group_name = arg; ap_unixd_config.group_id = ap_gname2id(arg); return NULL; @@ -289,6 +290,7 @@ unixd_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_finfo_t wrapper; ap_unixd_config.user_name = DEFAULT_USER; ap_unixd_config.user_id = ap_uname2id(DEFAULT_USER); + ap_unixd_config.group_name = DEFAULT_GROUP; ap_unixd_config.group_id = ap_gname2id(DEFAULT_GROUP); ap_unixd_config.chroot_dir = NULL; /* none */ @@ -369,11 +371,30 @@ AP_DECLARE(int) ap_unixd_setup_child(void) return 0; } +static void unixd_dump_config(apr_pool_t *p, server_rec *s) +{ + apr_file_t *out = NULL; + apr_uid_t uid = ap_unixd_config.user_id; + apr_gid_t gid = ap_unixd_config.group_id; + char *no_root = ""; + if (geteuid() != 0) + no_root = " not_used"; + apr_file_open_stdout(&out, p); + apr_file_printf(out, "User: name=\"%s\" id=%lu%s\n", + ap_unixd_config.user_name, (unsigned long)uid, no_root); + apr_file_printf(out, "Group: name=\"%s\" id=%lu%s\n", + ap_unixd_config.group_name, (unsigned long)gid, no_root); + if (ap_unixd_config.chroot_dir) + apr_file_printf(out, "ChrootDir: \"%s\"%s\n", + ap_unixd_config.chroot_dir, no_root); +} + static void unixd_hooks(apr_pool_t *pool) { ap_hook_pre_config(unixd_pre_config, NULL, NULL, APR_HOOK_FIRST); - + ap_hook_test_config(unixd_dump_config, + NULL, NULL, APR_HOOK_FIRST); ap_hook_drop_privileges(unixd_drop_privileges, NULL, NULL, APR_HOOK_MIDDLE); } diff --git a/modules/ssl/ssl_engine_config.c b/modules/ssl/ssl_engine_config.c index dfcfc65b3a..906d791426 100644 --- a/modules/ssl/ssl_engine_config.c +++ b/modules/ssl/ssl_engine_config.c @@ -1724,6 +1724,7 @@ void ssl_hook_ConfigTest(apr_pool_t *pconf, server_rec *s) return; } apr_file_open_stdout(&out, pconf); + apr_file_printf(out, "Server certificates:\n"); /* Dump the filenames of all configured server certificates to * stdout. */ @@ -1735,7 +1736,7 @@ void ssl_hook_ConfigTest(apr_pool_t *pconf, server_rec *s) int i; for (i = 0; (i < SSL_AIDX_MAX) && pks->cert_files[i]; i++) { - apr_file_printf(out, "%s\n", pks->cert_files[i]); + apr_file_printf(out, " %s\n", pks->cert_files[i]); } } diff --git a/os/unix/unixd.h b/os/unix/unixd.h index 721250f372..74961c348e 100644 --- a/os/unix/unixd.h +++ b/os/unix/unixd.h @@ -73,6 +73,7 @@ AP_DECLARE_HOOK(ap_unix_identity_t *, get_suexec_identity,(const request_rec *r) typedef struct { const char *user_name; + const char *group_name; uid_t user_id; gid_t group_id; int suexec_enabled; 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]" : ""); + } +} -- 2.40.0