From: Justin Erenkrantz Date: Mon, 17 Feb 2003 07:04:50 +0000 (+0000) Subject: Allow restart of httpd to occur even with syntax errors in the config X-Git-Tag: pre_ajp_proxy~2120 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1a344d46b69651bba195d62c547cce259cdb99a9;p=apache Allow restart of httpd to occur even with syntax errors in the config file. (Out-of-date DSOs with bad MMNs will still be fatal unfortunately.) Add return parameter to ap_process_config_tree - OK on success, !OK on syntax error. We will no longer call exit() from ap_process_config_tree. The caller must exit if there is an error (makes sense anyway). This allows the initial start-up code to delay the exit until trying to let the signal_server optional function execute first. (The chances are that the syntax error isn't in the PidFile directive. If that happens, we'll try the default one. Oh, well.) PR: 16813 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@98693 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 6847faa176..99ea482296 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache 2.1.0-dev [Remove entries to the current 2.0 section below, when backported] + *) Allow restart of httpd to occur even with syntax errors in the config + file. PR 16813. [Justin Erenkrantz] + *) Rewrite ap_xml_parse_input to use bucket brigades. PR 16134. [Justin Erenkrantz] diff --git a/include/http_config.h b/include/http_config.h index b752207841..3c85429e4a 100644 --- a/include/http_config.h +++ b/include/http_config.h @@ -927,9 +927,12 @@ AP_DECLARE(void) ap_process_resource_config(server_rec *s, const char *fname, * @param conftree The config tree to process * @param p The pool for general allocation * @param ptemp The pool for temporary allocations + * @return OK if no problems */ -AP_DECLARE(void) ap_process_config_tree(server_rec *s, ap_directive_t *conftree, - apr_pool_t *p, apr_pool_t *ptemp); +AP_DECLARE(int) ap_process_config_tree(server_rec *s, + ap_directive_t *conftree, + apr_pool_t *p, + apr_pool_t *ptemp); /* Module-method dispatchers, also for http_request.c */ /** diff --git a/server/config.c b/server/config.c index 2e2b06b387..3be4368841 100644 --- a/server/config.c +++ b/server/config.c @@ -1577,9 +1577,10 @@ AP_DECLARE(void) ap_process_resource_config(server_rec *s, const char *fname, ap_cfg_closefile(cfp); } -AP_DECLARE(void) ap_process_config_tree(server_rec *s, - ap_directive_t *conftree, - apr_pool_t *p, apr_pool_t *ptemp) +AP_DECLARE(int) ap_process_config_tree(server_rec *s, + ap_directive_t *conftree, + apr_pool_t *p, + apr_pool_t *ptemp) { const char *errmsg; cmd_parms parms; @@ -1599,8 +1600,10 @@ AP_DECLARE(void) ap_process_config_tree(server_rec *s, parms.err_directive->filename); ap_log_perror(APLOG_MARK, APLOG_STARTUP, 0, p, "%s", errmsg); - exit(1); + return HTTP_INTERNAL_SERVER_ERROR; } + + return OK; } AP_CORE_DECLARE(int) ap_parse_htaccess(ap_conf_vector_t **result, diff --git a/server/main.c b/server/main.c index a2cbcc3717..5472160b63 100644 --- a/server/main.c +++ b/server/main.c @@ -573,13 +573,16 @@ int main(int argc, const char * const argv[]) destroy_and_exit_process(process, 1); } - ap_process_config_tree(server_conf, ap_conftree, process->pconf, ptemp); - ap_fixup_virtual_hosts(pconf, server_conf); - ap_fini_vhost_config(pconf, server_conf); - apr_hook_sort_all(); - if (configtestonly) { - ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Syntax OK"); - destroy_and_exit_process(process, 0); + rv = ap_process_config_tree(server_conf, ap_conftree, + process->pconf, ptemp); + if (rv == OK) { + ap_fixup_virtual_hosts(pconf, server_conf); + ap_fini_vhost_config(pconf, server_conf); + apr_hook_sort_all(); + if (configtestonly) { + ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Syntax OK"); + destroy_and_exit_process(process, 0); + } } signal_server = APR_RETRIEVE_OPTIONAL_FN(ap_signal_server); @@ -591,6 +594,11 @@ int main(int argc, const char * const argv[]) } } + /* If our config failed, deal with that here. */ + if (rv != OK) { + destroy_and_exit_process(process, 1); + } + apr_pool_clear(plog); if ( ap_run_open_logs(pconf, plog, ptemp, server_conf) != OK) { @@ -630,7 +638,10 @@ int main(int argc, const char * const argv[]) destroy_and_exit_process(process, 1); } - ap_process_config_tree(server_conf, ap_conftree, process->pconf, ptemp); + if (ap_process_config_tree(server_conf, ap_conftree, process->pconf, + ptemp) != OK) { + destroy_and_exit_process(process, 1); + } ap_fixup_virtual_hosts(pconf, server_conf); ap_fini_vhost_config(pconf, server_conf); apr_hook_sort_all();