From 1d642bab662b5544f75099c4286c6f66856de30f Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Tue, 30 May 2000 02:42:32 +0000 Subject: [PATCH] We now report the correct line number for syntax errors in config files. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85348 13f79535-47bb-0310-9956-ffa450edef68 --- include/http_config.h | 1 + server/config.c | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/http_config.h b/include/http_config.h index 04210856e9..c97681f142 100644 --- a/include/http_config.h +++ b/include/http_config.h @@ -188,6 +188,7 @@ typedef struct { void *context; /* per_dir_config vector passed * to handle_command */ + const ap_directive_t *err_directive; /* directive with syntax error */ } cmd_parms; /* This structure records the existence of handlers in a module... */ diff --git a/server/config.c b/server/config.c index 09942c9923..5df5653d44 100644 --- a/server/config.c +++ b/server/config.c @@ -984,6 +984,7 @@ static const char *ap_walk_config_sub(const ap_directive_t *current, const command_rec *cmd; if (!(cmd = ap_find_command_in_modules(current->directive, &mod))) { + parms->err_directive = current; return ap_pstrcat(parms->pool, "Invalid command '", current->directive, "', perhaps mis-spelled or defined by a module " @@ -995,8 +996,20 @@ static const char *ap_walk_config_sub(const ap_directive_t *current, const char *retval; retval = invoke_cmd(cmd, parms, mconfig, current->args); - if (retval == NULL || strcmp(retval, DECLINE_CMD) != 0) + if (retval == NULL) { + return NULL; + } + if (strcmp(retval, DECLINE_CMD) != 0) { + /* If the directive in error has already been set, don't + * replace it. Otherwise, an error inside a container + * will be reported as occuring on the first line of the + * container. + */ + if (!parms->err_directive) { + parms->err_directive = current; + } return retval; + } mod = mod->next; /* Next time around, skip this one */ } @@ -1130,7 +1143,7 @@ API_EXPORT_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, char *struct_pt */ static cmd_parms default_parms = -{NULL, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; +{NULL, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; API_EXPORT(const char *) ap_server_root_relative(ap_pool_t *p, const char *file) { @@ -1300,10 +1313,10 @@ void ap_process_resource_config(server_rec *s, const char *fname, ap_pool_t *p, errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults); if (errmsg != NULL) { - /* ### wrong line number. need to pull from ap_directive_t */ ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Syntax error on line %d of %s:", - cfp->line_number, cfp->name); + parms.err_directive->line_num, + parms.err_directive->filename); ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "%s", errmsg); exit(1); -- 2.50.1