From cd17cd2c10f8d47e115e6c07e30b758dece17010 Mon Sep 17 00:00:00 2001 From: Stefan Fritsch Date: Sun, 9 Oct 2011 17:55:06 +0000 Subject: [PATCH] Consistenly use apr_file_* API instead of libc when dumping config because 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 | 4 ++++ modules/generators/mod_info.c | 28 ++++++++++++++++------------ modules/ssl/ssl_engine_config.c | 4 +++- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/include/http_config.h b/include/http_config.h index 2eef16a710..649f4f6baf 100644 --- a/include/http_config.h +++ b/include/http_config.h @@ -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)) diff --git a/modules/generators/mod_info.c b/modules/generators/mod_info.c index db1072f82b..b685560bce 100644 --- a/modules/generators/mod_info.c +++ b/modules/generators/mod_info.c @@ -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(" ", 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("  ", 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, "</%s>", ap_escape_html(r->pool, dirname + 1)); else - printf("\n", dirname + 1); + apr_file_printf(out, "\n", dirname + 1); } else { if (r) ap_rprintf(r, "/%s", 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; } diff --git a/modules/ssl/ssl_engine_config.c b/modules/ssl/ssl_engine_config.c index 6ceabd4036..dfcfc65b3a 100644 --- a/modules/ssl/ssl_engine_config.c +++ b/modules/ssl/ssl_engine_config.c @@ -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]); } } -- 2.40.0