]> granicus.if.org Git - apache/commitdiff
core: Add -DDUMP_INCLUDES configtest to show the Include tree.
authorGraham Leggett <minfrin@apache.org>
Mon, 13 Jun 2016 23:08:08 +0000 (23:08 +0000)
committerGraham Leggett <minfrin@apache.org>
Mon, 13 Jun 2016 23:08:08 +0000 (23:08 +0000)
     Example:

        Included configuration files:
          (*) .../conf/httpd.conf
            (517) .../conf/extra/proxy-html.conf
              (91) /dev/null

Submitted by: Jacob Champion <champion.pxi gmail.com>
Reviewed by: covener, gsmith, minfrin

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1748327 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
server/config.c
server/core.c
server/main.c

diff --git a/CHANGES b/CHANGES
index 9f99c832e308d25dea2a14b03d895cbcad4ce5d9..ffa442d132db7d37d5d66e515b5a4bd7e3ae487f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,10 @@
 
 Changes with Apache 2.4.21
 
+  *) core: Add -DDUMP_INCLUDES configtest option to show the tree
+     of Included configuration files.
+     [Jacob Champion <champion.pxi gmail.com>]
+
   *) mod_proxy_fcgi: Avoid passing a filename of proxy:fcgi:// as
      SCRIPT_FILENAME to a FastCGI server. PR59618.
      [Jacob Champion <champion.pxi gmail.com>]
diff --git a/STATUS b/STATUS
index 92131a0c23fdeb7e7e36931b6d071b094891ba06..005b1ccf34bdbd171633691193c4ab109ae1e221 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -114,18 +114,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
-  *) core: Add -DDUMP_INCLUDES configtest to show the Include tree.
-
-     Example:
-
-        Included configuration files:
-          (*) .../conf/httpd.conf
-            (517) .../conf/extra/proxy-html.conf
-              (91) /dev/null
-
-     trunk patch: http://svn.apache.org/r1747808.
-     2.4.x: trunk works
-     +1: covener, gsmith, minfrin
 
 
 PATCHES PROPOSED TO BACKPORT FROM TRUNK:
index 2f652e8eec51787db0bb21b1da5afd4c7ae076e1..7c7a1e00337e9986e3fbc86e5ac6fd742727ae21 100644 (file)
@@ -1790,6 +1790,54 @@ static int fname_alphasort(const void *fn1, const void *fn2)
     return strcmp(f1->fname,f2->fname);
 }
 
+/**
+ * Used by -D DUMP_INCLUDES to output the config file "tree".
+ */
+static void dump_config_name(const char *fname, apr_pool_t *p)
+{
+    unsigned i, recursion, line_number;
+    void *data;
+    apr_file_t *out = NULL;
+
+    apr_file_open_stdout(&out, p);
+
+    /* ap_include_sentinel is defined by the core Include directive; use it to
+     * figure out how deep in the stack we are.
+     */
+    apr_pool_userdata_get(&data, "ap_include_sentinel", p);
+
+    if (data) {
+        recursion = *(unsigned *)data;
+    } else {
+        recursion = 0;
+    }
+
+    /* Indent once for each level. */
+    for (i = 0; i < (recursion + 1); ++i) {
+        apr_file_printf(out, "  ");
+    }
+
+    /* ap_include_lineno is similarly defined to tell us where in the last
+     * config file we were.
+     */
+    apr_pool_userdata_get(&data, "ap_include_lineno", p);
+
+    if (data) {
+        line_number = *(unsigned *)data;
+    } else {
+        line_number = 0;
+    }
+
+    /* Print the line number and the name of the parsed file. */
+    if (line_number > 0) {
+        apr_file_printf(out, "(%u)", line_number);
+    } else {
+        apr_file_printf(out, "(*)");
+    }
+
+    apr_file_printf(out, " %s\n", fname);
+}
+
 AP_DECLARE(const char *) ap_process_resource_config(server_rec *s,
                                                     const char *fname,
                                                     ap_directive_t **conftree,
@@ -1814,6 +1862,10 @@ AP_DECLARE(const char *) ap_process_resource_config(server_rec *s,
                             fname, &rv);
     }
 
+    if (ap_exists_config_define("DUMP_INCLUDES")) {
+        dump_config_name(fname, p);
+    }
+
     parms.config_file = cfp;
     error = ap_build_config(&parms, p, ptemp, conftree);
     ap_cfg_closefile(cfp);
@@ -2407,6 +2459,16 @@ AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp,
 
     init_config_globals(p);
 
+    if (ap_exists_config_define("DUMP_INCLUDES")) {
+        apr_file_t *out = NULL;
+        apr_file_open_stdout(&out, p);
+
+        /* Included files will be dumped as the config is walked; print a
+         * header.
+         */
+        apr_file_printf(out, "Included configuration files:\n");
+    }
+
     /* All server-wide config files now have the SAME syntax... */
     error = process_command_config(s, ap_server_pre_read_config, conftree,
                                    p, ptemp);
index 43cad2dc25fa8a4ee8952612cc7b04ab21d3a5d0..e8c1ef675c019019caf1dd99b60da023af477e21 100644 (file)
@@ -3172,6 +3172,10 @@ static const char *include_config (cmd_parms *cmd, void *dummy,
     int optional = cmd->cmd->cmd_data ? 1 : 0;
     void *data;
 
+    /* NOTE: ap_include_sentinel is also used by ap_process_resource_config()
+     * during DUMP_INCLUDES; don't change its type or remove it without updating
+     * the other.
+     */
     apr_pool_userdata_get(&data, "ap_include_sentinel", cmd->pool);
     if (data) {
         recursion = data;
@@ -3196,6 +3200,24 @@ static const char *include_config (cmd_parms *cmd, void *dummy,
                            name, NULL);
     }
 
+    if (ap_exists_config_define("DUMP_INCLUDES")) {
+        unsigned *line_number;
+
+        /* NOTE: ap_include_lineno is used by ap_process_resource_config()
+         * during DUMP_INCLUDES; don't change its type or remove it without
+         * updating the other.
+         */
+        apr_pool_userdata_get(&data, "ap_include_lineno", cmd->pool);
+        if (data) {
+            line_number = data;
+        } else {
+            data = line_number = apr_palloc(cmd->pool, sizeof(*line_number));
+            apr_pool_userdata_setn(data, "ap_include_lineno", NULL, cmd->pool);
+        }
+
+        *line_number = cmd->config_file->line_number;
+    }
+
     error = ap_process_fnmatch_configs(cmd->server, conffile, &conftree,
                                        cmd->pool, cmd->temp_pool,
                                        optional);
index cfa5a9d3e5be5a60f8dfc22d894191dd6523de38..c5f35b9b447a5e003c9fc2216e4b0d970beffbe3 100644 (file)
@@ -425,6 +425,8 @@ static void usage(process_rec *process)
                  "  -t -D DUMP_MODULES : show all loaded modules ");
     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
                  "  -M                 : a synonym for -t -D DUMP_MODULES");
+    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
+                 "  -t -D DUMP_INCLUDES: show all included configuration files");
     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
                  "  -t                 : run syntax check for config files");
     ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
@@ -524,6 +526,9 @@ int main(int argc, const char * const argv[])
             /* Setting -D DUMP_MODULES is equivalent to setting -M */
             else if (strcmp(opt_arg, "DUMP_MODULES") == 0)
                 ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
+            /* Setting -D DUMP_INCLUDES is a type of configuration dump */
+            else if (strcmp(opt_arg, "DUMP_INCLUDES") == 0)
+                ap_run_mode = AP_SQ_RM_CONFIG_DUMP;
             break;
 
         case 'e':