mirror of
https://github.com/apache/httpd.git
synced 2025-08-08 15:02:10 +03:00
mod_info: Dump config to stdout during startup if -DDUMP_CONFIG is
specified. This functionality should probably be moved into core, but for now it's a lot better than nothing. And it may even help me debug some other config related code. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1086441 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
3
CHANGES
3
CHANGES
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
Changes with Apache 2.3.12
|
Changes with Apache 2.3.12
|
||||||
|
|
||||||
|
*) mod_info: Dump config to stdout during startup if -DDUMP_CONFIG is
|
||||||
|
specified. [Stefan Fritsch]
|
||||||
|
|
||||||
*) Restore visibility of DEFAULT_PIDLOG to core and modules. MPM
|
*) Restore visibility of DEFAULT_PIDLOG to core and modules. MPM
|
||||||
helper function ap_remove_pid() added. [Jeff Trawick]
|
helper function ap_remove_pid() added. [Jeff Trawick]
|
||||||
|
|
||||||
|
@@ -61,6 +61,7 @@
|
|||||||
#include "http_request.h"
|
#include "http_request.h"
|
||||||
#include "util_script.h"
|
#include "util_script.h"
|
||||||
#include "ap_mpm.h"
|
#include "ap_mpm.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -75,6 +76,9 @@ typedef struct
|
|||||||
|
|
||||||
module AP_MODULE_DECLARE_DATA info_module;
|
module AP_MODULE_DECLARE_DATA info_module;
|
||||||
|
|
||||||
|
/* current file name when doing -DDUMP_CONFIG */
|
||||||
|
const char *dump_config_fn_info;
|
||||||
|
|
||||||
static void *create_info_config(apr_pool_t * p, server_rec * s)
|
static void *create_info_config(apr_pool_t * p, server_rec * s)
|
||||||
{
|
{
|
||||||
info_svr_conf *conf =
|
info_svr_conf *conf =
|
||||||
@@ -100,34 +104,74 @@ static void put_int_flush_right(request_rec * r, int i, int field)
|
|||||||
{
|
{
|
||||||
if (field > 1 || i > 9)
|
if (field > 1 || i > 9)
|
||||||
put_int_flush_right(r, i / 10, field - 1);
|
put_int_flush_right(r, i / 10, field - 1);
|
||||||
if (i)
|
if (i) {
|
||||||
|
if (r)
|
||||||
ap_rputc('0' + i % 10, r);
|
ap_rputc('0' + i % 10, r);
|
||||||
else
|
else
|
||||||
ap_rputs(" ", r);
|
putchar('0' + i % 10);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (r)
|
||||||
|
ap_rputs(" ", r);
|
||||||
|
else
|
||||||
|
printf(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_fn_info(request_rec *r, const char *name)
|
||||||
|
{
|
||||||
|
if (r)
|
||||||
|
ap_set_module_config(r->request_config, &info_module, (void *)name);
|
||||||
|
else
|
||||||
|
dump_config_fn_info = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *get_fn_info(request_rec *r)
|
||||||
|
{
|
||||||
|
if (r)
|
||||||
|
return ap_get_module_config(r->request_config, &info_module);
|
||||||
|
else
|
||||||
|
return dump_config_fn_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void mod_info_indent(request_rec * r, int nest,
|
static void mod_info_indent(request_rec * r, int nest,
|
||||||
const char *thisfn, int linenum)
|
const char *thisfn, int linenum)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
const char *prevfn =
|
const char *prevfn = get_fn_info(r);
|
||||||
ap_get_module_config(r->request_config, &info_module);
|
|
||||||
if (thisfn == NULL)
|
if (thisfn == NULL)
|
||||||
thisfn = "*UNKNOWN*";
|
thisfn = "*UNKNOWN*";
|
||||||
if (prevfn == NULL || 0 != strcmp(prevfn, thisfn)) {
|
if (prevfn == NULL || 0 != strcmp(prevfn, thisfn)) {
|
||||||
|
if (r) {
|
||||||
thisfn = ap_escape_html(r->pool, thisfn);
|
thisfn = ap_escape_html(r->pool, thisfn);
|
||||||
ap_rprintf(r, "<dd><tt><strong>In file: %s</strong></tt></dd>\n",
|
ap_rprintf(r, "<dd><tt><strong>In file: %s</strong></tt></dd>\n",
|
||||||
thisfn);
|
thisfn);
|
||||||
ap_set_module_config(r->request_config, &info_module,
|
}
|
||||||
(void *) thisfn);
|
else {
|
||||||
|
printf("# In file: %s\n", thisfn);
|
||||||
|
}
|
||||||
|
set_fn_info(r, thisfn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (r) {
|
||||||
ap_rputs("<dd><tt>", r);
|
ap_rputs("<dd><tt>", r);
|
||||||
put_int_flush_right(r, linenum > 0 ? linenum : 0, 4);
|
put_int_flush_right(r, linenum > 0 ? linenum : 0, 4);
|
||||||
ap_rputs(": ", r);
|
ap_rputs(": ", r);
|
||||||
|
}
|
||||||
|
else if (linenum > 0) {
|
||||||
|
for (i = 1; i <= nest; ++i)
|
||||||
|
printf(" ");
|
||||||
|
putchar('#');
|
||||||
|
put_int_flush_right(r, linenum, 4);
|
||||||
|
printf(":\n");
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 1; i <= nest; ++i) {
|
for (i = 1; i <= nest; ++i) {
|
||||||
|
if (r)
|
||||||
ap_rputs(" ", r);
|
ap_rputs(" ", r);
|
||||||
|
else
|
||||||
|
printf(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,18 +179,24 @@ static void mod_info_show_cmd(request_rec * r, const ap_directive_t * dir,
|
|||||||
int nest)
|
int nest)
|
||||||
{
|
{
|
||||||
mod_info_indent(r, nest, dir->filename, dir->line_num);
|
mod_info_indent(r, nest, dir->filename, dir->line_num);
|
||||||
|
if (r)
|
||||||
ap_rprintf(r, "%s <i>%s</i></tt></dd>\n",
|
ap_rprintf(r, "%s <i>%s</i></tt></dd>\n",
|
||||||
ap_escape_html(r->pool, dir->directive),
|
ap_escape_html(r->pool, dir->directive),
|
||||||
ap_escape_html(r->pool, dir->args));
|
ap_escape_html(r->pool, dir->args));
|
||||||
|
else
|
||||||
|
printf("%s %s\n", dir->directive, dir->args);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mod_info_show_open(request_rec * r, const ap_directive_t * dir,
|
static void mod_info_show_open(request_rec * r, const ap_directive_t * dir,
|
||||||
int nest)
|
int nest)
|
||||||
{
|
{
|
||||||
mod_info_indent(r, nest, dir->filename, dir->line_num);
|
mod_info_indent(r, nest, dir->filename, dir->line_num);
|
||||||
|
if (r)
|
||||||
ap_rprintf(r, "%s %s</tt></dd>\n",
|
ap_rprintf(r, "%s %s</tt></dd>\n",
|
||||||
ap_escape_html(r->pool, dir->directive),
|
ap_escape_html(r->pool, dir->directive),
|
||||||
ap_escape_html(r->pool, dir->args));
|
ap_escape_html(r->pool, dir->args));
|
||||||
|
else
|
||||||
|
printf("%s %s\n", dir->directive, dir->args);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mod_info_show_close(request_rec * r, const ap_directive_t * dir,
|
static void mod_info_show_close(request_rec * r, const ap_directive_t * dir,
|
||||||
@@ -155,11 +205,17 @@ static void mod_info_show_close(request_rec * r, const ap_directive_t * dir,
|
|||||||
const char *dirname = dir->directive;
|
const char *dirname = dir->directive;
|
||||||
mod_info_indent(r, nest, dir->filename, 0);
|
mod_info_indent(r, nest, dir->filename, 0);
|
||||||
if (*dirname == '<') {
|
if (*dirname == '<') {
|
||||||
|
if (r)
|
||||||
ap_rprintf(r, "</%s></tt></dd>",
|
ap_rprintf(r, "</%s></tt></dd>",
|
||||||
ap_escape_html(r->pool, dirname + 1));
|
ap_escape_html(r->pool, dirname + 1));
|
||||||
|
else
|
||||||
|
printf("</%s>\n", dirname + 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (r)
|
||||||
ap_rprintf(r, "/%s</tt></dd>", ap_escape_html(r->pool, dirname));
|
ap_rprintf(r, "/%s</tt></dd>", ap_escape_html(r->pool, dirname));
|
||||||
|
else
|
||||||
|
printf("/%s\n", dirname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +245,7 @@ static int mod_info_module_cmds(request_rec * r, const command_rec * cmds,
|
|||||||
int shown = from;
|
int shown = from;
|
||||||
ap_directive_t *dir;
|
ap_directive_t *dir;
|
||||||
if (level == 0)
|
if (level == 0)
|
||||||
ap_set_module_config(r->request_config, &info_module, NULL);
|
set_fn_info(r, NULL);
|
||||||
for (dir = node; dir; dir = dir->next) {
|
for (dir = node; dir; dir = dir->next) {
|
||||||
if (dir->first_child != NULL) {
|
if (dir->first_child != NULL) {
|
||||||
if (level < mod_info_module_cmds(r, cmds, dir->first_child,
|
if (level < mod_info_module_cmds(r, cmds, dir->first_child,
|
||||||
@@ -797,9 +853,20 @@ static const command_rec info_cmds[] = {
|
|||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int check_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp,
|
||||||
|
server_rec *s)
|
||||||
|
{
|
||||||
|
if (ap_exists_config_define("DUMP_CONFIG"))
|
||||||
|
mod_info_module_cmds(NULL, NULL, ap_conftree, 0, 0);
|
||||||
|
|
||||||
|
return DECLINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void register_hooks(apr_pool_t * p)
|
static void register_hooks(apr_pool_t * p)
|
||||||
{
|
{
|
||||||
ap_hook_handler(display_info, NULL, NULL, APR_HOOK_MIDDLE);
|
ap_hook_handler(display_info, NULL, NULL, APR_HOOK_MIDDLE);
|
||||||
|
ap_hook_check_config(check_config, NULL, NULL, APR_HOOK_FIRST);
|
||||||
}
|
}
|
||||||
|
|
||||||
AP_DECLARE_MODULE(info) = {
|
AP_DECLARE_MODULE(info) = {
|
||||||
|
Reference in New Issue
Block a user