I am trying to write a sample Apache module to read config file whose file path is specified in httpd.conf like that:
<Location ~ /(?!.*\.(png|jpeg|jpg|gif|bmp|tif)$)>
SetInputFilter SAMPLE_INPUT_FILTER
SetOutputFilter SAMPLE_OUTPUT_FILTER
ConfigFilePath "/etc/httpd/conf.d/sample/sample.config"
</Location>
At command record structure, I do:
static const command_rec config_check_cmds[] =
{
AP_INIT_TAKE1( "ConfigFilePath", read_config_file, NULL, OR_ALL, "sample config"),
{ NULL }
};
I also set:
module AP_MODULE_DECLARE_DATA SAMPLE_module = {
STANDARD20_MODULE_STUFF,
create_dir_config, /* create per-dir config structures */
NULL, /* merge per-dir config structures */
NULL, /* create per-server config structures */
NULL, /* merge per-server config structures */
config_check_cmds, /* table of config file commands */
sample_register_hooks /* register hooks */
};
I could read config file path successfully. And now I want to check that if "ConfigFilePath" is not specified in httpd.conf, It will show error at console when I use "service httpd restart"
How could I do that?
You'd register a ap_hook_post_config
hook and do the verification of required settings there. Be aware that that hook is called twice as documented in the answer here: Init modules in apache2
See an example post config hook implementation here: http://svn.apache.org/repos/asf/httpd/httpd/tags/2.3.0/modules/examples/mod_example_hooks.c