httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <trawi...@bellsouth.net>
Subject [PATCH] improving line number reporting for config file syntax errors
Date Mon, 29 May 2000 02:02:20 GMT
The key word here is "improving", not "fixing" :)

The plan was to pass back the address of the bad ap_directive_t back
to the caller of ap_walk_config() from the place that discovered the
problem.  (We could pass back just the line number or the line number
and the file name.)

Unfortunately (for this problem, at least), we process stuff like

<Directory />
silly
</Directory>

via the same code that we use for calling a module's command handler.
We wouldn't want to modify the parameter lists to those routines since
it would break every module.

The patch below doesn't modify the parameter lists of the functions
called by invoke_cmd(), so perfect information isn't reported.  While
it is a big improvement over the current reporting (which always
reports the last line number in the file), it reports the starting
line number of the container as the bad line number when a syntax
error is encountered in a container.  Thus, for the example above we
get 

  Syntax error on line 1 of /tmp/apache-2.0/conf/httpd.conf:
  Invalid command 'silly', perhaps mis-spelled or defined by...

We could invent a new parmlist flavor to use with ap_limit_section(),
dirsection(), urlsection(), filesection(), and virtualhost_section()
so that they could pass back the information on the syntax error to
invoke_cmd() and then back to ap_walk_config_sub()
(These are the routines that call ap_walk_config() when processing a
container.) 

any other ideas, other than "just use a global variable"?

Index: src/include/http_config.h
===================================================================
RCS file: /cvs/apache/apache-2.0/src/include/http_config.h,v
retrieving revision 1.25
diff -u -r1.25 http_config.h
--- http_config.h	2000/05/27 22:53:46	1.25
+++ http_config.h	2000/05/29 01:41:03
@@ -349,6 +349,7 @@
 					 ap_pool_t *temp_pool,
 					 ap_directive_t **conftree);
 API_EXPORT(const char *) ap_walk_config(ap_directive_t *conftree,
+                                        ap_directive_t **bad_directive,
 					cmd_parms *parms, void *config);
 
 /* ap_check_cmd_context() definitions: */
Index: src/main/http_config.c
===================================================================
RCS file: /cvs/apache/apache-2.0/src/main/http_config.c,v
retrieving revision 1.53
diff -u -r1.53 http_config.c
--- http_config.c	2000/05/27 22:53:48	1.53
+++ http_config.c	2000/05/29 01:41:07
@@ -995,7 +995,7 @@
 	    const char *retval;
 
 	    retval = invoke_cmd(cmd, parms, mconfig, current->args);
-	    if (retval == NULL || strcmp(retval, DECLINE_CMD) != 0)
+            if (retval == NULL || strcmp(retval, DECLINE_CMD) != 0)
 		return retval;
 
 	    mod = mod->next;	/* Next time around, skip this one */
@@ -1005,11 +1005,13 @@
 }
 
 API_EXPORT(const char *) ap_walk_config(ap_directive_t *current,
+                                        ap_directive_t **bad_directive,
 					cmd_parms *parms, void *config)
 {
     void *oldconfig = parms->context;
 
     parms->context = config;
+    *bad_directive = NULL;
 
     /* scan through all directives, executing each one */
     for (; current != NULL; current = current->next) {
@@ -1020,6 +1022,7 @@
         /* actually parse the command and execute the correct function */
         errmsg = ap_walk_config_sub(current, parms, config);
 	if (errmsg != NULL) {
+            *bad_directive = current;
 	    /* restore the context (just in case) */
 	    parms->context = oldconfig;
 	    return errmsg;
@@ -1235,7 +1238,7 @@
     const char *errmsg;
     cmd_parms parms;
     arr_elts_param_t arr_parms;
-    ap_directive_t *conftree;
+    ap_directive_t *conftree, *bad_directive;
 
     arr_parms.curr_idx = 0;
     arr_parms.array = arr;
@@ -1252,7 +1255,8 @@
 
     errmsg = ap_build_config(&parms, p, ptemp, &conftree);
     if (errmsg == NULL)
-	errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults);
+	errmsg = ap_walk_config(conftree, &bad_directive, &parms, 
+                                s->lookup_defaults);
     if (errmsg) {
         ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
                      "Syntax error in -C/-c directive:\n%s", errmsg);
@@ -1266,7 +1270,7 @@
 {
     cmd_parms parms;
     ap_finfo_t finfo;
-    ap_directive_t *conftree;
+    ap_directive_t *conftree, *bad_directive;
     const char *errmsg;
     configfile_t *cfp;
 
@@ -1297,13 +1301,14 @@
     parms.config_file = cfp;
     errmsg = ap_build_config(&parms, p, ptemp, &conftree);
     if (errmsg == NULL)
-	errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults);
+	errmsg = ap_walk_config(conftree, &bad_directive, &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);
+		     bad_directive->line_num, bad_directive->filename);
 	ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, 
                      "%s", errmsg);
 	exit(1);
@@ -1348,14 +1353,14 @@
 
         if (status == APR_SUCCESS) {
 	    const char *errmsg;
-	    ap_directive_t *conftree;
+	    ap_directive_t *conftree, *bad_directive;
 
             dc = ap_create_per_dir_config(r->pool);
 
             parms.config_file = f;
             errmsg = ap_build_config(&parms, r->pool, r->pool, &conftree);
 	    if (errmsg == NULL)
-		errmsg = ap_walk_config(conftree, &parms, dc);
+		errmsg = ap_walk_config(conftree, &bad_directive, &parms, dc);
 
             ap_cfg_closefile(f);
 
Index: src/main/http_core.c
===================================================================
RCS file: /cvs/apache/apache-2.0/src/main/http_core.c,v
retrieving revision 1.62
diff -u -r1.62 http_core.c
--- http_core.c	2000/05/27 22:40:27	1.62
+++ http_core.c	2000/05/29 01:41:10
@@ -1294,6 +1294,7 @@
     void *tog = cmd->cmd->cmd_data;
     int limited = 0;
     const char *errmsg;
+    ap_directive_t *bad_directive;
   
     const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
     if (err != NULL) {
@@ -1321,7 +1322,8 @@
      */
     cmd->limited = tog ? ~limited : limited;
 
-    errmsg = ap_walk_config(cmd->directive->first_child, cmd, cmd->context);
+    errmsg = ap_walk_config(cmd->directive->first_child, &bad_directive, cmd, 
+                            cmd->context);
 
     cmd->limited = -1;
 
@@ -1357,6 +1359,7 @@
     void *new_dir_conf = ap_create_per_dir_config(cmd->pool);
     regex_t *r = NULL;
     const command_rec *thiscmd = cmd->cmd;
+    ap_directive_t *bad_directive;
 
     const char *err = ap_check_cmd_context(cmd,
 					   NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT);
@@ -1389,7 +1392,8 @@
     conf = (core_dir_config *)ap_set_config_vectors(cmd, new_dir_conf,
 						    &core_module);
 
-    errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_dir_conf);
+    errmsg = ap_walk_config(cmd->directive->first_child, &bad_directive, cmd, 
+                            new_dir_conf);
     if (errmsg != NULL)
 	return errmsg;
 
@@ -1417,6 +1421,7 @@
     core_dir_config *conf;
     regex_t *r = NULL;
     const command_rec *thiscmd = cmd->cmd;
+    ap_directive_t *bad_directive;
 
     void *new_url_conf = ap_create_per_dir_config(cmd->pool);
 
@@ -1447,7 +1452,8 @@
     conf = (core_dir_config *)ap_set_config_vectors(cmd, new_url_conf,
 						    &core_module);
 
-    errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_url_conf);
+    errmsg = ap_walk_config(cmd->directive->first_child, &bad_directive, cmd, 
+                            new_url_conf);
     if (errmsg != NULL)
 	return errmsg;
 
@@ -1478,6 +1484,7 @@
     core_dir_config *conf;
     regex_t *r = NULL;
     const command_rec *thiscmd = cmd->cmd;
+    ap_directive_t *bad_directive;
 
     void *new_file_conf = ap_create_per_dir_config(cmd->pool);
 
@@ -1514,7 +1521,8 @@
     conf = (core_dir_config *)ap_set_config_vectors(cmd, new_file_conf,
 						    &core_module);
 
-    errmsg = ap_walk_config(cmd->directive->first_child, cmd, new_file_conf);
+    errmsg = ap_walk_config(cmd->directive->first_child, &bad_directive, cmd, 
+                            new_file_conf);
     if (errmsg != NULL)
 	return errmsg;
 
@@ -1626,6 +1634,7 @@
     const char *errmsg;
     char *endp = strrchr(arg, '>');
     ap_pool_t *p = cmd->pool;
+    ap_directive_t *bad_directive;
 
     const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
     if (err != NULL) {
@@ -1660,7 +1669,7 @@
 
     cmd->server = s;
 
-    errmsg = ap_walk_config(cmd->directive->first_child, cmd,
+    errmsg = ap_walk_config(cmd->directive->first_child, &bad_directive, cmd,
 			    s->lookup_defaults);
 
     cmd->server = main_server;


-- 
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
     http://www.geocities.com/SiliconValley/Park/9289/
          Born in Roswell... married an alien...

Mime
View raw message