我正在尝试编写一个示例Apache模块来读取配置文件,其文件路径在httpd.conf中指定,如下所示:
<Location ~ /(?!.*\.(png|jpeg|jpg|gif|bmp|tif)$)>
SetInputFilter SAMPLE_INPUT_FILTER
SetOutputFilter SAMPLE_OUTPUT_FILTER
ConfigFilePath "/etc/httpd/conf.d/sample/sample.config"
</Location>
在命令记录结构中,我这样做:
static const command_rec config_check_cmds[] =
{
AP_INIT_TAKE1( "ConfigFilePath", read_config_file, NULL, OR_ALL, "sample config"),
{ NULL }
};
我也设置了:
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 */
};
我可以成功读取配置文件路径。现在我想检查一下如果httpd.conf中没有指定“ConfigFilePath”,当我使用“service httpd restart”时它会在控制台显示错误
我怎么能这样做?
答案 0 :(得分:1)
您注册了ap_hook_post_config
个钩子并在那里进行所需设置的验证。请注意,该钩子被调用两次,如答案中所述:Init modules in apache2
在此处查看示例post config hook实现:http://svn.apache.org/repos/asf/httpd/httpd/tags/2.3.0/modules/examples/mod_example_hooks.c