]> granicus.if.org Git - apache/commitdiff
Consistenly use apr_file_* API instead of libc when dumping config because
authorStefan Fritsch <sf@apache.org>
Sun, 9 Oct 2011 17:55:06 +0000 (17:55 +0000)
committerStefan Fritsch <sf@apache.org>
Sun, 9 Oct 2011 17:55:06 +0000 (17:55 +0000)
mixing the two can give strange results due to buffering.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1180671 13f79535-47bb-0310-9956-ffa450edef68

include/http_config.h
modules/generators/mod_info.c
modules/ssl/ssl_engine_config.c

index 2eef16a7108f267f3ad5105534d7504b1a80ba19..649f4f6baf6dbecefb1a29fb04c10eeb9e9c410e 100644 (file)
@@ -1237,6 +1237,10 @@ AP_DECLARE_HOOK(int,check_config,(apr_pool_t *pconf, apr_pool_t *plog,
  * only if the server was invoked to test the configuration syntax.
  * @param pconf The config pool
  * @param s The list of server_recs
+ * @note To avoid reordering problems due to different buffering, hook
+ *       functions should only apr_file_*() to print to stdout/stderr and
+ *       not simple printf()/fprintf().
+ *     
  */
 AP_DECLARE_HOOK(void,test_config,(apr_pool_t *pconf, server_rec *s))
 
index db1072f82bfa9b04ccf06f8202968eb520f977e0..b685560bce063c52e483ed3ed2d4a0b1733099c8 100644 (file)
@@ -78,6 +78,8 @@ module AP_MODULE_DECLARE_DATA info_module;
 
 /* current file name when doing -DDUMP_CONFIG */
 const char *dump_config_fn_info;
+/* file handle when doing -DDUMP_CONFIG */
+apr_file_t *out = NULL;
 
 static void *create_info_config(apr_pool_t * p, server_rec * s)
 {
@@ -108,13 +110,13 @@ static void put_int_flush_right(request_rec * r, int i, int field)
         if (r)
             ap_rputc('0' + i % 10, r);
         else
-            putchar('0' + i % 10);
+            apr_file_putc('0' + i % 10, out);
     }
     else {
         if (r)
             ap_rputs("&nbsp;", r);
         else
-            printf(" ");
+            apr_file_printf(out, " ");
     }
 }
 
@@ -149,7 +151,7 @@ static void mod_info_indent(request_rec * r, int nest,
                    thisfn);
         }
         else {
-            printf("# In file: %s\n", thisfn);
+            apr_file_printf(out, "# In file: %s\n", thisfn);
         }
         set_fn_info(r, thisfn);
     }
@@ -161,17 +163,17 @@ static void mod_info_indent(request_rec * r, int nest,
     }
     else if (linenum > 0) {
         for (i = 1; i <= nest; ++i)
-            printf("  ");
-        putchar('#');
+            apr_file_printf(out, "  ");
+        apr_file_putc('#', out);
         put_int_flush_right(r, linenum, 4);
-        printf(":\n");
+        apr_file_printf(out, ":\n");
     }
 
     for (i = 1; i <= nest; ++i) {
         if (r)
             ap_rputs("&nbsp;&nbsp;", r);
         else
-            printf("  ");
+            apr_file_printf(out, "  ");
     }
 }
 
@@ -184,7 +186,7 @@ static void mod_info_show_cmd(request_rec * r, const ap_directive_t * dir,
                    ap_escape_html(r->pool, dir->directive),
                    ap_escape_html(r->pool, dir->args));
     else
-        printf("%s %s\n", dir->directive, dir->args);
+        apr_file_printf(out, "%s %s\n", dir->directive, dir->args);
 }
 
 static void mod_info_show_open(request_rec * r, const ap_directive_t * dir,
@@ -196,7 +198,7 @@ static void mod_info_show_open(request_rec * r, const ap_directive_t * dir,
                    ap_escape_html(r->pool, dir->directive),
                    ap_escape_html(r->pool, dir->args));
     else
-        printf("%s %s\n", dir->directive, dir->args);
+        apr_file_printf(out, "%s %s\n", dir->directive, dir->args);
 }
 
 static void mod_info_show_close(request_rec * r, const ap_directive_t * dir,
@@ -209,13 +211,13 @@ static void mod_info_show_close(request_rec * r, const ap_directive_t * dir,
             ap_rprintf(r, "&lt;/%s&gt;</tt></dd>",
                        ap_escape_html(r->pool, dirname + 1));
         else
-            printf("</%s>\n", dirname + 1);
+            apr_file_printf(out, "</%s>\n", dirname + 1);
     }
     else {
         if (r)
             ap_rprintf(r, "/%s</tt></dd>", ap_escape_html(r->pool, dirname));
         else
-            printf("/%s\n", dirname);
+            apr_file_printf(out, "/%s\n", dirname);
     }
 }
 
@@ -859,8 +861,10 @@ static const command_rec info_cmds[] = {
 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"))
+    if (ap_exists_config_define("DUMP_CONFIG")) {
+        apr_file_open_stdout(&out, ptemp);
         mod_info_module_cmds(NULL, NULL, ap_conftree, 0, 0);
+    }
 
     return DECLINED;
 }
index 6ceabd4036332281b44885f2742fbddcc56e4eda..dfcfc65b3ac1a11bfe242e4996a3a7e3465bcf7f 100644 (file)
@@ -1719,9 +1719,11 @@ const char *ssl_cmd_SSLStaplingForceURL(cmd_parms *cmd, void *dcfg,
 
 void ssl_hook_ConfigTest(apr_pool_t *pconf, server_rec *s)
 {
+    apr_file_t *out = NULL;
     if (!ap_exists_config_define("DUMP_CERTS")) {
         return;
     }
+    apr_file_open_stdout(&out, pconf);
 
     /* Dump the filenames of all configured server certificates to
      * stdout. */
@@ -1733,7 +1735,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++) {
-                printf("%s\n", pks->cert_files[i]);
+                apr_file_printf(out, "%s\n", pks->cert_files[i]);
             }
         }