httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <traw...@gmail.com>
Subject [RFC] Error directive to generate custom error messages from httpd.conf
Date Mon, 08 Nov 2010 00:35:37 GMT
This is handy when a module depends on another module at load time or
run time, and the config for that module needs to display a message
more helpful than the normal symbol-not-found or
optional-function-not-found or invalid-filter message.

The current kludge for generating an error message is to put it on a
single line in quotes like this:

<IfModule !mod_include.c>
"Tests won't work without mod_include!"
</IfModule>

yielding a message like

$ ./httpd -t
Syntax error on line 7 of /home/trawick/inst/23/conf/conf.d/fcgid.conf:
Invalid command 'Tests won't work without mod_include!', perhaps
misspelled or defined by a module not included in the server
configuration

(If the entire message isn't in quotes, the first token will be peeled
off and reported as the invalid command.)

With the Error directive:

<IfModule !mod_include.c>
Error mod_foo requires mod_include!  Use the LoadModule directive to
load mod_include.
</IfModule>


$ ./httpd -t
Syntax error on line 486 of /home/trawick/inst/23/conf/httpd.conf:
mod_foo requires mod_include!  Use the LoadModule directive to load mod_include.

Index: server/core.c
===================================================================
--- server/core.c	(revision 1032266)
+++ server/core.c	(working copy)
@@ -1092,6 +1092,11 @@
     return NULL;
 }

+static const char *set_error(cmd_parms *cmd, void *dummy, const char *arg)
+{
+    return arg;
+}
+
 #ifdef GPROF
 static const char *set_gprof_dir(cmd_parms *cmd, void *dummy, const char *arg)
 {
@@ -3432,6 +3437,8 @@
               "Define the existence of a variable.  Same as passing
-D to the command line."),
 AP_INIT_TAKE1("UnDefine", unset_define, NULL, RSRC_CONF,
               "Undefine the existence of a variable. Undo a Define."),
+AP_INIT_RAW_ARGS("Error", set_error, NULL, OR_ALL,
+                 "Generate error message from within configuration"),
 AP_INIT_RAW_ARGS("<If", ifsection, NULL, OR_ALL,
   "Container for directives to be conditionally applied"),

Mime
View raw message